Esempio n. 1
0
        public async Task <ResultData <TokkepediaReaction> > GetReactionsAsync(ReactionQueryValues values = null)
        {
            if (values == null)
            {
                values = new ReactionQueryValues();
            }

            client.DefaultRequestHeaders.Add("limit", values?.limit.ToString());
            client.DefaultRequestHeaders.Add("kind", values?.kind);
            client.DefaultRequestHeaders.Add("activity_id", values?.activity_id);
            client.DefaultRequestHeaders.Add("user_id", values?.user_id);
            client.DefaultRequestHeaders.Add("reaction_id", values?.reaction_id);
            client.DefaultRequestHeaders.Add("pagination_id", values?.pagination_id);
            client.BaseAddress = new Uri($"{baseUrl}/reactions{codePrefix}{apiKey}");
            HttpResponseMessage response = await client.GetAsync(client.BaseAddress);

            client = new HttpClient();

            try
            {
                var data = await response.Content.ReadAsAsync <ResultData <TokkepediaReaction> >();

                for (int i = 0; i < data.Results.Count; ++i)
                {
                    if (data.Results[i].UserId == "tokket")
                    {
                        data.Results[i].UserPhoto = "/images/tokket.png";
                    }
                }

                return(data);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <ResultData <TokkepediaReaction> > GetReactionsAsync(ReactionQueryValues values = null)
        {
            if (values == null)
            {
                values = new ReactionQueryValues();
            }

            _httpClient.DefaultRequestHeaders.Add("limit", values?.limit.ToString());
            _httpClient.DefaultRequestHeaders.Add("kind", values?.kind);
            _httpClient.DefaultRequestHeaders.Add("item_id", values?.item_id);
            _httpClient.DefaultRequestHeaders.Add("activity_id", values?.activity_id);
            _httpClient.DefaultRequestHeaders.Add("user_id", values?.user_id);
            _httpClient.DefaultRequestHeaders.Add("reaction_id", values?.reaction_id);
            _httpClient.DefaultRequestHeaders.Add("pagination_id", values?.pagination_id);
            var apiUrl = $"{_apiSettings.ApiPrefix}/reactions{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";
            HttpResponseMessage response = await _httpClient.GetAsync(apiUrl);

            try
            {
                var data = await response.Content.ReadAsAsync <ResultData <TokkepediaReaction> >();

                for (int i = 0; i < data.Results.Count; ++i)
                {
                    if (data.Results[i].UserId == "tokket")
                    {
                        data.Results[i].UserPhoto = "/images/tokket.png";
                    }
                }

                return(data);
            }
            catch
            {
                return(null);
            }
        }