////http://football.ua/handlers/stanfy/authors.ashx
        //public Task<ResponseCategory> LoadAuthorsCategoriesAsync()
        //{
        //    var request = new HttpRequestMessage();
        //    var parser = new XmlParser<ResponseCategory>();
        //    request.RequestUri = new Uri("http://football.ua/handlers/stanfy/authors.ashx");
        //    var settings = new RestSettings<>
        //    return _restClient.SendMessageAsync(request, parser);
        //}

        public Task <List <FeedItem> > LoadAuthorsFeedAsync(FeedItem lastFeedItem = null, string filterCode = "")
        {
            var request           = new HttpRequestMessage();
            var parser            = new RssFeedParser();
            var requestUriBuilder = new ParameterUriBuilder("http://football.ua/handlers/stanfy/news.ashx");

            requestUriBuilder.Add("type", "author");
            if (lastFeedItem != null)
            {
                var dateTimeOffset = lastFeedItem.Date.ToString("dd.MM.yyyy HH:mm:sszzz");
                dateTimeOffset = dateTimeOffset.Remove(dateTimeOffset.LastIndexOf(":"), 1);
                requestUriBuilder.Add("before", dateTimeOffset);
            }

            if (!string.IsNullOrEmpty(filterCode))
            {
                requestUriBuilder.Add("filterCode", filterCode);
            }

            request.RequestUri = requestUriBuilder.BuildParametersUri();

            var restSettings = new RestSettings <List <FeedItem> >()
                               .AddMode(RequestAccessMode.Server)
                               .AddParser(parser)
                               .AddRequestMessage(request);

            return(_restClient.SendAsync(restSettings, null));
        }
Пример #2
0
        public async Task <MatchesResponse> LoadMatchesAsync(DateTime date, CancellationToken cancellationToken)
        {
            var month = date.Month;
            var year  = date.Year;
            var day   = date.Day - 1;

            if (day == 0)
            {
                month -= 1;
                if (month == 0)
                {
                    year -= 1;
                    month = 12;
                }

                day = DateTime.DaysInMonth(date.Year, month);
            }

            var dtKey = string.Format("{0}-{1}-{2}T00:00:00", year, month, day);
            var uri   = new ParameterUriBuilder("http://services.football.ua/api/FootballGameBlockMain/GameList");

            uri.Add("dt", dtKey);
            uri.Add("direction", "false");
            uri.Add("callback", "");
            uri.Add("_1413706301734", "");

            var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri.BuildParametersUri());
            var settings       = new RestSettings <MatchesResponse>()
                                 .AddMode(RequestAccessMode.Server)
                                 .AddParser(new JsonParser <MatchesResponse>())
                                 .AddRequestMessage(requestMessage);

            return(await _restClient.SendAsync <MatchesResponse>(settings, null));
        }
        public async Task <Models.News.RssNewsDetailsChannelItem> GetDetailsAsync(int id, DateTimeOffset publishedDate, bool requestIfExists = false)
        {
            var uriBuilder = new ParameterUriBuilder("http://football.ua/hnd/Android/NewsItem.ashx");

            uriBuilder.Add("news_id", id.ToString());
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, uriBuilder.BuildParametersUri());
            var settings       = new RestSettings <rss>();

            settings.AddParser(new XmlParser <rss>())
            .AddRequestMessage(requestMessage)
            .AddMode(RequestAccessMode.Server);

            var result = await _restClient.SendAsync <rss>(settings, (Tuple <rss, DateTimeOffset?> tupleData) =>
            {
                if (!tupleData.Item2.HasValue)
                {
                    return(true);
                }

                return(requestIfExists && Math.Abs((publishedDate.UtcDateTime - tupleData.Item2.Value).TotalDays) < 1);
            });


            return(result?.Channel?.Item);
        }
        public async Task <IList <NewsItem> > LoadNewsAsync(DateTimeOffset dateTime, string code, Action <Exception> onError = null)
        {
            var uriBuider = new ParameterUriBuilder("http://services.football.ua/api/News/GetArchive");

            uriBuider.Add("pageId", code);
            uriBuider.Add("teamId", "0");
            uriBuider.Add("datePublish", dateTime.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture));
            uriBuider.Add("count", "20");
            uriBuider.Add("imageFormat", "s318x171");
            uriBuider.Add("callback", "");
            uriBuider.Add("_1480515720809", "");

            var settings = new RestSettings <NewsResponse>();

            settings.AddMode(RequestAccessMode.Server)
            .AddParser(new JsonParser <NewsResponse>())
            .AddRequestMessage(new HttpRequestMessage(HttpMethod.Get, uriBuider.BuildParametersUri()));

            var newsResponse = await _restClient.SendAsync(settings, onError : onError);

            try
            {
                var fillDetailsTask = newsResponse.News.Select(x => GetDetailsAsync(x.Id, x.DateTimeOffsetPublish, false));
                await Task.WhenAll(fillDetailsTask);
            }
            catch (Exception)
            {
                // ignore fill details task
            }

            return(newsResponse.News);
        }
        public Task<CommentsResponse> LoadCommentsAsync(int id, int pageIndex, CommentType commentType)
        {
            var request = new HttpRequestMessage();

            var uriBuilder = new ParameterUriBuilder("http://services.football.ua/api/Comment/Comments");
            uriBuilder.Add("itemId", id.ToString());
            uriBuilder.Add("commentType", ((int)commentType).ToString());
            uriBuilder.Add("pageIndex", pageIndex.ToString());
            uriBuilder.Add("pageSize", "25");
            uriBuilder.Add("sort", "0");
            uriBuilder.Add("anchor", "");
            uriBuilder.Add("callback","");

            request.RequestUri = uriBuilder.BuildParametersUri();

            var settings = new RestSettings<CommentsResponse>()
                              .AddMode(RequestAccessMode.Server)
                              .AddParser(new JsonParser<CommentsResponse>())
                              .AddRequestMessage(request);

            return _restClient.SendAsync(settings, null);
        }