Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.49 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Threading.Tasks;
  4. using Customer.Dtos;
  5. using Customer.Dtos.CampaignCustomer;
  6. using Customer.Dtos.CampaignSignOff;
  7. using Customer.Dtos.CreditBureauImport;
  8. using Customer.Dtos.Fi;
  9. using Customer.RestClient.Requests;
  10. using Pliny.SharedKernel.Api.Responses;
  11. using Pliny.SharedKernel.Data.RestClient.Exceptions;
  12. using RestSharp;
  13. using RestSharp.Authenticators;
  14.  
  15. namespace Customer.RestClient
  16. {
  17. /// <inheritdoc cref="ICustomerApi" />
  18. public class CustomerRestClient : Pliny.SharedKernel.Data.RestClient.RestClient, ICustomerApi
  19. {
  20. /// <inheritdoc />
  21. public CustomerRestClient(Uri baseUri) : base(baseUri)
  22. {
  23. }
  24.  
  25. /// <inheritdoc />
  26. public CustomerRestClient(string baseUri) : base(baseUri)
  27. {
  28. }
  29.  
  30. /// <inheritdoc />
  31. public Task<DataObjectResponse<StatusDto>> GetCampaignSignOffStatusAsync(GetCampaignSignOffStatusRequest request)
  32. {
  33. var restClient = new RestSharp.RestClient(Uri)
  34. {
  35. Authenticator = new JwtAuthenticator(request.AccessToken)
  36. };
  37. var restRequest = new RestRequest("/campaign/{id}/campaign-sign-off/status", Method.GET);
  38. restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
  39. restRequest.AddHeader("FID", request.Fid.ToString());
  40.  
  41. var t = new Task<DataObjectResponse<StatusDto>>(() =>
  42. {
  43. var response = restClient.Execute<DataObjectResponse<StatusDto>>(restRequest);
  44.  
  45. if (response.ErrorException != null)
  46. {
  47. throw new HostCommunicationException(
  48. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  49. response.ErrorException
  50. );
  51. }
  52.  
  53. if (response.StatusCode == HttpStatusCode.Unauthorized)
  54. {
  55. throw new Http401UnauthorizedException<DataObjectResponse<StatusDto>>(
  56. response.StatusDescription,
  57. response.StatusDescription,
  58. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
  59. );
  60. }
  61.  
  62. if (response.StatusCode == HttpStatusCode.Forbidden)
  63. {
  64. throw new Http403ForbiddenException<DataObjectResponse<StatusDto>>(
  65. response.StatusDescription,
  66. response.StatusDescription,
  67. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
  68. );
  69. }
  70.  
  71. if (response.StatusCode != HttpStatusCode.OK)
  72. {
  73. throw new HttpResponseCodeException<DataObjectResponse<StatusDto>>(
  74. response.StatusDescription,
  75. response.StatusCode,
  76. response.StatusDescription,
  77. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<StatusDto>>>(response)
  78. );
  79. }
  80.  
  81. return response.Data;
  82. });
  83.  
  84. t.Start();
  85.  
  86. return t;
  87. }
  88.  
  89. /// <inheritdoc />
  90. public async Task<DataObjectResponse<CustomerImportOperationDto>> LatestCustomerImportOperationAsync(GetLatestOperationRequest request)
  91. {
  92. var restClient = new RestSharp.RestClient(Uri)
  93. {
  94. Authenticator = new JwtAuthenticator(request.AccessToken)
  95. };
  96.  
  97. var restRequest = new RestRequest("/campaign/{id}/customer-import/operation/latest", Method.GET);
  98. restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
  99. restRequest.AddHeader("FID", request.Fid.ToString());
  100.  
  101. var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CustomerImportOperationDto>>(restRequest);
  102.  
  103. if (response.ErrorException != null)
  104. {
  105. throw new HostCommunicationException(
  106. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  107. response.ErrorException
  108. );
  109. }
  110.  
  111. if (response.StatusCode == HttpStatusCode.Unauthorized)
  112. {
  113. throw new Http401UnauthorizedException(
  114. response.StatusDescription,
  115. response.StatusDescription,
  116. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  117. );
  118. }
  119.  
  120. if (response.StatusCode == HttpStatusCode.Forbidden)
  121. {
  122. throw new Http403ForbiddenException(
  123. response.StatusDescription,
  124. response.StatusDescription,
  125. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  126. );
  127. }
  128.  
  129. if (response.StatusCode != HttpStatusCode.OK)
  130. {
  131. throw new HttpResponseCodeException(
  132. response.StatusDescription,
  133. response.StatusCode,
  134. response.StatusDescription,
  135. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  136. );
  137. }
  138.  
  139. return response.Data;
  140. }
  141.  
  142. /// <inheritdoc />
  143. public async Task<DataObjectResponse<CreditBureauImportOperationDto>> LatestCreditBureauImportOperationAsync(GetLatestOperationRequest request)
  144. {
  145. var restClient = new RestSharp.RestClient(Uri)
  146. {
  147. Authenticator = new JwtAuthenticator(request.AccessToken)
  148. };
  149.  
  150. var restRequest = new RestRequest("/campaign/{id}/bureau-import/operation/latest", Method.GET);
  151. restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
  152. restRequest.AddHeader("FID", request.Fid.ToString());
  153.  
  154. var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CreditBureauImportOperationDto>>(restRequest);
  155.  
  156. if (response.ErrorException != null)
  157. {
  158. throw new HostCommunicationException(
  159. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  160. response.ErrorException
  161. );
  162. }
  163.  
  164. if (response.StatusCode == HttpStatusCode.Unauthorized)
  165. {
  166. throw new Http401UnauthorizedException(
  167. response.StatusDescription,
  168. response.StatusDescription,
  169. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  170. );
  171. }
  172.  
  173. if (response.StatusCode == HttpStatusCode.Forbidden)
  174. {
  175. throw new Http403ForbiddenException(
  176. response.StatusDescription,
  177. response.StatusDescription,
  178. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  179. );
  180. }
  181.  
  182. if (response.StatusCode != HttpStatusCode.OK)
  183. {
  184. throw new HttpResponseCodeException(
  185. response.StatusDescription,
  186. response.StatusCode,
  187. response.StatusDescription,
  188. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  189. );
  190. }
  191.  
  192. return response.Data;
  193. }
  194.  
  195.  
  196. /// <inheritdoc />
  197. [Obsolete("Use ICustomerApi.GetCampaignSignOffStatusAsync() instead.")]
  198. public Task<DataObjectResponse<ImportUpdateDto>> GetLatestOperationAsync(GetLatestOperationRequest request)
  199. {
  200. var restClient = new RestSharp.RestClient(Uri)
  201. {
  202. Authenticator = new JwtAuthenticator(request.AccessToken)
  203. };
  204. var restRequest = new RestRequest("/campaign/{campaignId}/import-update", Method.GET);
  205. restRequest.AddParameter("campaignId", request.CampaignId, ParameterType.UrlSegment);
  206. restRequest.AddHeader("FID", request.Fid.ToString());
  207.  
  208. var t = new Task<DataObjectResponse<ImportUpdateDto>>(() =>
  209. {
  210. var response = restClient.Execute<DataObjectResponse<ImportUpdateDto>>(restRequest);
  211.  
  212. if (response.ErrorException != null)
  213. {
  214. throw new HostCommunicationException(
  215. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  216. response.ErrorException
  217. );
  218. }
  219.  
  220. if (response.StatusCode == HttpStatusCode.Unauthorized)
  221. {
  222. throw new Http401UnauthorizedException<DataObjectResponse<ImportUpdateDto>>(
  223. response.StatusDescription,
  224. response.StatusDescription,
  225. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
  226. );
  227. }
  228.  
  229. if (response.StatusCode == HttpStatusCode.Forbidden)
  230. {
  231. throw new Http403ForbiddenException<DataObjectResponse<ImportUpdateDto>>(
  232. response.StatusDescription,
  233. response.StatusDescription,
  234. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
  235. );
  236. }
  237. if (response.StatusCode == HttpStatusCode.NotFound)
  238. {
  239. return null;
  240. }
  241. if (response.StatusCode != HttpStatusCode.OK)
  242. {
  243. throw new HttpResponseCodeException<DataObjectResponse<ImportUpdateDto>>(
  244. response.StatusDescription,
  245. response.StatusCode,
  246. response.StatusDescription,
  247. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<ImportUpdateDto>>>(response)
  248. );
  249. }
  250.  
  251. return response.Data;
  252. });
  253.  
  254. t.Start();
  255.  
  256. return t;
  257. }
  258.  
  259. /// <inheritdoc />
  260. public Task<DataListResponse<GetCampaignCustomerDto>> GetCampaignCustomersAsync(GetCampaignCustomersRequest request)
  261. {
  262. var restClient = new RestSharp.RestClient(Uri)
  263. {
  264. Authenticator = new JwtAuthenticator(request.AccessToken)
  265. };
  266. var restRequest = new RestRequest("/campaign/{id}/customers", Method.GET);
  267. restRequest.AddParameter("id", request.CampaignId, ParameterType.UrlSegment);
  268. restRequest.AddHeader("FID", request.Fid.ToString());
  269.  
  270. var t = new Task<DataListResponse<GetCampaignCustomerDto>>(() =>
  271. {
  272. var response = restClient.Execute<DataListResponse<GetCampaignCustomerDto>>(restRequest);
  273.  
  274. if (response.ErrorException != null)
  275. {
  276. throw new HostCommunicationException(
  277. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  278. response.ErrorException
  279. );
  280. }
  281.  
  282. if (response.StatusCode == HttpStatusCode.Unauthorized)
  283. {
  284. throw new Http401UnauthorizedException<DataListResponse<GetCampaignCustomerDto>>(
  285. response.StatusDescription,
  286. response.StatusDescription,
  287. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
  288. );
  289. }
  290.  
  291. if (response.StatusCode == HttpStatusCode.Forbidden)
  292. {
  293. throw new Http403ForbiddenException<DataListResponse<GetCampaignCustomerDto>>(
  294. response.StatusDescription,
  295. response.StatusDescription,
  296. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
  297. );
  298. }
  299.  
  300. if (response.StatusCode != HttpStatusCode.OK)
  301. {
  302. throw new HttpResponseCodeException<DataListResponse<GetCampaignCustomerDto>>(
  303. response.StatusDescription,
  304. response.StatusCode,
  305. response.StatusDescription,
  306. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataListResponse<GetCampaignCustomerDto>>>(response)
  307. );
  308. }
  309.  
  310. return response.Data;
  311. });
  312.  
  313. t.Start();
  314.  
  315. return t;
  316. }
  317.  
  318. /// <inheritdoc />
  319. public Task<DataObjectResponse<LookupMemberIdDto>> LookupMemberIdAsync(LookupMemberIdRequest request)
  320. {
  321. var restClient = new RestSharp.RestClient(Uri)
  322. {
  323. Authenticator = new JwtAuthenticator(request.AccessToken)
  324. };
  325. var restRequest = new RestRequest("/fi/{fid}/member/{memberId}", Method.GET);
  326. restRequest.AddUrlSegment("fid", request.Fid);
  327. restRequest.AddUrlSegment("memberId", request.MemberId);
  328. restRequest.AddHeader("FID", request.Fid.ToString());
  329.  
  330. var t = new Task<DataObjectResponse<LookupMemberIdDto>>(() =>
  331. {
  332. var response = restClient.Execute<DataObjectResponse<LookupMemberIdDto>>(restRequest);
  333.  
  334. if (response.ErrorException != null)
  335. {
  336. throw new HostCommunicationException(
  337. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  338. response.ErrorException
  339. );
  340. }
  341.  
  342. if (response.StatusCode == HttpStatusCode.Unauthorized)
  343. {
  344. throw new Http401UnauthorizedException<DataObjectResponse<LookupMemberIdDto>>(
  345. response.StatusDescription,
  346. response.StatusDescription,
  347. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
  348. );
  349. }
  350.  
  351. if (response.StatusCode == HttpStatusCode.Forbidden)
  352. {
  353. throw new Http403ForbiddenException<DataObjectResponse<LookupMemberIdDto>>(
  354. response.StatusDescription,
  355. response.StatusDescription,
  356. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
  357. );
  358. }
  359.  
  360. if (response.StatusCode != HttpStatusCode.OK)
  361. {
  362. throw new HttpResponseCodeException<DataObjectResponse<LookupMemberIdDto>>(
  363. response.StatusDescription,
  364. response.StatusCode,
  365. response.StatusDescription,
  366. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<DataObjectResponse<LookupMemberIdDto>>>(response)
  367. );
  368. }
  369. return response.Data;
  370. });
  371.  
  372. t.Start();
  373.  
  374. return t;
  375. }
  376.  
  377. /// <inheritdoc />
  378. public bool ImportExperianCustomer(ImportExperianCustomerRequest request)
  379. {
  380. var restClient = new RestSharp.RestClient(Uri)
  381. {
  382. Authenticator = new JwtAuthenticator(request.AccessToken)
  383. };
  384. restClient.ConfigureWebRequest(webRequest =>
  385. {
  386. webRequest.ServicePoint.Expect100Continue = false;
  387. webRequest.KeepAlive = true;
  388. });
  389. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{eventId}", Method.POST);
  390. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  391. restRequest.AddUrlSegment("operationId", request.OperationId);
  392. restRequest.AddUrlSegment("eventId", request.EventId);
  393. restRequest.AddHeader("FID", request.Fid.ToString());
  394. restRequest.AddJsonBody(request.Customer);
  395.  
  396. var response = restClient.Execute(restRequest);
  397.  
  398. if (response.ErrorException != null)
  399. {
  400. throw new HostCommunicationException(
  401. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  402. response.ErrorException
  403. );
  404. }
  405.  
  406. if (response.StatusCode == HttpStatusCode.Unauthorized)
  407. {
  408. throw new Http401UnauthorizedException(
  409. response.StatusDescription,
  410. response.StatusDescription,
  411. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  412. );
  413. }
  414.  
  415. if (response.StatusCode == HttpStatusCode.Forbidden)
  416. {
  417. throw new Http403ForbiddenException(
  418. response.StatusDescription,
  419. response.StatusDescription,
  420. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  421. );
  422. }
  423.  
  424. return response.StatusCode == HttpStatusCode.NoContent;
  425. }
  426.  
  427. /// <inheritdoc />
  428. public bool ImportEquifaxCustomer(ImportEquifaxCustomerRequest request)
  429. {
  430. var restClient = new RestSharp.RestClient(Uri)
  431. {
  432. Authenticator = new JwtAuthenticator(request.AccessToken)
  433. };
  434. restClient.ConfigureWebRequest(webRequest =>
  435. {
  436. webRequest.ServicePoint.Expect100Continue = false;
  437. webRequest.KeepAlive = true;
  438. });
  439. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{eventId}", Method.POST);
  440. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  441. restRequest.AddUrlSegment("operationId", request.OperationId);
  442. restRequest.AddUrlSegment("eventId", request.EventId);
  443. restRequest.AddHeader("FID", request.Fid.ToString());
  444. restRequest.AddJsonBody(request.Customer);
  445.  
  446. var response = restClient.Execute(restRequest);
  447.  
  448. if (response.ErrorException != null)
  449. {
  450. throw new HostCommunicationException(
  451. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  452. response.ErrorException
  453. );
  454. }
  455.  
  456. if (response.StatusCode == HttpStatusCode.Unauthorized)
  457. {
  458. throw new Http401UnauthorizedException(
  459. response.StatusDescription,
  460. response.StatusDescription,
  461. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  462. );
  463. }
  464.  
  465. if (response.StatusCode == HttpStatusCode.Forbidden)
  466. {
  467. throw new Http403ForbiddenException(
  468. response.StatusDescription,
  469. response.StatusDescription,
  470. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  471. );
  472. }
  473.  
  474. return response.StatusCode == HttpStatusCode.NoContent;
  475. }
  476.  
  477. /// <inheritdoc />
  478. public bool ImportTransUnionCustomer(ImportTransUnionCustomerRequest request)
  479. {
  480. var restClient = new RestSharp.RestClient(Uri)
  481. {
  482. Authenticator = new JwtAuthenticator(request.AccessToken)
  483. };
  484. restClient.ConfigureWebRequest(webRequest =>
  485. {
  486. webRequest.ServicePoint.Expect100Continue = false;
  487. webRequest.KeepAlive = true;
  488. });
  489. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{eventId}", Method.POST);
  490. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  491. restRequest.AddUrlSegment("operationId", request.OperationId);
  492. restRequest.AddUrlSegment("eventId", request.EventId);
  493. restRequest.AddHeader("FID", request.Fid.ToString());
  494. restRequest.AddJsonBody(request.Customer);
  495.  
  496. var response = restClient.Execute(restRequest);
  497.  
  498. if (response.ErrorException != null)
  499. {
  500. throw new HostCommunicationException(
  501. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  502. response.ErrorException
  503. );
  504. }
  505.  
  506. if (response.StatusCode == HttpStatusCode.Unauthorized)
  507. {
  508. throw new Http401UnauthorizedException(
  509. response.StatusDescription,
  510. response.StatusDescription,
  511. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  512. );
  513. }
  514.  
  515. if (response.StatusCode == HttpStatusCode.Forbidden)
  516. {
  517. throw new Http403ForbiddenException(
  518. response.StatusDescription,
  519. response.StatusDescription,
  520. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  521. );
  522. }
  523.  
  524. return response.StatusCode == HttpStatusCode.NoContent;
  525. }
  526.  
  527. /// <inheritdoc />
  528. public bool ImportDatamyxCustomer(ImportDatamyxCustomerRequest request)
  529. {
  530. var restClient = new RestSharp.RestClient(Uri)
  531. {
  532. Authenticator = new JwtAuthenticator(request.AccessToken)
  533. };
  534. restClient.ConfigureWebRequest(webRequest =>
  535. {
  536. webRequest.ServicePoint.Expect100Continue = false;
  537. webRequest.KeepAlive = true;
  538. });
  539. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{eventId}", Method.POST);
  540. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  541. restRequest.AddUrlSegment("operationId", request.OperationId);
  542. restRequest.AddUrlSegment("eventId", request.EventId);
  543. restRequest.AddHeader("FID", request.Fid.ToString());
  544. restRequest.AddJsonBody(request.Customer);
  545.  
  546. var response = restClient.Execute(restRequest);
  547.  
  548. if (response.ErrorException != null)
  549. {
  550. throw new HostCommunicationException(
  551. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  552. response.ErrorException
  553. );
  554. }
  555.  
  556. if (response.StatusCode == HttpStatusCode.Unauthorized)
  557. {
  558. throw new Http401UnauthorizedException(
  559. response.StatusDescription,
  560. response.StatusDescription,
  561. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  562. );
  563. }
  564.  
  565. if (response.StatusCode == HttpStatusCode.Forbidden)
  566. {
  567. throw new Http403ForbiddenException(
  568. response.StatusDescription,
  569. response.StatusDescription,
  570. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  571. );
  572. }
  573.  
  574. return response.StatusCode == HttpStatusCode.NoContent;
  575. }
  576.  
  577. /// <inheritdoc />
  578. public bool BatchImportExperianCustomers(BatchImportExperianCustomersRequest request)
  579. {
  580. var restClient = new RestSharp.RestClient(Uri)
  581. {
  582. Authenticator = new JwtAuthenticator(request.AccessToken)
  583. };
  584. restClient.ConfigureWebRequest(webRequest =>
  585. {
  586. webRequest.ServicePoint.Expect100Continue = false;
  587. webRequest.KeepAlive = true;
  588. });
  589. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{requestId}/batch", Method.POST);
  590. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  591. restRequest.AddUrlSegment("operationId", request.OperationId);
  592. restRequest.AddUrlSegment("requestId", request.RequestId);
  593. restRequest.AddHeader("FID", request.Fid.ToString());
  594. restRequest.AddJsonBody(request.Customers);
  595.  
  596. var response = restClient.Execute(restRequest);
  597.  
  598. if (response.ErrorException != null)
  599. {
  600. throw new HostCommunicationException(
  601. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  602. response.ErrorException
  603. );
  604. }
  605.  
  606. if (response.StatusCode == HttpStatusCode.Unauthorized)
  607. {
  608. throw new Http401UnauthorizedException(
  609. response.StatusDescription,
  610. response.StatusDescription,
  611. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  612. );
  613. }
  614.  
  615. if (response.StatusCode == HttpStatusCode.Forbidden)
  616. {
  617. throw new Http403ForbiddenException(
  618. response.StatusDescription,
  619. response.StatusDescription,
  620. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  621. );
  622. }
  623.  
  624. return response.StatusCode == HttpStatusCode.NoContent;
  625. }
  626.  
  627. /// <inheritdoc />
  628. public async Task<bool> BatchImportExperianCustomersAsync(BatchImportExperianCustomersRequest request)
  629. {
  630. var restClient = new RestSharp.RestClient(Uri)
  631. {
  632. Authenticator = new JwtAuthenticator(request.AccessToken)
  633. };
  634. restClient.ConfigureWebRequest(webRequest =>
  635. {
  636. webRequest.ServicePoint.Expect100Continue = false;
  637. webRequest.KeepAlive = true;
  638. });
  639. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/experian/{requestId}/batch", Method.POST);
  640. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  641. restRequest.AddUrlSegment("operationId", request.OperationId);
  642. restRequest.AddUrlSegment("requestId", request.RequestId);
  643. restRequest.AddHeader("FID", request.Fid.ToString());
  644. restRequest.AddJsonBody(request.Customers);
  645.  
  646. var response = await restClient.ExecuteTaskAsync(restRequest);
  647.  
  648. if (response.ErrorException != null)
  649. {
  650. throw new HostCommunicationException(
  651. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  652. response.ErrorException
  653. );
  654. }
  655.  
  656. if (response.StatusCode == HttpStatusCode.Unauthorized)
  657. {
  658. throw new Http401UnauthorizedException(
  659. response.StatusDescription,
  660. response.StatusDescription,
  661. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  662. );
  663. }
  664.  
  665. if (response.StatusCode == HttpStatusCode.Forbidden)
  666. {
  667. throw new Http403ForbiddenException(
  668. response.StatusDescription,
  669. response.StatusDescription,
  670. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  671. );
  672. }
  673.  
  674. return response.StatusCode == HttpStatusCode.NoContent;
  675. }
  676.  
  677. /// <inheritdoc />
  678. public bool BatchImportEquifaxCustomers(BatchImportEquifaxCustomersRequest request)
  679. {
  680. var restClient = new RestSharp.RestClient(Uri)
  681. {
  682. Authenticator = new JwtAuthenticator(request.AccessToken)
  683. };
  684. restClient.ConfigureWebRequest(webRequest =>
  685. {
  686. webRequest.ServicePoint.Expect100Continue = false;
  687. webRequest.KeepAlive = true;
  688. });
  689. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{requestId}/batch", Method.POST);
  690. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  691. restRequest.AddUrlSegment("operationId", request.OperationId);
  692. restRequest.AddUrlSegment("requestId", request.RequestId);
  693. restRequest.AddHeader("FID", request.Fid.ToString());
  694. restRequest.AddJsonBody(request.Customers);
  695.  
  696. var response = restClient.Execute(restRequest);
  697.  
  698. if (response.ErrorException != null)
  699. {
  700. throw new HostCommunicationException(
  701. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  702. response.ErrorException
  703. );
  704. }
  705.  
  706. if (response.StatusCode == HttpStatusCode.Unauthorized)
  707. {
  708. throw new Http401UnauthorizedException(
  709. response.StatusDescription,
  710. response.StatusDescription,
  711. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  712. );
  713. }
  714.  
  715. if (response.StatusCode == HttpStatusCode.Forbidden)
  716. {
  717. throw new Http403ForbiddenException(
  718. response.StatusDescription,
  719. response.StatusDescription,
  720. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  721. );
  722. }
  723.  
  724. return response.StatusCode == HttpStatusCode.NoContent;
  725. }
  726.  
  727. /// <inheritdoc />
  728. public async Task<bool> BatchImportEquifaxCustomersAsync(BatchImportEquifaxCustomersRequest request)
  729. {
  730. var restClient = new RestSharp.RestClient(Uri)
  731. {
  732. Authenticator = new JwtAuthenticator(request.AccessToken)
  733. };
  734. restClient.ConfigureWebRequest(webRequest =>
  735. {
  736. webRequest.ServicePoint.Expect100Continue = false;
  737. webRequest.KeepAlive = true;
  738. });
  739. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/equifax/{requestId}/batch", Method.POST);
  740. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  741. restRequest.AddUrlSegment("operationId", request.OperationId);
  742. restRequest.AddUrlSegment("requestId", request.RequestId);
  743. restRequest.AddHeader("FID", request.Fid.ToString());
  744. restRequest.AddJsonBody(request.Customers);
  745.  
  746. var response = await restClient.ExecuteTaskAsync(restRequest);
  747.  
  748. if (response.ErrorException != null)
  749. {
  750. throw new HostCommunicationException(
  751. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  752. response.ErrorException
  753. );
  754. }
  755.  
  756. if (response.StatusCode == HttpStatusCode.Unauthorized)
  757. {
  758. throw new Http401UnauthorizedException(
  759. response.StatusDescription,
  760. response.StatusDescription,
  761. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  762. );
  763. }
  764.  
  765. if (response.StatusCode == HttpStatusCode.Forbidden)
  766. {
  767. throw new Http403ForbiddenException(
  768. response.StatusDescription,
  769. response.StatusDescription,
  770. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  771. );
  772. }
  773.  
  774. return response.StatusCode == HttpStatusCode.NoContent;
  775. }
  776.  
  777. /// <inheritdoc />
  778. public bool BatchImportTransUnionCustomers(BatchImportTransUnionCustomersRequest request)
  779. {
  780. var restClient = new RestSharp.RestClient(Uri)
  781. {
  782. Authenticator = new JwtAuthenticator(request.AccessToken)
  783. };
  784. restClient.ConfigureWebRequest(webRequest =>
  785. {
  786. webRequest.ServicePoint.Expect100Continue = false;
  787. webRequest.KeepAlive = true;
  788. });
  789. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{requestId}/batch", Method.POST);
  790. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  791. restRequest.AddUrlSegment("operationId", request.OperationId);
  792. restRequest.AddUrlSegment("requestId", request.RequestId);
  793. restRequest.AddHeader("FID", request.Fid.ToString());
  794. restRequest.AddJsonBody(request.Customers);
  795.  
  796. var response = restClient.Execute(restRequest);
  797.  
  798. if (response.ErrorException != null)
  799. {
  800. throw new HostCommunicationException(
  801. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  802. response.ErrorException
  803. );
  804. }
  805.  
  806. if (response.StatusCode == HttpStatusCode.Unauthorized)
  807. {
  808. throw new Http401UnauthorizedException(
  809. response.StatusDescription,
  810. response.StatusDescription,
  811. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  812. );
  813. }
  814.  
  815. if (response.StatusCode == HttpStatusCode.Forbidden)
  816. {
  817. throw new Http403ForbiddenException(
  818. response.StatusDescription,
  819. response.StatusDescription,
  820. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  821. );
  822. }
  823.  
  824. return response.StatusCode == HttpStatusCode.NoContent;
  825. }
  826.  
  827. /// <inheritdoc />
  828. public async Task<bool> BatchImportTransUnionCustomersAsync(BatchImportTransUnionCustomersRequest request)
  829. {
  830. var restClient = new RestSharp.RestClient(Uri)
  831. {
  832. Authenticator = new JwtAuthenticator(request.AccessToken)
  833. };
  834. restClient.ConfigureWebRequest(webRequest =>
  835. {
  836. webRequest.ServicePoint.Expect100Continue = false;
  837. webRequest.KeepAlive = true;
  838. });
  839. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/transunion/{requestId}/batch", Method.POST);
  840. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  841. restRequest.AddUrlSegment("operationId", request.OperationId);
  842. restRequest.AddUrlSegment("requestId", request.RequestId);
  843. restRequest.AddHeader("FID", request.Fid.ToString());
  844. restRequest.AddJsonBody(request.Customers);
  845.  
  846. var response = await restClient.ExecuteTaskAsync(restRequest);
  847.  
  848. if (response.ErrorException != null)
  849. {
  850. throw new HostCommunicationException(
  851. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  852. response.ErrorException
  853. );
  854. }
  855.  
  856. if (response.StatusCode == HttpStatusCode.Unauthorized)
  857. {
  858. throw new Http401UnauthorizedException(
  859. response.StatusDescription,
  860. response.StatusDescription,
  861. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  862. );
  863. }
  864.  
  865. if (response.StatusCode == HttpStatusCode.Forbidden)
  866. {
  867. throw new Http403ForbiddenException(
  868. response.StatusDescription,
  869. response.StatusDescription,
  870. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  871. );
  872. }
  873.  
  874. return response.StatusCode == HttpStatusCode.NoContent;
  875. }
  876.  
  877. /// <inheritdoc />
  878. public bool BatchImportDatamyxCustomers(BatchImportDatamyxCustomersRequest request)
  879. {
  880. var restClient = new RestSharp.RestClient(Uri)
  881. {
  882. Authenticator = new JwtAuthenticator(request.AccessToken)
  883. };
  884. restClient.ConfigureWebRequest(webRequest =>
  885. {
  886. webRequest.ServicePoint.Expect100Continue = false;
  887. webRequest.KeepAlive = true;
  888. });
  889. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{requestId}/batch", Method.POST);
  890. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  891. restRequest.AddUrlSegment("operationId", request.OperationId);
  892. restRequest.AddUrlSegment("requestId", request.RequestId);
  893. restRequest.AddHeader("FID", request.Fid.ToString());
  894. restRequest.AddJsonBody(request.Customers);
  895.  
  896. var response = restClient.Execute(restRequest);
  897.  
  898. if (response.ErrorException != null)
  899. {
  900. throw new HostCommunicationException(
  901. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  902. response.ErrorException
  903. );
  904. }
  905.  
  906. if (response.StatusCode == HttpStatusCode.Unauthorized)
  907. {
  908. throw new Http401UnauthorizedException(
  909. response.StatusDescription,
  910. response.StatusDescription,
  911. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  912. );
  913. }
  914.  
  915. if (response.StatusCode == HttpStatusCode.Forbidden)
  916. {
  917. throw new Http403ForbiddenException(
  918. response.StatusDescription,
  919. response.StatusDescription,
  920. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  921. );
  922. }
  923.  
  924. return response.StatusCode == HttpStatusCode.NoContent;
  925. }
  926.  
  927. /// <inheritdoc />
  928. public async Task<bool> BatchImportDatamyxCustomersAsync(BatchImportDatamyxCustomersRequest request)
  929. {
  930. var restClient = new RestSharp.RestClient(Uri)
  931. {
  932. Authenticator = new JwtAuthenticator(request.AccessToken)
  933. };
  934. restClient.ConfigureWebRequest(webRequest =>
  935. {
  936. webRequest.ServicePoint.Expect100Continue = false;
  937. webRequest.KeepAlive = true;
  938. });
  939. var restRequest = new RestRequest("/campaign/{campaignId}/bureau-import/operation/{operationId}/data/datamyx/{requestId}/batch", Method.POST);
  940. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  941. restRequest.AddUrlSegment("operationId", request.OperationId);
  942. restRequest.AddUrlSegment("requestId", request.RequestId);
  943. restRequest.AddHeader("FID", request.Fid.ToString());
  944. restRequest.AddJsonBody(request.Customers);
  945.  
  946. var response = await restClient.ExecuteTaskAsync(restRequest);
  947.  
  948. if (response.ErrorException != null)
  949. {
  950. throw new HostCommunicationException(
  951. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  952. response.ErrorException
  953. );
  954. }
  955.  
  956. if (response.StatusCode == HttpStatusCode.Unauthorized)
  957. {
  958. throw new Http401UnauthorizedException(
  959. response.StatusDescription,
  960. response.StatusDescription,
  961. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  962. );
  963. }
  964.  
  965. if (response.StatusCode == HttpStatusCode.Forbidden)
  966. {
  967. throw new Http403ForbiddenException(
  968. response.StatusDescription,
  969. response.StatusDescription,
  970. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  971. );
  972. }
  973.  
  974. return response.StatusCode == HttpStatusCode.NoContent;
  975. }
  976.  
  977. /// <inheritdoc />
  978. public DataListResponse<Guid> ProcessingCreditBureauImports(
  979. ProcessingCreditBureauImportsRequest request
  980. )
  981. {
  982. var restClient = new RestSharp.RestClient(Uri)
  983. {
  984. Authenticator = new JwtAuthenticator(request.AccessToken)
  985. };
  986. var restRequest = new RestRequest("/scheduling/credit-bureau-import/processing", Method.GET);
  987.  
  988. var response = restClient.Execute<DataListResponse<Guid>>(restRequest);
  989.  
  990. if (response.ErrorException != null)
  991. {
  992. throw new HostCommunicationException(
  993. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  994. response.ErrorException
  995. );
  996. }
  997.  
  998. if (response.StatusCode == HttpStatusCode.Unauthorized)
  999. {
  1000. throw new Http401UnauthorizedException(
  1001. response.StatusDescription,
  1002. response.StatusDescription,
  1003. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1004. );
  1005. }
  1006.  
  1007. if (response.StatusCode == HttpStatusCode.Forbidden)
  1008. {
  1009. throw new Http403ForbiddenException(
  1010. response.StatusDescription,
  1011. response.StatusDescription,
  1012. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1013. );
  1014. }
  1015.  
  1016. return response.Data;
  1017. }
  1018.  
  1019. /// <inheritdoc />
  1020. public async Task<DataListResponse<Guid>> ProcessingCreditBureauImportsAsync(
  1021. ProcessingCreditBureauImportsRequest request
  1022. )
  1023. {
  1024. var restClient = new RestSharp.RestClient(Uri)
  1025. {
  1026. Authenticator = new JwtAuthenticator(request.AccessToken)
  1027. };
  1028. var restRequest = new RestRequest("/scheduling/credit-bureau-import/processing", Method.GET);
  1029.  
  1030. var response = await restClient.ExecuteTaskAsync<DataListResponse<Guid>>(restRequest);
  1031.  
  1032. if (response.ErrorException != null)
  1033. {
  1034. throw new HostCommunicationException(
  1035. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1036. response.ErrorException
  1037. );
  1038. }
  1039.  
  1040. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1041. {
  1042. throw new Http401UnauthorizedException(
  1043. response.StatusDescription,
  1044. response.StatusDescription,
  1045. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1046. );
  1047. }
  1048.  
  1049. if (response.StatusCode == HttpStatusCode.Forbidden)
  1050. {
  1051. throw new Http403ForbiddenException(
  1052. response.StatusDescription,
  1053. response.StatusDescription,
  1054. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1055. );
  1056. }
  1057.  
  1058. return response.Data;
  1059. }
  1060.  
  1061. /// <inheritdoc />
  1062. public bool RollupCreditBureauImportLogs(RollupCreditBureauImportLogsRequest request)
  1063. {
  1064. var restClient = new RestSharp.RestClient(Uri)
  1065. {
  1066. Authenticator = new JwtAuthenticator(request.AccessToken)
  1067. };
  1068. var restRequest = new RestRequest("/scheduling/credit-bureau-import/rollup-logs/{operationId}", Method.PUT);
  1069. restRequest.AddUrlSegment("operationId", request.OperationId);
  1070.  
  1071. var response = restClient.Execute(restRequest);
  1072.  
  1073. if (response.ErrorException != null)
  1074. {
  1075. throw new HostCommunicationException(
  1076. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1077. response.ErrorException
  1078. );
  1079. }
  1080.  
  1081. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1082. {
  1083. throw new Http401UnauthorizedException(
  1084. response.StatusDescription,
  1085. response.StatusDescription,
  1086. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1087. );
  1088. }
  1089.  
  1090. if (response.StatusCode == HttpStatusCode.Forbidden)
  1091. {
  1092. throw new Http403ForbiddenException(
  1093. response.StatusDescription,
  1094. response.StatusDescription,
  1095. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1096. );
  1097. }
  1098.  
  1099. return response.StatusCode == HttpStatusCode.NoContent;
  1100. }
  1101.  
  1102. /// <inheritdoc />
  1103. public async Task<bool> RollupCreditBureauImportLogsAsync(
  1104. RollupCreditBureauImportLogsRequest request
  1105. )
  1106. {
  1107. var restClient = new RestSharp.RestClient(Uri)
  1108. {
  1109. Authenticator = new JwtAuthenticator(request.AccessToken)
  1110. };
  1111. var restRequest = new RestRequest("/scheduling/credit-bureau-import/rollup-logs/{operationId}", Method.PUT);
  1112. restRequest.AddUrlSegment("operationId", request.OperationId);
  1113.  
  1114. var response = await restClient.ExecuteTaskAsync(restRequest);
  1115.  
  1116. if (response.ErrorException != null)
  1117. {
  1118. throw new HostCommunicationException(
  1119. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1120. response.ErrorException
  1121. );
  1122. }
  1123.  
  1124. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1125. {
  1126. throw new Http401UnauthorizedException(
  1127. response.StatusDescription,
  1128. response.StatusDescription,
  1129. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1130. );
  1131. }
  1132.  
  1133. if (response.StatusCode == HttpStatusCode.Forbidden)
  1134. {
  1135. throw new Http403ForbiddenException(
  1136. response.StatusDescription,
  1137. response.StatusDescription,
  1138. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1139. );
  1140. }
  1141.  
  1142. return response.StatusCode == HttpStatusCode.NoContent;
  1143. }
  1144.  
  1145. /// <inheritdoc />
  1146. public DataListResponse<Guid> ProcessingCustomerImports(ProcessingCustomerImportsRequest request)
  1147. {
  1148. var restClient = new RestSharp.RestClient(Uri)
  1149. {
  1150. Authenticator = new JwtAuthenticator(request.AccessToken)
  1151. };
  1152. var restRequest = new RestRequest("/scheduling/customer-import/processing", Method.GET);
  1153.  
  1154. var response = restClient.Execute<DataListResponse<Guid>>(restRequest);
  1155.  
  1156. if (response.ErrorException != null)
  1157. {
  1158. throw new HostCommunicationException(
  1159. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1160. response.ErrorException
  1161. );
  1162. }
  1163.  
  1164. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1165. {
  1166. throw new Http401UnauthorizedException(
  1167. response.StatusDescription,
  1168. response.StatusDescription,
  1169. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1170. );
  1171. }
  1172.  
  1173. if (response.StatusCode == HttpStatusCode.Forbidden)
  1174. {
  1175. throw new Http403ForbiddenException(
  1176. response.StatusDescription,
  1177. response.StatusDescription,
  1178. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1179. );
  1180. }
  1181.  
  1182. return response.Data;
  1183. }
  1184.  
  1185. /// <inheritdoc />
  1186. public async Task<DataListResponse<Guid>> ProcessingCustomerImportsAsync(
  1187. ProcessingCustomerImportsRequest request
  1188. )
  1189. {
  1190. var restClient = new RestSharp.RestClient(Uri)
  1191. {
  1192. Authenticator = new JwtAuthenticator(request.AccessToken)
  1193. };
  1194. var restRequest = new RestRequest("/scheduling/customer-import/processing", Method.GET);
  1195.  
  1196. var response = await restClient.ExecuteTaskAsync<DataListResponse<Guid>>(restRequest);
  1197.  
  1198. if (response.ErrorException != null)
  1199. {
  1200. throw new HostCommunicationException(
  1201. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1202. response.ErrorException
  1203. );
  1204. }
  1205.  
  1206. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1207. {
  1208. throw new Http401UnauthorizedException(
  1209. response.StatusDescription,
  1210. response.StatusDescription,
  1211. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1212. );
  1213. }
  1214.  
  1215. if (response.StatusCode == HttpStatusCode.Forbidden)
  1216. {
  1217. throw new Http403ForbiddenException(
  1218. response.StatusDescription,
  1219. response.StatusDescription,
  1220. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1221. );
  1222. }
  1223.  
  1224. return response.Data;
  1225. }
  1226.  
  1227. /// <inheritdoc />
  1228. public bool RollupCustomerImportLogs(RollupCustomerImportLogsRequest request)
  1229. {
  1230. var restClient = new RestSharp.RestClient(Uri)
  1231. {
  1232. Authenticator = new JwtAuthenticator(request.AccessToken)
  1233. };
  1234. var restRequest = new RestRequest("/scheduling/customer-import/rollup-logs/{operationId}", Method.PUT);
  1235. restRequest.AddUrlSegment("operationId", request.OperationId);
  1236.  
  1237. var response = restClient.Execute(restRequest);
  1238.  
  1239. if (response.ErrorException != null)
  1240. {
  1241. throw new HostCommunicationException(
  1242. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1243. response.ErrorException
  1244. );
  1245. }
  1246.  
  1247. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1248. {
  1249. throw new Http401UnauthorizedException(
  1250. response.StatusDescription,
  1251. response.StatusDescription,
  1252. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1253. );
  1254. }
  1255.  
  1256. if (response.StatusCode == HttpStatusCode.Forbidden)
  1257. {
  1258. throw new Http403ForbiddenException(
  1259. response.StatusDescription,
  1260. response.StatusDescription,
  1261. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1262. );
  1263. }
  1264.  
  1265. return response.StatusCode == HttpStatusCode.NoContent;
  1266. }
  1267.  
  1268. /// <inheritdoc />
  1269. public async Task<bool> RollupCustomerImportLogsAsync(RollupCustomerImportLogsRequest request)
  1270. {
  1271. var restClient = new RestSharp.RestClient(Uri)
  1272. {
  1273. Authenticator = new JwtAuthenticator(request.AccessToken)
  1274. };
  1275. var restRequest = new RestRequest("/scheduling/customer-import/rollup-logs/{operationId}", Method.PUT);
  1276. restRequest.AddUrlSegment("operationId", request.OperationId);
  1277.  
  1278. var response = await restClient.ExecuteTaskAsync(restRequest);
  1279.  
  1280. if (response.ErrorException != null)
  1281. {
  1282. throw new HostCommunicationException(
  1283. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1284. response.ErrorException
  1285. );
  1286. }
  1287.  
  1288. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1289. {
  1290. throw new Http401UnauthorizedException(
  1291. response.StatusDescription,
  1292. response.StatusDescription,
  1293. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1294. );
  1295. }
  1296.  
  1297. if (response.StatusCode == HttpStatusCode.Forbidden)
  1298. {
  1299. throw new Http403ForbiddenException(
  1300. response.StatusDescription,
  1301. response.StatusDescription,
  1302. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1303. );
  1304. }
  1305.  
  1306. return response.StatusCode == HttpStatusCode.NoContent;
  1307. }
  1308.  
  1309. /// <inheritdoc />
  1310. public DataObjectResponse<RandomCampaignCustomerDto> RandomCampaignCustomer(RandomCampaignCustomerRequest request)
  1311. {
  1312. var restClient = new RestSharp.RestClient(Uri)
  1313. {
  1314. Authenticator = new JwtAuthenticator(request.AccessToken)
  1315. };
  1316. var restRequest = new RestRequest("/campaign/{campaignId}/customers/random", Method.GET);
  1317. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  1318. restRequest.AddHeader("FID", request.Fid.ToString());
  1319.  
  1320. var response = restClient.Execute<DataObjectResponse<RandomCampaignCustomerDto>>(restRequest);
  1321.  
  1322. if (response.ErrorException != null)
  1323. {
  1324. throw new HostCommunicationException(
  1325. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1326. response.ErrorException
  1327. );
  1328. }
  1329.  
  1330. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1331. {
  1332. throw new Http401UnauthorizedException(
  1333. response.StatusDescription,
  1334. response.StatusDescription,
  1335. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1336. );
  1337. }
  1338.  
  1339. if (response.StatusCode == HttpStatusCode.Forbidden)
  1340. {
  1341. throw new Http403ForbiddenException(
  1342. response.StatusDescription,
  1343. response.StatusDescription,
  1344. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1345. );
  1346. }
  1347.  
  1348. if (response.StatusCode == HttpStatusCode.NotFound)
  1349. {
  1350. return null;
  1351. }
  1352.  
  1353. return response.Data;
  1354. }
  1355.  
  1356. /// <inheritdoc />
  1357. public DataObjectResponse<CampaignCustomerDto> GetCampaignCustomer(GetCampaignCustomerRequest request)
  1358. {
  1359. var restClient = new RestSharp.RestClient(Uri)
  1360. {
  1361. Authenticator = new JwtAuthenticator(request.AccessToken)
  1362. };
  1363. var restRequest = new RestRequest("/campaign/{campaignId}/customers/{customerId}", Method.GET);
  1364. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  1365. restRequest.AddUrlSegment("customerId", request.CustomerId);
  1366. restRequest.AddHeader("FID", request.Fid.ToString());
  1367.  
  1368. var response = restClient.Execute<DataObjectResponse<CampaignCustomerDto>>(restRequest);
  1369.  
  1370. if (response.ErrorException != null)
  1371. {
  1372. throw new HostCommunicationException(
  1373. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1374. response.ErrorException
  1375. );
  1376. }
  1377.  
  1378. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1379. {
  1380. throw new Http401UnauthorizedException(
  1381. response.StatusDescription,
  1382. response.StatusDescription,
  1383. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1384. );
  1385. }
  1386.  
  1387. if (response.StatusCode == HttpStatusCode.Forbidden)
  1388. {
  1389. throw new Http403ForbiddenException(
  1390. response.StatusDescription,
  1391. response.StatusDescription,
  1392. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1393. );
  1394. }
  1395.  
  1396. if (response.StatusCode == HttpStatusCode.OK)
  1397. {
  1398. return response.Data;
  1399. }
  1400.  
  1401. return null;
  1402. }
  1403.  
  1404. /// <inheritdoc />
  1405. public async Task<DataObjectResponse<CampaignCustomerDto>> GetCampaignCustomerAsync(GetCampaignCustomerRequest request)
  1406. {
  1407. var restClient = new RestSharp.RestClient(Uri)
  1408. {
  1409. Authenticator = new JwtAuthenticator(request.AccessToken)
  1410. };
  1411. var restRequest = new RestRequest("/campaign/{campaignId}/customers/{customerId}", Method.GET);
  1412. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  1413. restRequest.AddUrlSegment("customerId", request.CustomerId);
  1414. restRequest.AddHeader("FID", request.Fid.ToString());
  1415.  
  1416. var response = await restClient.ExecuteTaskAsync<DataObjectResponse<CampaignCustomerDto>>(restRequest).ConfigureAwait(false);
  1417.  
  1418. if (response.ErrorException != null)
  1419. {
  1420. throw new HostCommunicationException(
  1421. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1422. response.ErrorException
  1423. );
  1424. }
  1425.  
  1426. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1427. {
  1428. throw new Http401UnauthorizedException(
  1429. response.StatusDescription,
  1430. response.StatusDescription,
  1431. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1432. );
  1433. }
  1434.  
  1435. if (response.StatusCode == HttpStatusCode.Forbidden)
  1436. {
  1437. throw new Http403ForbiddenException(
  1438. response.StatusDescription,
  1439. response.StatusDescription,
  1440. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1441. );
  1442. }
  1443.  
  1444. return response.StatusCode == HttpStatusCode.OK ? response.Data : null;
  1445. }
  1446.  
  1447. /// <inheritdoc />
  1448. public bool BatchImportCustomers(BatchImportCustomersRequest request)
  1449. {
  1450. var restClient = new RestSharp.RestClient(Uri)
  1451. {
  1452. Authenticator = new JwtAuthenticator(request.AccessToken)
  1453. };
  1454. restClient.ConfigureWebRequest(webRequest =>
  1455. {
  1456. webRequest.ServicePoint.Expect100Continue = false;
  1457. webRequest.KeepAlive = true;
  1458. //webRequest.Timeout
  1459. });
  1460. var restRequest = new RestRequest("/campaign/{campaignId}/customer-import/operation/{operationId}/data/customer/{requestId}", Method.POST);
  1461. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  1462. restRequest.AddUrlSegment("operationId", request.OperationId);
  1463. restRequest.AddUrlSegment("requestId", request.RequestId);
  1464. restRequest.AddHeader("FID", request.Fid.ToString());
  1465. restRequest.AddJsonBody(request.Customers);
  1466.  
  1467. var response = restClient.Execute(restRequest);
  1468.  
  1469. if (response.ErrorException != null)
  1470. {
  1471. throw new HostCommunicationException(
  1472. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1473. response.ErrorException
  1474. );
  1475. }
  1476.  
  1477. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1478. {
  1479. throw new Http401UnauthorizedException(
  1480. response.StatusDescription,
  1481. response.StatusDescription,
  1482. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1483. );
  1484. }
  1485.  
  1486. if (response.StatusCode == HttpStatusCode.Forbidden)
  1487. {
  1488. throw new Http403ForbiddenException(
  1489. response.StatusDescription,
  1490. response.StatusDescription,
  1491. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1492. );
  1493. }
  1494.  
  1495. return response.StatusCode == HttpStatusCode.NoContent;
  1496. }
  1497.  
  1498. /// <inheritdoc />
  1499. public async Task<bool> BatchImportCustomersAsync(BatchImportCustomersRequest request)
  1500. {
  1501. var restClient = new RestSharp.RestClient(Uri)
  1502. {
  1503. Authenticator = new JwtAuthenticator(request.AccessToken)
  1504. };
  1505. restClient.ConfigureWebRequest(webRequest =>
  1506. {
  1507. webRequest.ServicePoint.Expect100Continue = false;
  1508. webRequest.KeepAlive = true;
  1509. //webRequest.Timeout
  1510. });
  1511. var restRequest = new RestRequest("/campaign/{campaignId}/customer-import/operation/{operationId}/data/customer/{requestId}", Method.POST);
  1512. restRequest.AddUrlSegment("campaignId", request.CampaignId);
  1513. restRequest.AddUrlSegment("operationId", request.OperationId);
  1514. restRequest.AddUrlSegment("requestId", request.RequestId);
  1515. restRequest.AddHeader("FID", request.Fid.ToString());
  1516. restRequest.AddJsonBody(request.Customers);
  1517.  
  1518. var response = await restClient.ExecuteTaskAsync(restRequest).ConfigureAwait(false);
  1519.  
  1520. if (response.ErrorException != null)
  1521. {
  1522. throw new HostCommunicationException(
  1523. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1524. response.ErrorException
  1525. );
  1526. }
  1527.  
  1528. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1529. {
  1530. throw new Http401UnauthorizedException(
  1531. response.StatusDescription,
  1532. response.StatusDescription,
  1533. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1534. );
  1535. }
  1536.  
  1537. if (response.StatusCode == HttpStatusCode.Forbidden)
  1538. {
  1539. throw new Http403ForbiddenException(
  1540. response.StatusDescription,
  1541. response.StatusDescription,
  1542. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1543. );
  1544. }
  1545.  
  1546. return response.StatusCode == HttpStatusCode.NoContent;
  1547. }
  1548.  
  1549. /// <inheritdoc />
  1550. public Task<DataObjectResponse<CustomerDOBDto>> GetCustomerDOBAsync(GetCustomerDOBRequest request)
  1551. {
  1552. var restClient = new RestSharp.RestClient(Uri)
  1553. {
  1554. Authenticator = new JwtAuthenticator(request.AccessToken)
  1555. };
  1556. var restRequest = new RestRequest("/campaign/{campaignid}/customers/{customerId}/dob", Method.GET);
  1557. restRequest.AddParameter("campaignid", request.CampaignId, ParameterType.UrlSegment);
  1558. restRequest.AddParameter("customerId", request.CustomerId, ParameterType.UrlSegment);
  1559.  
  1560. var t = new Task<DataObjectResponse<CustomerDOBDto>>(() =>
  1561. {
  1562.  
  1563. var response = restClient.Execute<DataObjectResponse<CustomerDOBDto>>(restRequest);
  1564.  
  1565. if (response.ErrorException != null)
  1566. {
  1567. throw new HostCommunicationException(
  1568. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1569. response.ErrorException
  1570. );
  1571. }
  1572.  
  1573. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1574. {
  1575. throw new Http401UnauthorizedException<DataObjectResponse<CustomerDOBDto>>(
  1576. response.StatusDescription,
  1577. response.StatusDescription,
  1578. Mapper
  1579. .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
  1580. DataObjectResponse<CustomerDOBDto>>>(response)
  1581. );
  1582. }
  1583.  
  1584. if (response.StatusCode == HttpStatusCode.Forbidden)
  1585. {
  1586. throw new Http403ForbiddenException<DataObjectResponse<CustomerDOBDto>>(
  1587. response.StatusDescription,
  1588. response.StatusDescription,
  1589. Mapper
  1590. .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
  1591. DataObjectResponse<CustomerDOBDto>>>(response)
  1592. );
  1593. }
  1594.  
  1595. if (response.StatusCode != HttpStatusCode.OK)
  1596. {
  1597. throw new HttpResponseCodeException<DataObjectResponse<CustomerDOBDto>>(
  1598. response.StatusDescription,
  1599. response.StatusCode,
  1600. response.StatusDescription,
  1601. Mapper
  1602. .Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse<
  1603. DataObjectResponse<CustomerDOBDto>>>(response)
  1604. );
  1605. }
  1606.  
  1607. return response.Data;
  1608. });
  1609.  
  1610. t.Start();
  1611.  
  1612. return t;
  1613. }
  1614.  
  1615. /// <inheritdoc />
  1616. public async Task<DataListResponse<CampaignCustomerDto>> GetCampaignCustomersAsync(GetCustomersRequest request)
  1617. {
  1618. var restClient = new RestSharp.RestClient(Uri)
  1619. {
  1620. Authenticator = new JwtAuthenticator(request.AccessToken)
  1621. };
  1622. var restRequest = new RestRequest("/campaign/{campaignid}/customers/within", Method.POST);
  1623. restRequest.AddParameter("campaignid", request.CampaignId, ParameterType.UrlSegment);
  1624. restRequest.AddJsonBody(request.CustomerIds);
  1625.  
  1626. var response = await restClient.ExecuteTaskAsync<DataListResponse<CampaignCustomerDto>>(restRequest);
  1627.  
  1628. if (response.ErrorException != null)
  1629. {
  1630. throw new HostCommunicationException(
  1631. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestRequest>(restRequest),
  1632. response.ErrorException
  1633. );
  1634. }
  1635.  
  1636. if (response.StatusCode == HttpStatusCode.Unauthorized)
  1637. {
  1638. throw new Http401UnauthorizedException(
  1639. response.StatusDescription,
  1640. response.StatusDescription,
  1641. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1642. );
  1643. }
  1644.  
  1645. if (response.StatusCode == HttpStatusCode.Forbidden)
  1646. {
  1647. throw new Http403ForbiddenException(
  1648. response.StatusDescription,
  1649. response.StatusDescription,
  1650. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1651. );
  1652. }
  1653.  
  1654. if (response.StatusCode != HttpStatusCode.OK)
  1655. {
  1656. throw new HttpResponseCodeException(
  1657. response.StatusDescription,
  1658. response.StatusCode,
  1659. response.StatusDescription,
  1660. Mapper.Map<Pliny.SharedKernel.Domain.RestClient.IRestResponse>(response)
  1661. );
  1662. }
  1663.  
  1664. return response.Data;
  1665. }
  1666. }
  1667. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement