Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Threading.Tasks;
- using Customer.Dtos;
- using Customer.Dtos.CampaignCustomer;
- using Customer.Dtos.CampaignSignOff;
- using Customer.Dtos.CreditBureauImport;
- using Customer.Dtos.Fi;
- using Customer.RestClient.Requests;
- using Pliny.SharedKernel.Api.Responses;
- using Pliny.SharedKernel.Data.RestClient.Exceptions;
- using RestSharp;
- using RestSharp.Authenticators;
- namespace Customer.RestClient
- {
- /// <inheritdoc cref="ICustomerApi" />
- public class CustomerRestClient : Pliny.SharedKernel.Data.RestClient.RestClient, ICustomerApi
- {
- /// <inheritdoc />
- public CustomerRestClient(Uri baseUri) : base(baseUri)
- {
- }
- /// <inheritdoc />
- public CustomerRestClient(string baseUri) : base(baseUri)
- {
- }
- /// <inheritdoc />
- public Task<DataObjectResponse<StatusDto>> GetCampaignSignOffStatusAsync(GetCampaignSignOffStatusRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{id}/campaign-sign-off/status", Method.GET);
- restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var t = new Task<DataObjectResponse<StatusDto>>(() =>
- {
- var response = restClient.Execute<DataObjectResponse<StatusDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException<DataObjectResponse<StatusDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException<DataObjectResponse<StatusDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException<DataObjectResponse<StatusDto>>(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
- );
- }
- return response.Data;
- });
- t.Start();
- return t;
- }
- /// <inheritdoc />
- public async Task<DataObjectResponse<CustomerImportOperationDto>> LatestCustomerImportOperationAsync(GetLatestOperationRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{id}/customer-import/operation/latest", Method.GET);
- restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CustomerImportOperationDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- public async Task<DataObjectResponse<CreditBureauImportOperationDto>> LatestCreditBureauImportOperationAsync(GetLatestOperationRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{id}/bureau-import/operation/latest", Method.GET);
- restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CreditBureauImportOperationDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- [Obsolete("Use ICustomerApi.GetCampaignSignOffStatusAsync() instead.")]
- public Task<DataObjectResponse<ImportUpdateDto>> GetLatestOperationAsync(GetLatestOperationRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignId}/import-update", Method.GET);
- restRequest.AddParameter("campaignId", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var t = new Task<DataObjectResponse<ImportUpdateDto>>(() =>
- {
- var response = restClient.Execute<DataObjectResponse<ImportUpdateDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException<DataObjectResponse<ImportUpdateDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException<DataObjectResponse<ImportUpdateDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.NotFound)
- {
- return null;
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException<DataObjectResponse<ImportUpdateDto>>(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
- );
- }
- return response.Data;
- });
- t.Start();
- return t;
- }
- /// <inheritdoc />
- public Task<DataListResponse<GetCampaignCustomerDto>> GetCampaignCustomersAsync(GetCampaignCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{id}/customers", Method.GET);
- restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var t = new Task<DataListResponse<GetCampaignCustomerDto>>(() =>
- {
- var response = restClient.Execute<DataListResponse<GetCampaignCustomerDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException<DataListResponse<GetCampaignCustomerDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException<DataListResponse<GetCampaignCustomerDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException<DataListResponse<GetCampaignCustomerDto>>(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
- );
- }
- return response.Data;
- });
- t.Start();
- return t;
- }
- /// <inheritdoc />
- public Task<DataObjectResponse<LookupMemberIdDto>> LookupMemberIdAsync(LookupMemberIdRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/fi/{fid}/member/{memberId}", Method.GET);
- restRequest.AddUrlSegment("fid", request.Fid);
- restRequest.AddUrlSegment("memberId", request.MemberId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var t = new Task<DataObjectResponse<LookupMemberIdDto>>(() =>
- {
- var response = restClient.Execute<DataObjectResponse<LookupMemberIdDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException<DataObjectResponse<LookupMemberIdDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException<DataObjectResponse<LookupMemberIdDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException<DataObjectResponse<LookupMemberIdDto>>(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
- );
- }
- return response.Data;
- });
- t.Start();
- return t;
- }
- /// <inheritdoc />
- public bool ImportExperianCustomer(ImportExperianCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{eventId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("eventId", request.EventId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customer);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool ImportEquifaxCustomer(ImportEquifaxCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{eventId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("eventId", request.EventId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customer);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool ImportTransUnionCustomer(ImportTransUnionCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{eventId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("eventId", request.EventId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customer);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool ImportDatamyxCustomer(ImportDatamyxCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{eventId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("eventId", request.EventId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customer);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool BatchImportExperianCustomers(BatchImportExperianCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> BatchImportExperianCustomersAsync(BatchImportExperianCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool BatchImportEquifaxCustomers(BatchImportEquifaxCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> BatchImportEquifaxCustomersAsync(BatchImportEquifaxCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool BatchImportTransUnionCustomers(BatchImportTransUnionCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> BatchImportTransUnionCustomersAsync(BatchImportTransUnionCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public bool BatchImportDatamyxCustomers(BatchImportDatamyxCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> BatchImportDatamyxCustomersAsync(BatchImportDatamyxCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{requestId}/batch", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public DataListResponse<Guid> ProcessingCreditBureauImports(
- ProcessingCreditBureauImportsRequest request
- )
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/credit-bureau-import/processing", Method.GET);
- var response = restClient.Execute<DataListResponse<Guid>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- public async Task<DataListResponse<Guid>> ProcessingCreditBureauImportsAsync(
- ProcessingCreditBureauImportsRequest request
- )
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/credit-bureau-import/processing", Method.GET);
- var response = await restClient.ExecuteTaskAsync<DataListResponse<Guid>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- public bool RollupCreditBureauImportLogs(RollupCreditBureauImportLogsRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/credit-bureau-import/rollup-logs/{operationId}", Method.PUT);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> RollupCreditBureauImportLogsAsync(
- RollupCreditBureauImportLogsRequest request
- )
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/credit-bureau-import/rollup-logs/{operationId}", Method.PUT);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public DataListResponse<Guid> ProcessingCustomerImports(ProcessingCustomerImportsRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/customer-import/processing", Method.GET);
- var response = restClient.Execute<DataListResponse<Guid>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- public async Task<DataListResponse<Guid>> ProcessingCustomerImportsAsync(
- ProcessingCustomerImportsRequest request
- )
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/customer-import/processing", Method.GET);
- var response = await restClient.ExecuteTaskAsync<DataListResponse<Guid>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- /// <inheritdoc />
- public bool RollupCustomerImportLogs(RollupCustomerImportLogsRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/customer-import/rollup-logs/{operationId}", Method.PUT);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> RollupCustomerImportLogsAsync(RollupCustomerImportLogsRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/scheduling/customer-import/rollup-logs/{operationId}", Method.PUT);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- var response = await restClient.ExecuteTaskAsync(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public DataObjectResponse<RandomCampaignCustomerDto> RandomCampaignCustomer(RandomCampaignCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignId}/customers/random", Method.GET);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var response = restClient.Execute<DataObjectResponse<RandomCampaignCustomerDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.NotFound)
- {
- return null;
- }
- return response.Data;
- }
- /// <inheritdoc />
- public DataObjectResponse<CampaignCustomerDto> GetCampaignCustomer(GetCampaignCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignId}/customers/{customerId}", Method.GET);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("customerId", request.CustomerId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var response = restClient.Execute<DataObjectResponse<CampaignCustomerDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.OK)
- {
- return response.Data;
- }
- return null;
- }
- /// <inheritdoc />
- public async Task<DataObjectResponse<CampaignCustomerDto>> GetCampaignCustomerAsync(GetCampaignCustomerRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignId}/customers/{customerId}", Method.GET);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("customerId", request.CustomerId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CampaignCustomerDto>>(restRequest).ConfigureAwait(false);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.OK ? response.Data : null;
- }
- /// <inheritdoc />
- public bool BatchImportCustomers(BatchImportCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- //webRequest.Timeout
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/customer-import/operation/{operationId}/data/customer/{requestId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = restClient.Execute(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public async Task<bool> BatchImportCustomersAsync(BatchImportCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- restClient.ConfigureWebRequest(webRequest =>
- {
- webRequest.ServicePoint.Expect100Continue = false;
- webRequest.KeepAlive = true;
- //webRequest.Timeout
- });
- var restRequest = new RestRequest("/campaign/{campaignId}/customer-import/operation/{operationId}/data/customer/{requestId}", Method.POST);
- restRequest.AddUrlSegment("campaignId", request.CampaignId);
- restRequest.AddUrlSegment("operationId", request.OperationId);
- restRequest.AddUrlSegment("requestId", request.RequestId);
- restRequest.AddHeader("FID", request.Fid.ToString());
- restRequest.AddJsonBody(request.Customers);
- var response = await restClient.ExecuteTaskAsync(restRequest).ConfigureAwait(false);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.StatusCode == HttpStatusCode.NoContent;
- }
- /// <inheritdoc />
- public Task<DataObjectResponse<CustomerDOBDto>> GetCustomerDOBAsync(GetCustomerDOBRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignid}/customers/{customerId}/dob", Method.GET);
- restRequest.AddParameter("campaignid", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddParameter("customerId", request.CustomerId, ParameterType.UrlSegment);
- var t = new Task<DataObjectResponse<CustomerDOBDto>>(() =>
- {
- var response = restClient.Execute<DataObjectResponse<CustomerDOBDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException<DataObjectResponse<CustomerDOBDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper
- .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
- DataObjectResponse<CustomerDOBDto>>>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException<DataObjectResponse<CustomerDOBDto>>(
- response.StatusDescription,
- response.StatusDescription,
- Mapper
- .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
- DataObjectResponse<CustomerDOBDto>>>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException<DataObjectResponse<CustomerDOBDto>>(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper
- .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
- DataObjectResponse<CustomerDOBDto>>>(response)
- );
- }
- return response.Data;
- });
- t.Start();
- return t;
- }
- /// <inheritdoc />
- public async Task<DataListResponse<CampaignCustomerDto>> GetCampaignCustomersAsync(GetCustomersRequest request)
- {
- var restClient = new RestSharp.RestClient(Uri)
- {
- Authenticator = new JwtAuthenticator(request.AccessToken)
- };
- var restRequest = new RestRequest("/campaign/{campaignid}/customers/within", Method.POST);
- restRequest.AddParameter("campaignid", request.CampaignId, ParameterType.UrlSegment);
- restRequest.AddJsonBody(request.CustomerIds);
- var response = await restClient.ExecuteTaskAsync<DataListResponse<CampaignCustomerDto>>(restRequest);
- if (response.ErrorException != null)
- {
- throw new HostCommunicationException(
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
- response.ErrorException
- );
- }
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- throw new Http401UnauthorizedException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode == HttpStatusCode.Forbidden)
- {
- throw new Http403ForbiddenException(
- response.StatusDescription,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new HttpResponseCodeException(
- response.StatusDescription,
- response.StatusCode,
- response.StatusDescription,
- Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
- );
- }
- return response.Data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement