public string GetCountryFromName(string fullName) { const string action = "country"; var headers = new Dictionary <string, string> { { apiKeyHeader, this.countryFilterApiKey } }; var model = new RestServiceModel { Url = $"{this.countryFilterUrl}/{action}/{fullName}", Headers = headers, Type = "GET" }; var result = this.dataService.GetResult <CountryInfoResponse>(model); return(result.Country); }
/// <summary> /// send request return json and deserialize into a given type, T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public T GetResult <T>(RestServiceModel model) { var request = (HttpWebRequest)WebRequest.Create(model.Url); this.SetRequestHeaders(request, model.Headers); request.Method = model.Type; var response = request.GetResponse(); var responseBody = string.Empty; using (var responseStream = response.GetResponseStream()) { if (responseStream != null) { using (var responseReader = new StreamReader(responseStream)) { responseBody = responseReader.ReadToEnd(); } } } return(JsonConvert.DeserializeObject <T>(responseBody)); }