Exemplo n.º 1
0
        /// <summary>
        /// Get the raw response from the API
        /// </summary>
        /// <returns>A key/associated values dictionary</returns>
        public virtual Dictionary <string, List <string> > GetResponseDictionary()
        {
            Uri finalUri       = Endpoint;
            var finalUriString = $"{Endpoint.ToString()}{EndpointSuffix}/";

            if (!String.IsNullOrEmpty(EndpointSuffix))
            {
                try
                {
                    finalUri = new Uri(finalUriString);
                }
                catch (UriFormatException ex) {
                    throw new UriFormatException($"The Uri {finalUriString} for this client is invalid", ex);
                }
            }

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HeaderAuthorizationKey);

                var response = client.GetStringAsync(finalUri).Result;

                var result = new Dictionary <string, List <string> >();
                try {
                    result = ParseHelper.BuildDictionaryFromTabbedAPIResponse(response);
                }
                catch (Exception) {
                    result = ParseHelper.BuildDictionaryFromTabbedAPIResponse(GetMockResponse());
                }

                return(result);
            }
        }