Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> SendHttpRequestAsync(PartyGoer user, SpotifyEndpoint spotifyEndpoint, ApiParameters queryStringParameters, object requestBodyParameters)
        {
            await RefreshTokenForUserAsync(user.GetId());

            string spotifyEndpointUrl = spotifyEndpoint.EndpointUrl;

            // look to see if spotifyendpoint has keys
            if (spotifyEndpoint?.Keys != null)
            {
                // we need to verify these keys exist in api parameters
                foreach (string key in spotifyEndpoint.Keys)
                {
                    if (!queryStringParameters.Keys.ContainsKey(key))
                    {
                        throw new Exception($"Endpoint: {spotifyEndpoint} says it contains a key: {key} but it is not found in parameters");
                    }

                    spotifyEndpointUrl = spotifyEndpointUrl.Replace(key, queryStringParameters.Keys[key]);
                }
            }

            using (var requestMessage = new HttpRequestMessage(spotifyEndpoint.HttpMethod, spotifyEndpointUrl + AddQueryStrings(queryStringParameters)))
            {
                requestMessage.Headers.Authorization = await _spotifyAuthentication.GetAuthenticationHeaderForPartyGoerAsync(user.GetId());

                if (requestBodyParameters != null)
                {
                    requestMessage.Content = new StringContent(JsonConvert.SerializeObject(requestBodyParameters));
                }

                return(await _httpClient.SendAsync(requestMessage));
            }
        }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> SendHttpRequestAsync(string spotifyId, SpotifyEndpoint spotifyEndpoint, object content = null, bool useQueryString = false)
        {
            await RefreshTokenForUserAsync(spotifyId);

            using (var requestMessage = new HttpRequestMessage(spotifyEndpoint.HttpMethod, spotifyEndpoint.EndpointUrl + (useQueryString ? $"?{content}" : string.Empty)))
            {
                requestMessage.Headers.Authorization = await _spotifyAuthentication.GetAuthenticationHeaderForPartyGoerAsync(spotifyId);

                if (content != null)
                {
                    if (!useQueryString)
                    {
                        requestMessage.Content = new StringContent(JsonConvert.SerializeObject(content));
                    }
                }


                return(await _httpClient.SendAsync(requestMessage));
            }
        }
Ejemplo n.º 3
0
 public async Task <HttpResponseMessage> SendHttpRequestAsync(PartyGoer user, SpotifyEndpoint spotifyEndpoint, object content = null, bool useQueryString = false)
 {
     return(await SendHttpRequestAsync(user.GetId(), spotifyEndpoint, content, useQueryString));
 }
Ejemplo n.º 4
0
 public async Task <HttpResponseMessage> SendHttpRequestAsync(PartyGoer user, SpotifyEndpoint endpoint, ApiParameters parameters)
 {
     return(await SendHttpRequestAsync(user, endpoint, parameters, null));
 }