/// <summary> /// Get Ping Api Result /// </summary> /// <returns></returns> public async Task <bool> GetPingResult() { RestRequestParameter parameters = new RestRequestParameter( ServiceSettings.ServiceAddress.GetRequestUrl($"/api/ping"), HttpMethod.Get) { IgnoreCertificateErrors = true }; RestServiceClient client = new RestServiceClient(); RestServiceCallResponse result = await client.CallRestServiceAsync <String>(parameters); var resultObject = JsonConvert.DeserializeObject <bool>(result.ResultObject.ToString()); return(resultObject); }
/// <summary> /// classworks POST Api Client Method /// </summary> /// <param name="qp"></param> /// <returns></returns> public async Task <List <ClassworkSummary> > GetClassworkSummary(QueryParameter qp) { RestRequestParameter parameters = new RestRequestParameter( ServiceSettings.ServiceAddress.GetRequestUrl($"/api/{_endpointName}?offset={qp.Offset}&limit={qp.Limit}"), HttpMethod.Get, headerParameters: GetAccessTokenHeader()) { IgnoreCertificateErrors = true }; RestServiceClient client = new RestServiceClient(); RestServiceCallResponse result = await client.CallRestServiceAsync <String>(parameters); var resultObject = JsonConvert.DeserializeObject <List <ClassworkSummary> >(result.ResultObject.ToString()); return(resultObject); }
/// <summary> /// Generic http rest call method with all parameters supplied /// </summary> /// <typeparam name="T"></typeparam> /// <param name="restRequestParameter"></param> /// <returns></returns> public async Task <RestServiceCallResponse> CallRestServiceAsync <T>(RestRequestParameter restRequestParameter) { RestServiceCallResponse result = null; _restRequest = new RestRequest(); HttpResponseMessage response = await _restRequest.SendRequestAsync(restRequestParameter); if (restRequestParameter.SuccessStatusCodes.Contains(response.StatusCode)) { try { Object resultContent; if (typeof(T) == typeof(Stream)) { resultContent = await response.Content.ReadAsStreamAsync(); } else if (typeof(T) == typeof(String)) { resultContent = await response.Content.ReadAsStringAsync(); } else if (typeof(T) == typeof(byte[])) { resultContent = await response.Content.ReadAsByteArrayAsync(); } else { throw new Exception("This type is not supported"); } result = new RestServiceCallResponse(resultContent, true, null, response.StatusCode, response.Headers); } catch (Exception ex) { result = new RestServiceCallResponse(null, false, ex, response.StatusCode, response.Headers); } } else { result = new RestServiceCallResponse(null, false, await ParseResponseErrorMessageContent(response), response.StatusCode, response.Headers); } return(result); }
/// <summary> /// classworkd/summary POST Api Client Method /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public async Task <List <ClassworkSummary> > GetClassworkSummary(DateTime startDate, DateTime endDate) { FilterParameter param = new FilterParameter() { StartDate = startDate, EndDate = endDate }; StringContent postContent = new StringContent(JsonConvert.SerializeObject(param), Encoding.UTF8, "application/json"); RestRequestParameter parameters = new RestRequestParameter( ServiceSettings.ServiceAddress.GetRequestUrl($"/api/{_endpointName}/summary"), HttpMethod.Post, headerParameters: GetAccessTokenHeader(), contentParameter: postContent) { IgnoreCertificateErrors = true }; RestServiceClient client = new RestServiceClient(); RestServiceCallResponse result = await client.CallRestServiceAsync <String>(parameters); var resultObject = JsonConvert.DeserializeObject <List <ClassworkSummary> >(result.ResultObject.ToString()); return(resultObject); }