private static void NextPage(this SearchEventsRequest originalRequest, SearchEventsResponse response)
        {
            const int pageIncrement = 1;

            if (response.Page.Number >= response.Page.TotalPages)
            {
                return;
            }

            var pageNumber = response.Page.Number + pageIncrement;

            originalRequest.AddQueryParameter(SearchEventsQueryParameters.page, pageNumber);

            if (response.Page.Size * pageNumber < ApiConstraints.MaxPagingDepth)
            {
                return;
            }

            var pageSize = response.Page.Size;

            while (pageSize * pageNumber >= ApiConstraints.MaxPagingDepth)
            {
                pageSize--;
            }

            originalRequest.AddQueryParameter(SearchEventsQueryParameters.size,
                                              pageSize > ApiConstraints.MinPageSize
                    ? pageSize
                    : ApiConstraints.MinPageSize);
        }
        public static SearchEventsResponse Unmarshall(UnmarshallerContext context)
        {
            SearchEventsResponse searchEventsResponse = new SearchEventsResponse();

            searchEventsResponse.HttpResponse = context.HttpResponse;
            searchEventsResponse.RequestId    = context.StringValue("SearchEvents.RequestId");
            searchEventsResponse.IsTrigger    = context.IntegerValue("SearchEvents.IsTrigger");

            SearchEventsResponse.SearchEvents_PageBean pageBean = new SearchEventsResponse.SearchEvents_PageBean();
            pageBean.TotalCount = context.IntegerValue("SearchEvents.PageBean.TotalCount");
            pageBean.PageNumber = context.IntegerValue("SearchEvents.PageBean.PageNumber");
            pageBean.PageSize   = context.IntegerValue("SearchEvents.PageBean.PageSize");

            List <SearchEventsResponse.SearchEvents_PageBean.SearchEvents_EventItem> pageBean_event = new List <SearchEventsResponse.SearchEvents_PageBean.SearchEvents_EventItem>();

            for (int i = 0; i < context.Length("SearchEvents.PageBean.Event.Length"); i++)
            {
                SearchEventsResponse.SearchEvents_PageBean.SearchEvents_EventItem eventItem = new SearchEventsResponse.SearchEvents_PageBean.SearchEvents_EventItem();
                eventItem.Id         = context.LongValue("SearchEvents.PageBean.Event[" + i + "].Id");
                eventItem.EventTime  = context.LongValue("SearchEvents.PageBean.Event[" + i + "].EventTime");
                eventItem.AlertType  = context.IntegerValue("SearchEvents.PageBean.Event[" + i + "].AlertType");
                eventItem.EventLevel = context.IntegerValue("SearchEvents.PageBean.Event[" + i + "].EventLevel");
                eventItem.Message    = context.StringValue("SearchEvents.PageBean.Event[" + i + "].Message");
                eventItem.AlertId    = context.LongValue("SearchEvents.PageBean.Event[" + i + "].AlertId");
                eventItem.AlertName  = context.StringValue("SearchEvents.PageBean.Event[" + i + "].AlertName");
                eventItem.AlertRule  = context.StringValue("SearchEvents.PageBean.Event[" + i + "].AlertRule");

                List <string> eventItem_links = new List <string>();
                for (int j = 0; j < context.Length("SearchEvents.PageBean.Event[" + i + "].Links.Length"); j++)
                {
                    eventItem_links.Add(context.StringValue("SearchEvents.PageBean.Event[" + i + "].Links[" + j + "]"));
                }
                eventItem.Links = eventItem_links;

                pageBean_event.Add(eventItem);
            }
            pageBean._Event = pageBean_event;
            searchEventsResponse.PageBean = pageBean;

            return(searchEventsResponse);
        }
Example #3
0
        internal List <TicketmasterEvent> SearchEvent(string latLong, string unit, string radius, DateTime startDate)
        {
            var list = new List <TicketmasterEvent>();

            try
            {
                var request = new SearchEventsRequest();
                request.AddQueryParameter(SearchEventsQueryParameters.latlong, latLong);
                request.AddQueryParameter(SearchEventsQueryParameters.unit, unit);
                request.AddQueryParameter(SearchEventsQueryParameters.radius, radius);
                request.AddQueryParameter(SearchEventsQueryParameters.startDateTime, startDate.ToString("yyyy-MM-ddThh:mm:ssZ"));
                request.AddQueryParameter(SearchEventsQueryParameters.size, "50");
                SearchEventsResponse result = EventsClient.SearchEventsAsync(request).GetAwaiter().GetResult();

                foreach (var _event in result._embedded.Events)
                {
                    var newEvent = new TicketmasterEvent();
                    newEvent.Name           = _event.Name;
                    newEvent.Url            = _event.Url;
                    newEvent.ExternalId     = _event.Id;
                    newEvent.ImageUrl       = _event.Images.First(x => x.Ratio == "16_9").Url;
                    newEvent.Promoter       = _event.Promoter.Name;
                    newEvent.SalesStartDate = _event.Sales.Public.StartDateTime;
                    newEvent.SalesEndDate   = _event.Sales.Public.EndDateTime;
                    newEvent.StartDate      = _event.Dates.Start.DateTime;
                    newEvent.Segment        = _event.Classifications.First().Segment.Name;
                    newEvent.SubGenre       = _event.Classifications.First().SubGenre.Name;
                    newEvent.Genre          = _event.Classifications.First().Genre.Name;

                    list.Add(newEvent);
                }

                return(list);
            }
            catch (Exception)
            {
                return(null);
            }
        }