From af7cd630279d8ca6ca374c36759fbe5f8d948810 Mon Sep 17 00:00:00 2001 From: tr00d Date: Fri, 13 Sep 2024 09:43:32 +0200 Subject: [PATCH] refactor: add verification channel enum for VerifyV2 --- .../StartVerification/Email/EmailWorkflow.cs | 17 ++++---- .../SilentAuth/SilentAuthWorkflow.cs | 17 ++++---- .../StartVerification/Sms/SmsWorkflow.cs | 23 +++++++---- .../StartVerification/Voice/VoiceWorkflow.cs | 17 ++++---- .../WhatsApp/WhatsAppWorkflow.cs | 17 ++++---- .../WhatsAppInteractiveWorkflow.cs | 17 ++++---- Vonage/VerifyV2/VerificationChannel.cs | 41 +++++++++++++++++++ 7 files changed, 106 insertions(+), 43 deletions(-) create mode 100644 Vonage/VerifyV2/VerificationChannel.cs diff --git a/Vonage/VerifyV2/StartVerification/Email/EmailWorkflow.cs b/Vonage/VerifyV2/StartVerification/Email/EmailWorkflow.cs index 92261085c..23c96efb6 100644 --- a/Vonage/VerifyV2/StartVerification/Email/EmailWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/Email/EmailWorkflow.cs @@ -1,7 +1,10 @@ +#region using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; +#endregion namespace Vonage.VerifyV2.StartVerification.Email; @@ -16,10 +19,6 @@ private EmailWorkflow(MailAddress to, Maybe from) this.From = from; } - /// - [JsonPropertyOrder(0)] - public string Channel => "email"; - /// /// The email address to send the verification request from. /// @@ -35,6 +34,13 @@ private EmailWorkflow(MailAddress to, Maybe from) [JsonConverter(typeof(EmailJsonConverter))] public MailAddress To { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.Email.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a EmailWorkflow. /// @@ -52,7 +58,4 @@ public static Result Parse(string to) => public static Result Parse(string to, string from) => MailAddress.Parse(to) .Merge(MailAddress.Parse(from), (toNumber, fromNumber) => new EmailWorkflow(toNumber, fromNumber)); - - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs b/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs index 2550c0f2c..c3558f27c 100644 --- a/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs @@ -1,8 +1,11 @@ +#region using System; using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; +#endregion namespace Vonage.VerifyV2.StartVerification.SilentAuth; @@ -17,10 +20,6 @@ private SilentAuthWorkflow(PhoneNumber to, Uri redirectUrl = null) this.RedirectUrl = redirectUrl ?? Maybe.None; } - /// - [JsonPropertyOrder(0)] - public string Channel => "silent_auth"; - /// /// Final redirect added at the end of the check_url request/response lifecycle. See the documentation for integrations. Will contain the request_id and code as a url fragment after the URL. /// @@ -37,6 +36,13 @@ private SilentAuthWorkflow(PhoneNumber to, Uri redirectUrl = null) [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.SilentAuth.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a SilentAuthWorkflow. /// @@ -53,7 +59,4 @@ public static Result Parse(string to) => /// Success or failure. public static Result Parse(string to, Uri redirectUrl) => PhoneNumber.Parse(to).Map(phoneNumber => new SilentAuthWorkflow(phoneNumber, redirectUrl)); - - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/Sms/SmsWorkflow.cs b/Vonage/VerifyV2/StartVerification/Sms/SmsWorkflow.cs index ce049a4c2..cdced5690 100644 --- a/Vonage/VerifyV2/StartVerification/Sms/SmsWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/Sms/SmsWorkflow.cs @@ -1,8 +1,11 @@ +#region using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; using Vonage.Common.Validation; +#endregion namespace Vonage.VerifyV2.StartVerification.Sms; @@ -24,10 +27,6 @@ private SmsWorkflow(PhoneNumber to, Maybe hash, Maybe entityId, this.To = to; } - /// - [JsonPropertyOrder(0)] - public string Channel => "sms"; - /// /// Optional Android Application Hash Key for automatic code detection on a user's device. /// @@ -74,6 +73,13 @@ private SmsWorkflow(PhoneNumber to, Maybe hash, Maybe entityId, [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Maybe From { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.Sms.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a SmsWorkflow. /// @@ -81,7 +87,11 @@ private SmsWorkflow(PhoneNumber to, Maybe hash, Maybe entityId, /// The Android application hash key. /// Optional PEID required for SMS delivery using Indian Carriers /// Optional value corresponding to a TemplateID for SMS delivery using Indian Carriers - /// An optional sender number, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start with the country code, for example, 447700900000. If no from number is given, the request will default to the brand. + /// + /// An optional sender number, in the E.164 format. Don't use a leading + or 00 when entering a phone + /// number, start with the country code, for example, 447700900000. If no from number is given, the request will + /// default to the brand. + /// /// Success or failure. public static Result Parse(string to, string hash = null, string entityId = null, string contentId = null, string from = null) @@ -106,9 +116,6 @@ public static Result Parse(string to, string hash = null, string en .Bind(VerifyWorkflowContentIdLength); } - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); - private static Result VerifyWorkflowHashLength( SmsWorkflow request) => request.Hash.Match(some => InputValidation.VerifyLength(request, some, 11, nameof(request.Hash)), diff --git a/Vonage/VerifyV2/StartVerification/Voice/VoiceWorkflow.cs b/Vonage/VerifyV2/StartVerification/Voice/VoiceWorkflow.cs index f0229befe..f1bc81c86 100644 --- a/Vonage/VerifyV2/StartVerification/Voice/VoiceWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/Voice/VoiceWorkflow.cs @@ -1,7 +1,10 @@ +#region using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; +#endregion namespace Vonage.VerifyV2.StartVerification.Voice; @@ -12,10 +15,6 @@ namespace Vonage.VerifyV2.StartVerification.Voice; { private VoiceWorkflow(PhoneNumber to) => this.To = to; - /// - [JsonPropertyOrder(0)] - public string Channel => "voice"; - /// /// The phone number to contact, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start /// with the country code, for example, 447700900000. @@ -24,6 +23,13 @@ namespace Vonage.VerifyV2.StartVerification.Voice; [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.Voice.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a VoiceWorkflow. /// @@ -31,7 +37,4 @@ namespace Vonage.VerifyV2.StartVerification.Voice; /// Success or failure. public static Result Parse(string to) => PhoneNumber.Parse(to).Map(phoneNumber => new VoiceWorkflow(phoneNumber)); - - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs b/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs index 49d16b4fb..8e8c99619 100644 --- a/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs @@ -1,7 +1,10 @@ +#region using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; +#endregion namespace Vonage.VerifyV2.StartVerification.WhatsApp; @@ -16,10 +19,6 @@ private WhatsAppWorkflow(PhoneNumber to, PhoneNumber from) this.From = from; } - /// - [JsonPropertyOrder(0)] - public string Channel => "whatsapp"; - /// /// An optional sender number, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start /// with the country code, for example, 447700900000. @@ -36,6 +35,13 @@ private WhatsAppWorkflow(PhoneNumber to, PhoneNumber from) [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.WhatsApp.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a WhatsAppWorkflow. /// @@ -45,7 +51,4 @@ private WhatsAppWorkflow(PhoneNumber to, PhoneNumber from) public static Result Parse(string to, string from) => PhoneNumber.Parse(to).Merge(PhoneNumber.Parse(from), (toNumber, fromNumber) => new WhatsAppWorkflow(toNumber, fromNumber)); - - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/WhatsAppInteractive/WhatsAppInteractiveWorkflow.cs b/Vonage/VerifyV2/StartVerification/WhatsAppInteractive/WhatsAppInteractiveWorkflow.cs index cfb62977d..7527fea1c 100644 --- a/Vonage/VerifyV2/StartVerification/WhatsAppInteractive/WhatsAppInteractiveWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/WhatsAppInteractive/WhatsAppInteractiveWorkflow.cs @@ -1,7 +1,10 @@ +#region using System.Text.Json.Serialization; +using EnumsNET; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; +#endregion namespace Vonage.VerifyV2.StartVerification.WhatsAppInteractive; @@ -12,10 +15,6 @@ namespace Vonage.VerifyV2.StartVerification.WhatsAppInteractive; { private WhatsAppInteractiveWorkflow(PhoneNumber to) => this.To = to; - /// - [JsonPropertyOrder(0)] - public string Channel => "whatsapp_interactive"; - /// /// The phone number to contact, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start /// with the country code, for example, 447700900000. @@ -24,6 +23,13 @@ namespace Vonage.VerifyV2.StartVerification.WhatsAppInteractive; [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } + /// + [JsonPropertyOrder(0)] + public string Channel => VerificationChannel.WhatsAppInteractive.AsString(EnumFormat.Description); + + /// + public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); + /// /// Parses the input into a WhatsAppInteractiveWorkflow. /// @@ -31,7 +37,4 @@ namespace Vonage.VerifyV2.StartVerification.WhatsAppInteractive; /// Success or failure. public static Result Parse(string to) => PhoneNumber.Parse(to).Map(phoneNumber => new WhatsAppInteractiveWorkflow(phoneNumber)); - - /// - public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file diff --git a/Vonage/VerifyV2/VerificationChannel.cs b/Vonage/VerifyV2/VerificationChannel.cs new file mode 100644 index 000000000..588c09152 --- /dev/null +++ b/Vonage/VerifyV2/VerificationChannel.cs @@ -0,0 +1,41 @@ +#region +using System.ComponentModel; +#endregion + +namespace Vonage.VerifyV2; + +/// +/// Represents supported verification channels. +/// +public enum VerificationChannel +{ + /// + /// SMS + /// + [Description("sms")] Sms, + + /// + /// Voice + /// + [Description("voice")] Voice, + + /// + /// Email + /// + [Description("email")] Email, + + /// + /// Silent Auth + /// + [Description("silent_auth")] SilentAuth, + + /// + /// WhatsApp + /// + [Description("whatsapp")] WhatsApp, + + /// + /// WhatsApp Interactive + /// + [Description("whatsapp_interactive")] WhatsAppInteractive, +} \ No newline at end of file