Skip to content

Commit 35f4c3b

Browse files
authored
Modified set method response to no longer contain the raw content of the Http response. (Azure#33850)
1 parent 13a1c54 commit 35f4c3b

File tree

9 files changed

+92
-107
lines changed

9 files changed

+92
-107
lines changed

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/Models/CommunicationError.cs

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/Models/CommunicationErrorResponse.cs

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/Models/SipConfiguration.cs

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/Models/SipTrunkRoute.cs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingModelFactory.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingRestClient.cs

Lines changed: 15 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingClient.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ public virtual Response SetTrunk(
172172
scope.Start();
173173
try
174174
{
175-
var response = _restClient.PatchSipConfiguration(config, cancellationToken);
176-
return response.GetRawResponse();
175+
return _restClient.PatchSipConfiguration(config, cancellationToken);
177176
}
178177
catch (Exception ex)
179178
{
@@ -197,8 +196,7 @@ public virtual async Task<Response> SetTrunkAsync(
197196
scope.Start();
198197
try
199198
{
200-
var response = await _restClient.PatchSipConfigurationAsync(config, cancellationToken).ConfigureAwait(false);
201-
return response.GetRawResponse();
199+
return await _restClient.PatchSipConfigurationAsync(config, cancellationToken).ConfigureAwait(false);
202200
}
203201
catch (Exception ex)
204202
{
@@ -222,8 +220,7 @@ public virtual Response DeleteTrunk(
222220
scope.Start();
223221
try
224222
{
225-
var response = _restClient.PatchSipConfiguration(removeConfig, cancellationToken);
226-
return response.GetRawResponse();
223+
return _restClient.PatchSipConfiguration(removeConfig, cancellationToken);
227224
}
228225
catch (Exception ex)
229226
{
@@ -247,8 +244,7 @@ public virtual async Task<Response> DeleteTrunkAsync(
247244
scope.Start();
248245
try
249246
{
250-
var response = await _restClient.PatchSipConfigurationAsync(removeConfig, cancellationToken).ConfigureAwait(false);
251-
return response.GetRawResponse();
247+
return await _restClient.PatchSipConfigurationAsync(removeConfig, cancellationToken).ConfigureAwait(false);
252248
}
253249
catch (Exception ex)
254250
{
@@ -376,8 +372,7 @@ public virtual Response SetTrunks(
376372
return currentConfig.GetRawResponse();
377373
}
378374

379-
var response = _restClient.PatchSipConfiguration(new SipConfiguration(newTrunks), cancellationToken);
380-
return response.GetRawResponse();
375+
return _restClient.PatchSipConfiguration(new SipConfiguration(newTrunks), cancellationToken);
381376
}
382377
catch (Exception ex)
383378
{
@@ -417,8 +412,7 @@ public virtual async Task<Response> SetTrunksAsync(
417412
return currentConfig.GetRawResponse();
418413
}
419414

420-
var response = await _restClient.PatchSipConfigurationAsync(new SipConfiguration(newTrunks), cancellationToken).ConfigureAwait(false);
421-
return response.GetRawResponse();
415+
return await _restClient.PatchSipConfigurationAsync(new SipConfiguration(newTrunks), cancellationToken).ConfigureAwait(false);
422416
}
423417
catch (Exception ex) {
424418
scope.Failed(ex);
@@ -441,7 +435,8 @@ public virtual Response SetRoutes(
441435
{
442436
var config = new SipConfiguration(routes);
443437
var response = _restClient.PatchSipConfiguration(config, cancellationToken);
444-
return response.GetRawResponse();
438+
439+
return response;
445440
}
446441
catch (Exception ex)
447442
{
@@ -464,8 +459,7 @@ public virtual async Task<Response> SetRoutesAsync(
464459
try
465460
{
466461
var config = new SipConfiguration(routes);
467-
var response = await _restClient.PatchSipConfigurationAsync(config, cancellationToken).ConfigureAwait(false);
468-
return response.GetRawResponse();
462+
return await _restClient.PatchSipConfigurationAsync(config, cancellationToken).ConfigureAwait(false);
469463
}
470464
catch (Exception ex)
471465
{

sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingRestClient.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Licensed under the MIT License.
33

44
using System.IO;
5+
using System.Text.Json;
6+
using System.Threading.Tasks;
7+
using System.Threading;
58
using Azure.Core;
69

710
namespace Azure.Communication.PhoneNumbers.SipRouting
@@ -15,9 +18,9 @@ internal HttpMessage CreatePatchSipConfigurationRequest(SipConfiguration body)
1518
var request = message.Request;
1619
request.Method = RequestMethod.Patch;
1720
var uri = new RawRequestUriBuilder();
18-
uri.AppendRaw(endpoint, false);
21+
uri.AppendRaw(_endpoint, false);
1922
uri.AppendPath("/sip", false);
20-
uri.AppendQuery("api-version", apiVersion, true);
23+
uri.AppendQuery("api-version", _apiVersion, true);
2124
request.Uri = uri;
2225
request.Headers.Add("Accept", "application/json");
2326
if (body != null)
@@ -29,5 +32,55 @@ internal HttpMessage CreatePatchSipConfigurationRequest(SipConfiguration body)
2932
}
3033
return message;
3134
}
35+
36+
/// <summary> Patches SIP configuration for resource. </summary>
37+
/// <param name="body"> Configuration patch. </param>
38+
/// <param name="cancellationToken"> The cancellation token to use. </param>
39+
public async Task<Response> PatchSipConfigurationAsync(SipConfiguration body = null, CancellationToken cancellationToken = default)
40+
{
41+
using var message = CreatePatchSipConfigurationRequest(body);
42+
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
43+
switch (message.Response.Status)
44+
{
45+
case 200:
46+
{
47+
SipConfiguration value = default;
48+
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
49+
value = SipConfiguration.DeserializeSipConfiguration(document.RootElement);
50+
var response = Response.FromValue(value, message.Response);
51+
Response mappedResponse = response.GetRawResponse();
52+
mappedResponse.ContentStream = null;
53+
54+
return mappedResponse;
55+
}
56+
default:
57+
throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
58+
}
59+
}
60+
61+
/// <summary> Patches SIP configuration for resource. </summary>
62+
/// <param name="body"> Configuration patch. </param>
63+
/// <param name="cancellationToken"> The cancellation token to use. </param>
64+
public Response PatchSipConfiguration(SipConfiguration body = null, CancellationToken cancellationToken = default)
65+
{
66+
using var message = CreatePatchSipConfigurationRequest(body);
67+
_pipeline.Send(message, cancellationToken);
68+
switch (message.Response.Status)
69+
{
70+
case 200:
71+
{
72+
SipConfiguration value = default;
73+
using var document = JsonDocument.Parse(message.Response.ContentStream);
74+
value = SipConfiguration.DeserializeSipConfiguration(document.RootElement);
75+
var response = Response.FromValue(value, message.Response);
76+
Response mappedResponse = response.GetRawResponse();
77+
mappedResponse.ContentStream = null;
78+
79+
return mappedResponse;
80+
}
81+
default:
82+
throw ClientDiagnostics.CreateRequestFailedException(message.Response);
83+
}
84+
}
3285
}
3386
}

0 commit comments

Comments
 (0)