/// <summary> /// This method gets the estimate from MBE. /// </summary> /// <param name="claimId">Represents the claim id.</param> /// <returns>The serialized estimate.</returns> public async Task <string> GetEstimageForClaim(string claimId) { var estimateInputDataForMbe = new Dictionary <string, string> { { "claimId", claimId } }; var estimateInputData = JsonConvert.SerializeObject(estimateInputDataForMbe); var estimateInputContentJson = new StringContent(estimateInputData, Encoding.UTF8, "application/json"); HttpResponseMessage estimateResponse = await DownloadEstimateFromMbe(estimateInputContentJson); Console.WriteLine("[ {0} ] : GET ESTIMATE : Received response from MBE with reason phrase : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), estimateResponse.ReasonPhrase); if (_errorStatus.Contains(estimateResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); estimateResponse = await DownloadEstimateFromMbe(estimateInputContentJson); } if (estimateResponse.ReasonPhrase == "Not Found") { return(null); } string downloadEstimateContent = await estimateResponse.Content.ReadAsStringAsync(); return(downloadEstimateContent); }
/// <summary> /// This method gets a get by it's ID. /// </summary> /// <returns>>The existing claim.</returns> /// <param name="claimId">Claim identifier.</param> public async Task <string> GetClaim(string claimId) { if (string.IsNullOrEmpty(claimId)) { throw new ArgumentNullException(nameof(claimId), "Cannot be null or empty."); } var claimResponse = await GetClaimFromMbe(claimId); Console.WriteLine("[ {0} ] : GET claim by ID : MBE endpoint returned with response phrase : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimResponse.ReasonPhrase); if (_errorStatus.Contains(claimResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchAccessToken(_mbeUrl); claimResponse = await GetClaimFromMbe(claimId); } else if (claimResponse.ReasonPhrase == "Not Found") { return(null); } var claimResult = await claimResponse.Content.ReadAsStringAsync(); Console.WriteLine("[ {0} ] : GET claim by ID : response received from MBE is : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimResult); return(claimResult); }
/// <summary> /// Async tast to post claim video from MBE using GetVideoUrlForClaim() /// Uses AXN token and Generate DRIVERS token if expires /// </summary> /// <param name="claimData">Represents the claim data.</param> /// <returns></returns> public async Task <string> GetClaimVideo(object claimData) { VideoInput videoData = new VideoInput { claim = claimData, videoVersion = 1, userAgent = "" }; string claimJsonData = JsonConvert.SerializeObject(videoData); var claimContentJson = new StringContent(claimJsonData, Encoding.UTF8, "application/json"); var videoRsponse = await GetVideoUrlForClaim(claimContentJson); Console.WriteLine("[ {0} ] : GET VIDEO : Response received from MBE with reason phrase as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), videoRsponse.ReasonPhrase); if (_errorStatus.Contains(videoRsponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); videoRsponse = await GetVideoUrlForClaim(claimContentJson); } if (videoRsponse.ReasonPhrase == "Not Found") { return(null); } string videoResult = await videoRsponse.Content.ReadAsStringAsync(); return(videoResult); }
/// <summary> /// This method updates the vehivle VIN from a claim. /// </summary> /// <param name="vinInputData">Represents the vin input data.</param> /// <returns>The vehicle updation VIN response.</returns> public async Task <string> UpdateVehicleVin(vehicleUpdateInput vinInputData) { var jsonData = JsonConvert.SerializeObject(vinInputData); var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); var vinDecodeData = await UpdateVehicleVintoMbe(jsonContent); Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Response received from MBE with reason phrase as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), vinDecodeData.ReasonPhrase); if (_errorStatus.Contains(vinDecodeData.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); vinDecodeData = await UpdateVehicleVintoMbe(jsonContent); } if (vinDecodeData.ReasonPhrase == "Not Found") { return(null); } var vinDecodeResults = vinDecodeData.Content.ReadAsStringAsync(); return(vinDecodeResults.Result); }
/// <summary> /// This method calls the MBE api to update an existing claim. /// </summary> /// <param name="id">Represents the claim identifier.</param> /// <param name="claimUpdateData">Represents the claim data to update.</param> /// <returns>An instance of HttpResponseMessage with the request results.</returns> async Task <HttpResponseMessage> PutClaimToMbe(string id, HttpContent claimUpdateData) { HttpClient httpClient = new HttpClient(); string claimPutUrl = _mbeUrl + "api/claims/" + id + "?access_token=" + InMemoryStorage.Instance().StoredToken; Console.WriteLine("[ {0} ] : UPDATE CLAIM : Update claim request sent to MBE using URL : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutUrl); HttpResponseMessage claimPutResponse = await httpClient.PutAsync(claimPutUrl, claimUpdateData); return(claimPutResponse); }
/// <summary> /// Gets the claim from mbe. /// </summary> /// <returns>The claim from mbe.</returns> /// <param name="claimId">Claim identifier.</param> async Task <HttpResponseMessage> GetClaimFromMbe(string claimId) { HttpClient client = new HttpClient(); string inputUrl = _mbeUrl + "api/claims/" + claimId + "?access_token=" + InMemoryStorage.Instance().StoredToken; Console.WriteLine("[ {0} ] : GET claim by ID : MBE endpoint used to get claim details : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), inputUrl); var claimResponse = await client.GetAsync(inputUrl); return(claimResponse); }
/// <summary> /// This method calls the MBE api to submit a file. /// </summary> /// <param name="photoData">Represents the photo data.</param> /// <returns></returns> async Task <HttpResponseMessage> PostClaimPhotoToMbe(HttpContent photoData) { var client = new HttpClient(); string photoPostUrl = _mbeUrl + "api/Attachments/uploadImage?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : POST PHOTO : Call made to MBE using URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), photoPostUrl); var photoUploadResponse = await client.PostAsync(photoPostUrl, photoData); return(photoUploadResponse); }
/// <summary> /// This method calls the MBE api in order to get the estimate. /// </summary> /// <param name="claimIdData">Represents the claim data.</param> /// <returns>The estimate response from MBE.</returns> private async Task <HttpResponseMessage> DownloadEstimateFromMbe(HttpContent claimIdData) { var httpClient = new HttpClient(); string downloadEstimateUrl = _mbeUrl + "api/Attachments/downloadEstimateReport?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : GET ESTIMATE : Call made to MBE using URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), downloadEstimateUrl); HttpResponseMessage estimateFiles = await httpClient.PostAsync(downloadEstimateUrl, claimIdData); return(estimateFiles); }
/** * Private async method to get claim video data by calling MBE API * uses StoredDriverToken (DRIVER) to get required access * */ private async Task <HttpResponseMessage> GetVideoUrlForClaim(HttpContent videoData) { var client = new HttpClient(); string videoPostUrl = _mbeUrl + "api/UserActionUtilities/getVideoURLFromSundaySky?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : GET VIDEO : Call made to MBE with URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), videoPostUrl); var videoPostResponse = await client.PostAsync(videoPostUrl, videoData); return(videoPostResponse); }
/// <summary> /// This method calls the MBE api to update the vehicle VIN information. /// </summary> /// <param name="vinData">Represents the VIN data.</param> /// <returns></returns> async Task <HttpResponseMessage> UpdateVehicleVintoMbe(HttpContent vinData) { var client = new HttpClient(); string eagleVinUrl = _mbeUrl + "api/claims/updateClaimByEagleApiVin?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Request made to MBE using URL : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), eagleVinUrl); HttpResponseMessage updatedClaim = await client.PostAsync(eagleVinUrl, vinData); return(updatedClaim); }
/// <summary> /// Posts the claim. /// </summary> /// <returns>The claim.</returns> /// <param name="claim">Claim.</param> public async Task <string> PostClaim(ClaimInputs claim) { if (claim == null) { throw new ArgumentNullException(nameof(claim), "Cannot be null"); } Console.WriteLine("[{0}] : Creating the claim # : [ {1} ] : with taskID : [ {2} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claim.claimNumber, claim.taskId); string serializedClaim = JsonConvert.SerializeObject(claim, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var requestBody = new StringContent(serializedClaim, Encoding.UTF8, "application/json"); string accessToken = InMemoryStorage.Instance().StoredDriverToken; var httpClient = new HttpClient(); var requestMessage = new HttpRequestMessage { RequestUri = new Uri($"{_mbeUrl}api/claims?access_token={accessToken}"), Method = HttpMethod.Post, Content = requestBody }; requestMessage.Headers.Add("correlation_id", ApiHelpers.GetRandomString()); HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage); if (_errorStatus.Contains(responseMessage.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); return(await PostClaim(claim)); } if (responseMessage.StatusCode != HttpStatusCode.OK && responseMessage.StatusCode != HttpStatusCode.Created) { return(string.Empty); } return(await responseMessage.Content.ReadAsStringAsync()); }
/// <summary> /// This method abstracts the orchestration to add a comment to a given claim. /// </summary> /// <returns>The claim comments.</returns> /// <param name="claimId">Represents the claim id.</param> /// <param name="claimNumber">Represents the claim number.</param> /// <param name="orgId">Represents the organization id.</param> /// <param name="comments">Represents the comments text.</param> public async Task <HttpResponseMessage> SubmitClaimComments(string claimId, string claimNumber, string orgId, string comments) { if (string.IsNullOrEmpty(claimId) || claimId.Trim().Length == 0) { throw new ArgumentNullException(nameof(claimId), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(claimNumber) || claimNumber.Trim().Length == 0) { throw new ArgumentNullException(nameof(claimNumber), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(orgId) || orgId.Trim().Length == 0) { throw new ArgumentNullException(nameof(orgId), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(comments) || comments.Trim().Length == 0) { throw new ArgumentNullException(nameof(comments), NullEmptyArgumentMessage); } string resourceUrl = $"{_mbeUrl}api/claims/{claimId}/attachmentcomments?access_token={InMemoryStorage.Instance().StoredToken}"; Console.WriteLine($"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : POST ATTACHMENT COMMENT BY ID : " + $"{claimId} - Resource URL [ {resourceUrl} ]"); var httpClient = new HttpClient(); var attComment = new { comments, claimNumber, orgId, synched = false }; var requestBody = new StringContent(JsonConvert.SerializeObject(attComment), Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await httpClient.PostAsync(resourceUrl, requestBody); return(responseMessage); }
/// <summary> /// This method updates an existing claim. /// </summary> /// <param name="id">Represents the claim identifier.</param> /// <param name="data">Represents the claim data.</param> /// <returns>The recently created claim serialized.</returns> public async Task <string> UpdateClaim(string id, object data) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or emtpy."); } if (data == null) { throw new ArgumentNullException(nameof(data), "Cannot be null."); } string jsonData = JsonConvert.SerializeObject(data); var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage claimPutResponse = await PutClaimToMbe(id, jsonContent); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Received response from MBE with reason phrase as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutResponse.ReasonPhrase); if (_errorStatus.Contains(claimPutResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchAccessToken(_mbeUrl); claimPutResponse = await PutClaimToMbe(id, jsonContent); } if (claimPutResponse.ReasonPhrase == "Not Found") { return(null); } string claimPutResult = await claimPutResponse.Content.ReadAsStringAsync(); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Received response from MBE with updated claim as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutResult); return(claimPutResult); }
/// <summary> /// Async tast to post claim claim video from MBE using GetVideoUrlForClaim() /// Uses AXN token and Generate DRIVERS token if expires /// </summary> /// <param name="photoData">Represents the photo data.</param> /// <returns>The serialized response from MBE</returns> public async Task <string> PostClaimPhoto(HttpContent photoData) { HttpResponseMessage photoUploadResponse = await PostClaimPhotoToMbe(photoData); Console.WriteLine("[ {0} ] : POST PHOTO : Response received from MBE with reason phrase as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), photoUploadResponse.ReasonPhrase); if (_errorStatus.Contains(photoUploadResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); photoUploadResponse = await PostClaimPhotoToMbe(photoData); } if (photoUploadResponse.ReasonPhrase == "Not Found") { return(null); } string photoUploadResult = await photoUploadResponse.Content.ReadAsStringAsync(); return(photoUploadResult); }