forked from Vonage/vonage-dotnet-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Vonage#167 from Nexmo/refactor
Adding type-safe webhooks and NCCOs. Adding application_id and has_application to Numbers API
- Loading branch information
Showing
41 changed files
with
913 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Nexmo.Api.Voice.AnswerWebhooks | ||
{ | ||
public class Answer | ||
{ | ||
[JsonProperty("to")] | ||
public string To { get; set; } | ||
|
||
[JsonProperty("from")] | ||
public string From { get; set; } | ||
|
||
[JsonProperty("uuid")] | ||
public string Uuid { get; set; } | ||
|
||
[JsonProperty("conversation_uuid")] | ||
public string ConversationUuid { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Nexmo.Api.Voice | ||
{ | ||
public class CallCommandConverter : JsonConverter | ||
{ | ||
public override bool CanWrite => true; | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(Call.CallCommand); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
const string NCCO = "ncco"; | ||
const string NCCO_OBJ = "NccoObj"; | ||
writer.WriteStartObject(); | ||
var nccoUsed = false; | ||
foreach(var property in value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) | ||
{ | ||
if(property.GetValue(value) == null || property.GetValue(value) is decimal && (decimal)property.GetValue(value) == (decimal)0.0) | ||
{ | ||
continue; | ||
} | ||
var propertyName = property.Name; | ||
foreach(CustomAttributeData att in property.CustomAttributes) | ||
{ | ||
if(att.AttributeType.Name == "JsonPropertyAttribute") | ||
{ | ||
propertyName = att.ConstructorArguments[0].Value.ToString(); | ||
break; | ||
} | ||
} | ||
if ((propertyName == NCCO || propertyName == NCCO_OBJ) && nccoUsed) | ||
{ | ||
continue; | ||
} | ||
else if(propertyName == NCCO || propertyName == NCCO_OBJ) | ||
{ | ||
nccoUsed = true; | ||
propertyName = "ncco"; | ||
} | ||
writer.WritePropertyName(propertyName); | ||
serializer.Serialize(writer, property.GetValue(value)); | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public class Answered : CallStatusEvent | ||
{ | ||
[JsonProperty("start_time")] | ||
public DateTime StartTime { get; set; } | ||
|
||
[JsonProperty("rate")] | ||
public string Rate { get; set; } | ||
|
||
[JsonProperty("network")] | ||
public string Network { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public class Busy : CallStatusEvent | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public abstract class CallStatusEvent : Event | ||
{ | ||
[JsonProperty("to")] | ||
public string To { get; set; } | ||
|
||
[JsonProperty("from")] | ||
public string From { get; set; } | ||
|
||
[JsonProperty("conversation_uuid")] | ||
public string ConversationUuid { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public string Status { get; set; } | ||
|
||
[JsonProperty("direction")] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public Direction Direction { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public class Cancelled : CallStatusEvent | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public class Completed : CallStatusEvent | ||
{ | ||
[JsonProperty("end_time")] | ||
public DateTime EndTime { get; set; } | ||
|
||
[JsonProperty("network")] | ||
public string Network { get; set; } | ||
|
||
[JsonProperty("duration")] | ||
public string Duration { get; set; } | ||
|
||
[JsonProperty("start_time")] | ||
public DateTime StartTime { get; set; } | ||
|
||
[JsonProperty("rate")] | ||
public string Rate { get; set; } | ||
|
||
[JsonProperty("price")] | ||
public string Price { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public enum Direction | ||
{ | ||
inbound = 1, | ||
outbound = 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public class Error : EventBase | ||
{ | ||
[JsonProperty("reason")] | ||
public string Reason { get; set; } | ||
|
||
[JsonProperty("conversation_uuid")] | ||
public string ConversationUuid { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Nexmo.Api.Voice.EventWebhooks | ||
{ | ||
public abstract class Event : EventBase | ||
{ | ||
[JsonProperty("uuid")] | ||
public virtual string Uuid { get; set; } | ||
} | ||
} |
Oops, something went wrong.