Exemplo n.º 1
0
        public TResult Get <TResult>(string resource, QueryStringParameter queryParameters = null)
        {
            var statusCode = default(HttpStatusCode);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(this.baseAddress);

                if (this.customHeaders.IsAny())
                {
                    AddHeaderInClientRequest(this.customHeaders.ToArray(), client);
                }

                resource = MakeResource(resource, queryParameters);


                var response = client.GetAsync(resource).Result;
                statusCode = response.StatusCode;

                if (statusCode == HttpStatusCode.OK)
                {
                    var data   = response.Content.ReadAsStringAsync().Result;
                    var result = JsonConvert.DeserializeObject <TResult>(data);
                    return(result);
                }
            }

            throw new InvalidOperationException(statusCode.ToString());
        }
Exemplo n.º 2
0
        private string MakeResource(string resource, QueryStringParameter queryParameters)
        {
            if (queryParameters != null && queryParameters.Get() != null)
            {
                var queryStringUrl = queryParameters.Get().ToQueryString();
                resource = String.Concat(resource, queryStringUrl);
            }

            return(resource);
        }
Exemplo n.º 3
0
        public TResult Get <TResult>(string resource, IDictionary <string, object> queryStringParameters = null)
        {
            var nameValueCollection = new NameValueCollection();

            if (queryStringParameters.IsNotNull())
            {
                foreach (var item in queryStringParameters)
                {
                    nameValueCollection.Add(item.Key, item.Value.ToString());
                }
            }
            var parameters = new QueryStringParameter().Add(nameValueCollection);

            return(this.Get <TResult>(resource, parameters));
        }
Exemplo n.º 4
0
        public TResult Get <TResult>(string resource, NameValueCollection queryStringParameters = null)
        {
            var parameters = new QueryStringParameter().Add(queryStringParameters);

            return(this.Get <TResult>(resource, parameters));
        }