public ApiClient(string baseUri, ApiClientParameterCollection headers = null, int timeoutInMilliseconds = 20000) { _headers = headers; _restClient = new RestClient(baseUri) { Authenticator = new NtlmAuthenticator(), Timeout = timeoutInMilliseconds }; }
private static void AddQueryParameters(IRestRequest request, ApiClientParameterCollection queryParameters) { if (queryParameters == null) { return; } foreach (var parameter in queryParameters) { request.AddQueryParameter(parameter.Key, parameter.Value); } }
private static void AddUrlSegments(IRestRequest request, ApiClientParameterCollection urlSegments) { if (urlSegments == null) { return; } foreach (var segment in urlSegments) { request.AddUrlSegment(segment.Key, segment.Value); } }
private static void AddHeaders(IRestRequest request, ApiClientParameterCollection headers) { if (headers == null) { return; } foreach (var header in headers) { request.AddHeader(header.Key, header.Value); } }
public static void CallProviderSearch() { var apiClient = new ApiClient("http://hc.fnct.webservice.ia.iafg.net:50080/HCMWPN37"); var queryParameters = new ApiClientParameterCollection(); queryParameters.Add("name", "tremblay"); queryParameters.Add("specialty_id", "12"); queryParameters.Add("province_code", "QC"); var response = apiClient.Get <dynamic>("v1/providers", null, queryParameters); return; }
public static void CallFiveLastClaims() { var headers = ApiClient.CreateParameterCollection("Bearer", "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1NDY2Mzk5MjEsInVuaXF1ZV9uYW1lIjoic3RhZmYiLCJkb21haW4iOiJMSUFET00wMSIsImlzcyI6Imh0dHA6Ly90b2tlbi5pYS5jYSIsImF1ZCI6Imh0dHA6Ly93d3cuaWEuY2EiLCJyb2xlIjoiR3JvdXBJbnN1cmFuY2VTdGFmZk1lbWJlciIsIm5hbWVpZCI6InN0YWZmIiwiY2xpZW50TnVtYmVyIjoiIiwiY29tcGFueUNvZGUiOiIwIn0.V1KQLKHlCx4JkCN3UV-T5dxRHw2viL0h8kJH3ueBTXgKvXMQ0Fxfoh2SZ11MMXfjDwfMJuR_s0_zNfunFjEcmA"); var apiClient = new ApiClient("http://hc.fnct.webservice.ia.iafg.net:50080/HCMWPN30", headers); var queryParameters = new ApiClientParameterCollection(); queryParameters.Add("from_date", "2015-01-01"); queryParameters.Add("start_index", "1"); queryParameters.Add("number_to_fetch", "5"); queryParameters.Add("include_details", "true"); var response = apiClient.Get <dynamic>("v2/membercontracts/0000023551-0000000065-00102/claims/search", null, queryParameters); return; }
private ApiClientResponse <T> ExecuteRequest <T>(Method method, string uri, ApiClientParameterCollection urlSegments = null, ApiClientParameterCollection queryParameters = null, object body = null) { var request = new RestRequest(uri, method); AddHeaders(request, _headers); AddBody(request, body); AddUrlSegments(request, urlSegments); AddQueryParameters(request, queryParameters); var response = _restClient.Execute(request); if (response.StatusCode == HttpStatusCode.NotFound) { return new ApiClientResponse <T> { StatusCode = response.StatusCode, Content = default(T) } } ; if (response.StatusCode == HttpStatusCode.BadRequest) { var content = JObject.Parse(response.Content); var messageObject = content["message"]; var message = messageObject?.ToString() ?? response.Content; return(new ApiClientResponse <T> { StatusCode = response.StatusCode, Message = message }); } if (response.StatusCode == 0 && response.ResponseStatus == ResponseStatus.TimedOut) { return new ApiClientResponse <T> { StatusCode = HttpStatusCode.RequestTimeout } } ; if ((int)response.StatusCode < 200 || (int)response.StatusCode > 299) { string message = null; if (!string.IsNullOrWhiteSpace(response.Content)) { var content = JObject.Parse(response.Content); var messageObject = content["message"]; message = messageObject?.ToString() ?? response.Content; } if (!string.IsNullOrWhiteSpace(response.ErrorMessage)) { message = response.ErrorMessage; } return(new ApiClientResponse <T> { StatusCode = response.StatusCode, Message = message }); } return(new ApiClientResponse <T> { StatusCode = response.StatusCode, Content = JsonConvert.DeserializeObject <T>(response.Content) }); }
public ApiClientResponse <object> Delete(string uri, ApiClientParameterCollection urlSegments = null) { return(ExecuteRequest <object>(Method.DELETE, uri, urlSegments)); }
public ApiClientResponse <T> Put <T>(string uri, JArray body, ApiClientParameterCollection urlSegments = null) { return(ExecuteRequest <T>(Method.PUT, uri, urlSegments, null, body)); }
public ApiClientResponse <T> Get <T>(string uri, ApiClientParameterCollection urlSegments = null, ApiClientParameterCollection queryParameters = null) { return(ExecuteRequest <T>(Method.GET, uri, urlSegments, queryParameters)); }
internal ApiClient(IRestClient restClient, string baseUri, ApiClientParameterCollection headers = null, int timeoutInMilliseconds = 20000) : this(baseUri, headers, timeoutInMilliseconds) { _restClient = restClient; }