Skip to content

Commit 7bd9a0e

Browse files
authored
Merge pull request #13 from sherweb/spons/AddFactoryToDistributorService
Add Factory and use internal constructors to force OnProblemDetailsHandler
2 parents dda6fb8 + f67192c commit 7bd9a0e

File tree

13 files changed

+14
-347
lines changed

13 files changed

+14
-347
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.cs diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

NugetPackagesSourceCode/Sherweb.Apis.Distributor/HttpClient/DistributorService.cs

Lines changed: 8 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected DistributorService(System.Uri baseUri, HttpClientHandler rootHandler,
134134
/// <exception cref="System.ArgumentNullException">
135135
/// Thrown when a required parameter is null
136136
/// </exception>
137-
public DistributorService(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
137+
internal DistributorService(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
138138
{
139139
if (credentials == null)
140140
{
@@ -161,7 +161,7 @@ public DistributorService(ServiceClientCredentials credentials, params Delegatin
161161
/// <exception cref="System.ArgumentNullException">
162162
/// Thrown when a required parameter is null
163163
/// </exception>
164-
public DistributorService(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient)
164+
internal DistributorService(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient)
165165
{
166166
if (credentials == null)
167167
{
@@ -189,7 +189,7 @@ public DistributorService(ServiceClientCredentials credentials, HttpClient httpC
189189
/// <exception cref="System.ArgumentNullException">
190190
/// Thrown when a required parameter is null
191191
/// </exception>
192-
public DistributorService(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers)
192+
internal DistributorService(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers)
193193
{
194194
if (credentials == null)
195195
{
@@ -217,7 +217,7 @@ public DistributorService(ServiceClientCredentials credentials, HttpClientHandle
217217
/// <exception cref="System.ArgumentNullException">
218218
/// Thrown when a required parameter is null
219219
/// </exception>
220-
public DistributorService(System.Uri baseUri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
220+
internal DistributorService(System.Uri baseUri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
221221
{
222222
if (baseUri == null)
223223
{
@@ -253,7 +253,7 @@ public DistributorService(System.Uri baseUri, ServiceClientCredentials credentia
253253
/// <exception cref="System.ArgumentNullException">
254254
/// Thrown when a required parameter is null
255255
/// </exception>
256-
public DistributorService(System.Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers)
256+
internal DistributorService(System.Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers)
257257
{
258258
if (baseUri == null)
259259
{
@@ -339,7 +339,7 @@ private void Initialize()
339339
/// <return>
340340
/// A response object containing the response body and response headers.
341341
/// </return>
342-
public async Task<HttpOperationResponse<object>> GetPayableChargesWithHttpMessagesAsync(System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
342+
public async Task<HttpOperationResponse<PayableCharges>> GetPayableChargesWithHttpMessagesAsync(System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
343343
{
344344
// Tracing
345345
bool _shouldTrace = ServiceClientTracing.IsEnabled;
@@ -415,7 +415,7 @@ private void Initialize()
415415
HttpStatusCode _statusCode = _httpResponse.StatusCode;
416416
cancellationToken.ThrowIfCancellationRequested();
417417
string _responseContent = null;
418-
if ((int)_statusCode != 200 && (int)_statusCode != 400 && (int)_statusCode != 401 && (int)_statusCode != 403 && (int)_statusCode != 404 && (int)_statusCode != 429 && (int)_statusCode != 500)
418+
if ((int)_statusCode != 200)
419419
{
420420
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
421421
if (_httpResponse.Content != null) {
@@ -438,7 +438,7 @@ private void Initialize()
438438
throw ex;
439439
}
440440
// Create Result
441-
var _result = new HttpOperationResponse<object>();
441+
var _result = new HttpOperationResponse<PayableCharges>();
442442
_result.Request = _httpRequest;
443443
_result.Response = _httpResponse;
444444
// Deserialize Response
@@ -459,114 +459,6 @@ private void Initialize()
459459
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
460460
}
461461
}
462-
// Deserialize Response
463-
if ((int)_statusCode == 400)
464-
{
465-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
466-
try
467-
{
468-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
469-
}
470-
catch (JsonException ex)
471-
{
472-
_httpRequest.Dispose();
473-
if (_httpResponse != null)
474-
{
475-
_httpResponse.Dispose();
476-
}
477-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
478-
}
479-
}
480-
// Deserialize Response
481-
if ((int)_statusCode == 401)
482-
{
483-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
484-
try
485-
{
486-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
487-
}
488-
catch (JsonException ex)
489-
{
490-
_httpRequest.Dispose();
491-
if (_httpResponse != null)
492-
{
493-
_httpResponse.Dispose();
494-
}
495-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
496-
}
497-
}
498-
// Deserialize Response
499-
if ((int)_statusCode == 403)
500-
{
501-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
502-
try
503-
{
504-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
505-
}
506-
catch (JsonException ex)
507-
{
508-
_httpRequest.Dispose();
509-
if (_httpResponse != null)
510-
{
511-
_httpResponse.Dispose();
512-
}
513-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
514-
}
515-
}
516-
// Deserialize Response
517-
if ((int)_statusCode == 404)
518-
{
519-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
520-
try
521-
{
522-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
523-
}
524-
catch (JsonException ex)
525-
{
526-
_httpRequest.Dispose();
527-
if (_httpResponse != null)
528-
{
529-
_httpResponse.Dispose();
530-
}
531-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
532-
}
533-
}
534-
// Deserialize Response
535-
if ((int)_statusCode == 429)
536-
{
537-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
538-
try
539-
{
540-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
541-
}
542-
catch (JsonException ex)
543-
{
544-
_httpRequest.Dispose();
545-
if (_httpResponse != null)
546-
{
547-
_httpResponse.Dispose();
548-
}
549-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
550-
}
551-
}
552-
// Deserialize Response
553-
if ((int)_statusCode == 500)
554-
{
555-
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
556-
try
557-
{
558-
_result.Body = SafeJsonConvert.DeserializeObject<ProblemDetails>(_responseContent, DeserializationSettings);
559-
}
560-
catch (JsonException ex)
561-
{
562-
_httpRequest.Dispose();
563-
if (_httpResponse != null)
564-
{
565-
_httpResponse.Dispose();
566-
}
567-
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
568-
}
569-
}
570462
if (_shouldTrace)
571463
{
572464
ServiceClientTracing.Exit(_invocationId, _result);

NugetPackagesSourceCode/Sherweb.Apis.Distributor/HttpClient/DistributorServiceExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static partial class DistributorServiceExtensions
3434
/// Specify language (and culture) following [RFC 7231, section 5.3.5:
3535
/// Accept-Language].
3636
/// </param>
37-
public static object GetPayableCharges(this IDistributorService operations, System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string))
37+
public static PayableCharges GetPayableCharges(this IDistributorService operations, System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string))
3838
{
3939
return operations.GetPayableChargesAsync(date, acceptLanguage).GetAwaiter().GetResult();
4040
}
@@ -61,7 +61,7 @@ public static partial class DistributorServiceExtensions
6161
/// <param name='cancellationToken'>
6262
/// The cancellation token.
6363
/// </param>
64-
public static async Task<object> GetPayableChargesAsync(this IDistributorService operations, System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), CancellationToken cancellationToken = default(CancellationToken))
64+
public static async Task<PayableCharges> GetPayableChargesAsync(this IDistributorService operations, System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), CancellationToken cancellationToken = default(CancellationToken))
6565
{
6666
using (var _result = await operations.GetPayableChargesWithHttpMessagesAsync(date, acceptLanguage, null, cancellationToken).ConfigureAwait(false))
6767
{

NugetPackagesSourceCode/Sherweb.Apis.Distributor/HttpClient/IDistributorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public partial interface IDistributorService : System.IDisposable
6262
/// <param name='cancellationToken'>
6363
/// The cancellation token.
6464
/// </param>
65-
Task<HttpOperationResponse<object>> GetPayableChargesWithHttpMessagesAsync(System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
65+
Task<HttpOperationResponse<PayableCharges>> GetPayableChargesWithHttpMessagesAsync(System.DateTime? date = default(System.DateTime?), string acceptLanguage = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
6666

6767
}
6868
}

NugetPackagesSourceCode/Sherweb.Apis.Distributor/HttpClient/Models/AccountsPayable.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)