private async Task <RemoteTwitchFollowersResponseDto> GetFollowers(string id)
        {
            var userQuery = new NetUtils.QueryBuilder(TwitchApiFollowersById);

            userQuery["to_id"] += id;
            using var request   = new HttpRequestMessage(HttpMethod.Get, userQuery.ToString());
            request.Headers.Add("Client-Id", _clientId);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken);
            var response = await _client.SendAsync(request);

            var content = await response.Content.ReadAsStringAsync();

            var dto = JsonConvert.DeserializeObject <RemoteTwitchFollowersResponseDto>(content);

            return(dto);
        }
Exemple #2
0
        public async Task <Youtube> GetYoutube(string channelId)
        {
            var query = new NetUtils.QueryBuilder(YoutubeChannelApi);

            query["part"]    += "statistics";
            query["id"]      += channelId;
            query["key"]     += _apiKey;
            using var request = new HttpRequestMessage(HttpMethod.Get, query.ToString());
            var response = await _client.SendAsync(request);

            var content = await response.Content.ReadAsStringAsync();

            var dto = JsonConvert.DeserializeObject <RemoteYoutubeResponseDto>(content);

            return(_mapper.Map <Youtube>(dto));
        }
Exemple #3
0
        public async Task <Twitter> GetTwitter(string handle)
        {
            var query = new NetUtils.QueryBuilder(TwitterApiUserByName + handle);

            query["user.fields"]         += new[] { "description", "profile_image_url", "public_metrics" };
            using var request             = new HttpRequestMessage(HttpMethod.Get, query.ToString());
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken);
            var response = await _client.SendAsync(request);

            var content = await response.Content.ReadAsStringAsync();

            var dto     = JsonConvert.DeserializeObject <RemoteTwitterResponseDto>(content);
            var twitter = _mapper.Map <Twitter>(dto);

            twitter.Tweets = await GetRecentTweets(twitter.RemoteId);

            return(twitter);
        }
Exemple #4
0
        private async Task <List <Tweet> > GetRecentTweets(string id)
        {
            var query = new NetUtils.QueryBuilder($"https://api.twitter.com/2/users/{id}/tweets");

            query["exclude"]             += new[] { "retweets", "replies" };
            query["tweet.fields"]        += "public_metrics";
            query["max_results"]         += "5"; // 5 is minimum allowed
            using var request             = new HttpRequestMessage(HttpMethod.Get, query.ToString());
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken);
            var response = await _client.SendAsync(request);

            var content = await response.Content.ReadAsStringAsync();

            var dto = JsonConvert.DeserializeObject <RemoteTwitterTweetsResponseDto>(content);

            if (dto == null)
            {
                throw new JsonException();
            }
            return(_mapper.Map <List <Tweet> >(dto.data));
        }