IronSmarkets.Data.EventQueryBuilder.GetResult C# (CSharp) Method

GetResult() public method

public GetResult ( ) : EventQuery
return EventQuery
        public EventQuery GetResult()
        {
            if (!_category.HasValue)
            {
                throw new InvalidEventQueryException("Must specify a category");
            }

            if (_category.Value != Proto.Seto.EventCategory.EVENTCATEGORYSPORT && _dateTime.HasValue)
            {
                throw new InvalidEventQueryException(
                    "Date can only be specified for football, " +
                    "horse racing, and tennis.");
            }

            if (_category.Value != Proto.Seto.EventCategory.EVENTCATEGORYSPORT && _sport.HasValue)
            {
                throw new InvalidEventQueryException(
                    "Sport can only be specified when category " +
                    "is also sport.");
            }

            var request = new Proto.Seto.EventsRequest {
                ContentType = Proto.Seto.ContentType.CONTENTTYPEPROTOBUF
            };

            if (!_dateTime.HasValue)
            {
                if (_category == Proto.Seto.EventCategory.EVENTCATEGORYPOLITICS)
                {
                    request.Type = Proto.Seto.EventsRequestType.EVENTSREQUESTPOLITICS;
                }
                else if (_category == Proto.Seto.EventCategory.EVENTCATEGORYCURRENTAFFAIRS)
                {
                    request.Type = Proto.Seto.EventsRequestType.EVENTSREQUESTCURRENTAFFAIRS;
                }
                else if (_category == Proto.Seto.EventCategory.EVENTCATEGORYTVANDENTERTAINMENT)
                {
                    request.Type = Proto.Seto.EventsRequestType.EVENTSREQUESTTVANDENTERTAINMENT;
                }
                else
                {
                    if (_sport.HasValue)
                    {
                        throw new InvalidEventQueryException(
                            "Date must be specified when sport is specified.");
                    }
                    request.Type = Proto.Seto.EventsRequestType.EVENTSREQUESTSPORTOTHER;
                }
            }
            else
            {
                if (!_sport.HasValue)
                {
                    throw new InvalidEventQueryException("Must specify a sport when specifying a date");
                }
                var dateTime = _dateTime.GetValueOrDefault();
                request.Type = Proto.Seto.EventsRequestType.EVENTSREQUESTSPORTBYDATE;
                request.SportByDate = new Proto.Seto.SportByDate {
                    Type = _sport.Value,
                    Date = SetoMap.FromDateTime(dateTime)
                };
            }

            return new EventQuery(request);
        }

Usage Example

        public void SportByDateType()
        {
            var builder = new EventQueryBuilder();
            builder.SetCategory("sport");
            builder.SetDateTime(new DateTime(2012, 1, 1));
            builder.SetSport("football");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATEFOOTBALL);
            builder.SetSport("tennis");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATETENNIS);
            builder.SetSport("horse-racing");
            Assert.Equal(builder.GetResult().ToEventsRequest().SportByDate.Type, Proto.Seto.SportByDateType.SPORTBYDATEHORSERACING);

            var builderDate = builder.GetResult().ToEventsRequest().SportByDate.Date;
            Assert.Equal(builderDate.Year, (uint)2012);
            Assert.Equal(builderDate.Month, (uint)1);
            Assert.Equal(builderDate.Day, (uint)1);
        }
All Usage Examples Of IronSmarkets.Data.EventQueryBuilder::GetResult