public ApiDetailsDto GetDetails(string id) { RequestParamteres requestParams = InitRequest(); requestParams.ImdbId = id; string omdbapiUrl = ConfigurationManager.AppSettings["omdbapiUrl"]; string responseData = InvokeRequest(omdbapiUrl, requestParams); return(JsonConvert.DeserializeObject <ApiDetailsDto>(responseData)); }
public ApiSearchRootDto Search(string title, int?page) { RequestParamteres requestParams = InitRequest(); requestParams.Title = title; requestParams.Page = page; string omdbapiUrl = ConfigurationManager.AppSettings["omdbapiUrl"]; string responseData = InvokeRequest(omdbapiUrl, requestParams); return(JsonConvert.DeserializeObject <ApiSearchRootDto>(responseData)); }
private string ComposeParameters(RequestParamteres requestDto) { var parameterDictionary = new Dictionary<string, string>(); if (!string.IsNullOrEmpty(requestDto.ImdbId)) { parameterDictionary.Add("i", requestDto.ImdbId); } if (!string.IsNullOrEmpty(requestDto.Title)) { parameterDictionary.Add("s", requestDto.Title); } if (requestDto.Page.HasValue) { parameterDictionary.Add("page", requestDto.Page.Value.ToString()); } parameterDictionary.Add("r", requestDto.ResponseType.ToString()); return ConcatenateParameters(parameterDictionary); }
private string ComposeParameters(RequestParamteres requestDto) { var parameterDictionary = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(requestDto.ImdbId)) { parameterDictionary.Add("i", requestDto.ImdbId); } if (!string.IsNullOrEmpty(requestDto.Title)) { parameterDictionary.Add("s", requestDto.Title); } if (requestDto.Page.HasValue) { parameterDictionary.Add("page", requestDto.Page.Value.ToString()); } parameterDictionary.Add("r", requestDto.ResponseType.ToString()); return(ConcatenateParameters(parameterDictionary)); }
private string InvokeRequest(string apiUrl, RequestParamteres requestDto) { string composeParameters = ComposeParameters(requestDto); string requestUrl = apiUrl + "?" + composeParameters; WebRequest request = WebRequest.Create(requestUrl); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); if (dataStream != null) { var reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); return responseFromServer; } return null; }
private string InvokeRequest(string apiUrl, RequestParamteres requestDto) { string composeParameters = ComposeParameters(requestDto); string requestUrl = apiUrl + "?" + composeParameters; WebRequest request = WebRequest.Create(requestUrl); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); if (dataStream != null) { var reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); return(responseFromServer); } return(null); }