@@ -13,34 +13,18 @@ namespace MessagingService.Client
1313 using Newtonsoft . Json ;
1414 using SimpleResults ;
1515
16- /// <summary>
17- ///
18- /// </summary>
19- /// <seealso cref="ClientProxyBase" />
20- /// <seealso cref="MessagingService.Client.IMessagingServiceClient" />
2116 public class MessagingServiceClient : ClientProxyBase , IMessagingServiceClient
2217 {
2318 #region Fields
2419
25- /// <summary>
26- /// The base address
27- /// </summary>
2820 private readonly String BaseAddress ;
2921
30- /// <summary>
31- /// The base address resolver
32- /// </summary>
3322 private readonly Func < String , String > BaseAddressResolver ;
3423
3524 #endregion
3625
3726 #region Constructors
3827
39- /// <summary>
40- /// Initializes a new instance of the <see cref="MessagingServiceClient"/> class.
41- /// </summary>
42- /// <param name="baseAddressResolver">The base address resolver.</param>
43- /// <param name="httpClient">The HTTP client.</param>
4428 public MessagingServiceClient ( Func < String , String > baseAddressResolver ,
4529 HttpClient httpClient ) : base ( httpClient )
4630 {
@@ -51,13 +35,6 @@ public MessagingServiceClient(Func<String, String> baseAddressResolver,
5135
5236 #region Methods
5337
54- /// <summary>
55- /// Sends the email.
56- /// </summary>
57- /// <param name="accessToken">The access token.</param>
58- /// <param name="sendEmailRequest">The send email request.</param>
59- /// <param name="cancellationToken">The cancellation token.</param>
60- /// <returns></returns>
6138 public async Task < Result > SendEmail ( String accessToken ,
6239 SendEmailRequest sendEmailRequest ,
6340 CancellationToken cancellationToken )
@@ -66,19 +43,8 @@ public async Task<Result> SendEmail(String accessToken,
6643
6744 try
6845 {
69- String requestSerialised = JsonConvert . SerializeObject ( sendEmailRequest ) ;
70-
71- StringContent httpContent = new ( requestSerialised , Encoding . UTF8 , "application/json" ) ;
72-
73- // Add the access token to the client headers
74- this . HttpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
75-
76- // Make the Http Call here
77- HttpResponseMessage httpResponse = await this . HttpClient . PostAsync ( requestUri , httpContent , cancellationToken ) ;
78-
79- // Process the response
80- Result < String > result = await this . HandleResponseX ( httpResponse , cancellationToken ) ;
81-
46+ Result < ResponseData < String > > result = await this . SendPostRequest < SendEmailRequest , ResponseData < String > > ( requestUri , accessToken , sendEmailRequest , cancellationToken ) ;
47+
8248 if ( result . IsFailed )
8349 return ResultHelpers . CreateFailure ( result ) ;
8450
@@ -99,18 +65,7 @@ public async Task<Result> ResendEmail(String accessToken,
9965 String requestUri = this . BuildRequestUrl ( "/api/email/resend" ) ;
10066
10167 try {
102- String requestSerialised = JsonConvert . SerializeObject ( resendEmailRequest ) ;
103-
104- StringContent httpContent = new ( requestSerialised , Encoding . UTF8 , "application/json" ) ;
105-
106- // Add the access token to the client headers
107- this . HttpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
108-
109- // Make the Http Call here
110- HttpResponseMessage httpResponse = await this . HttpClient . PostAsync ( requestUri , httpContent , cancellationToken ) ;
111-
112- // Process the response
113- Result < String > result = await this . HandleResponseX ( httpResponse , cancellationToken ) ;
68+ Result < ResponseData < String > > result = await this . SendPostRequest < ResendEmailRequest , ResponseData < String > > ( requestUri , accessToken , resendEmailRequest , cancellationToken ) ;
11469
11570 if ( result . IsFailed )
11671 return ResultHelpers . CreateFailure ( result ) ;
@@ -125,13 +80,6 @@ public async Task<Result> ResendEmail(String accessToken,
12580 }
12681 }
12782
128- /// <summary>
129- /// Sends the SMS.
130- /// </summary>
131- /// <param name="accessToken">The access token.</param>
132- /// <param name="sendSMSRequest">The send SMS request.</param>
133- /// <param name="cancellationToken">The cancellation token.</param>
134- /// <returns></returns>
13583 public async Task < Result > SendSMS ( String accessToken ,
13684 SendSMSRequest sendSMSRequest ,
13785 CancellationToken cancellationToken )
@@ -140,18 +88,7 @@ public async Task<Result> SendSMS(String accessToken,
14088
14189 try
14290 {
143- String requestSerialised = JsonConvert . SerializeObject ( sendSMSRequest ) ;
144-
145- StringContent httpContent = new ( requestSerialised , Encoding . UTF8 , "application/json" ) ;
146-
147- // Add the access token to the client headers
148- this . HttpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
149-
150- // Make the Http Call here
151- HttpResponseMessage httpResponse = await this . HttpClient . PostAsync ( requestUri , httpContent , cancellationToken ) ;
152-
153- // Process the response
154- Result < String > result = await this . HandleResponseX ( httpResponse , cancellationToken ) ;
91+ Result < ResponseData < String > > result = await this . SendPostRequest < SendSMSRequest , ResponseData < String > > ( requestUri , accessToken , sendSMSRequest , cancellationToken ) ;
15592
15693 if ( result . IsFailed )
15794 return ResultHelpers . CreateFailure ( result ) ;
@@ -166,12 +103,6 @@ public async Task<Result> SendSMS(String accessToken,
166103 throw exception ;
167104 }
168105 }
169-
170- /// <summary>
171- /// Builds the request URL.
172- /// </summary>
173- /// <param name="route">The route.</param>
174- /// <returns></returns>
175106 private String BuildRequestUrl ( String route )
176107 {
177108 String baseAddress = this . BaseAddressResolver ( "MessagingServiceApi" ) ;
0 commit comments