8000 Merge pull request #101 from Giorgi/releases/v7 · twilio-labs/twilio-aspnet@1693469 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1693469

Browse files
authored
Merge pull request #101 from Giorgi/releases/v7
Merge TwiMLResult classes, add extension methods.
2 parents adbc3a8 + e7f5f74 commit 1693469

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System.Text;
21
using System.Threading.Tasks;
32
using Microsoft.AspNetCore.Http;
43

5-
// ReSharper disable once CheckNamespace
6-
namespace Twilio.AspNet.Core.MinimalApi;
4+
5+
namespace Twilio.AspNet.Core;
76

87
/// <summary>
98
/// Adds extension methods to Results.Extensions to write TwiML objects to the HTTP response body
@@ -26,31 +25,14 @@ public static TwiMLResult TwiML(this IResultExtensions results, TwiML.TwiML twim
2625
/// Writes TwiML object to the HTTP response body
2726
/// </summary>
2827
// ReSharper disable once InconsistentNaming
29-
public class TwiMLResult : IResult
28+
public partial class TwiMLResult : IResult
3029
{
31-
// ReSharper disable once InconsistentNaming
32-
private string twiML;
33-
34-
/// <summary>
35-
/// Creates a TwiMLResult object
36-
/// </summary>
37-
/// <param name="twimlResponse">The TwiML to write to the HTTP response body</param>
38-
// ReSharper disable once InconsistentNaming
39-
public TwiMLResult(TwiML.TwiML twimlResponse)
40-
{
41-
twiML = twimlResponse?.ToString();
42-
}
43-
4430
/// <summary>
4531
/// Writes the TwiML to the HTTP response body
4632
/// </summary>
4733
/// <param name="httpContext">The HttpContext containing the Response to write the TwiML to</param>
4834
public Task ExecuteAsync(HttpContext httpContext)
4935
{
50-
twiML ??= "<Response></Response>";
51-
52-
httpContext.Response.ContentType = "application/xml";
53-
httpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(twiML);
54-
return httpContext.Response.WriteAsync(twiML);
36+
return WriteTwiMLToResponse(httpContext.Response);
5537
}
5638
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Twilio.TwiML;
5+
6+
namespace Twilio.AspNet.Core
7+
{
8+
// ReSharper disable once InconsistentNaming
9+
public static class TwiMLExtensions
10+
{
11+
// ReSharper disable once InconsistentNaming
12+
public static TwiMLResult ToTwiMLResult(this VoiceResponse voiceResponse)
13+
{
14+
return new TwiMLResult(voiceResponse);
15+
}
16+
17+
// ReSharper disable once InconsistentNaming
18+
public static TwiMLResult ToTwiMLResult(this MessagingResponse messagingResponse)
19+
{
20+
return new TwiMLResult(messagingResponse);
21+
}
22+
}
23+
}

src/Twilio.AspNet.Core/TwiMLResult C557 .cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Twilio.AspNet.Core
66
{
77
// ReSharper disable once InconsistentNaming
8-
public class TwiMLResult : IActionResult
8+
public partial class TwiMLResult : IActionResult
99
{
1010
public string Data { get; protected set; }
1111

@@ -27,6 +27,12 @@ public TwiMLResult(TwiML.TwiML response)
2727
public async Task ExecuteResultAsync(ActionContext actionContext)
2828
{
2929
var response = actionContext.HttpContext.Response;
30+
await WriteTwiMLToResponse(response);
31+
}
32+
33+
// ReSharper disable once InconsistentNaming
34+
private async Task WriteTwiMLToResponse(HttpResponse response)
35+
{
3036
response.ContentType = "application/xml";
3137

3238
if (Data == null)

0 commit comments

Comments
 (0)
0