예제 #1
0
        private string AddQueryStrings(ApiParameters queryStringParameters)
        {
            if (queryStringParameters?.Parameters == null)
            {
                return(string.Empty);
            }

            int count = queryStringParameters.Parameters.Count;

            if (count > 0)
            {
                StringBuilder builder = new StringBuilder(35);

                builder.Append("?");
                int i = 0;
                foreach (KeyValuePair <string, object> parameter in queryStringParameters.Parameters)
                {
                    builder.Append($"{parameter.Key}={parameter.Value}");
                    AppendAmpersandConditonallyBetweenParameters(builder, i, count);
                    i++;
                }

                return(builder.ToString());
            }

            return(string.Empty);
        }
예제 #2
0
        private async Task <HttpResponseMessage> SendHttpRequestAsync(PartyGoer user, SpotifyEndpoint spotifyEndpoint, ApiParameters queryStringParameters, object requestBodyParameters)
        {
            await RefreshTokenForUserAsync(user.Id);

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

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

                return(await _httpClient.SendAsync(requestMessage));
            }
        }