From 8c6051d44c7bc74994d335752fa5de7a19e6ea2d Mon Sep 17 00:00:00 2001 From: ammaraltahan Date: Thu, 22 Mar 2018 17:01:54 -0400 Subject: [PATCH 1/5] Introducing an interface for VerifyClient for test-ability. Interface for VerifyClient comes very handy in unit testing, it is much easier to mock an interface than mock a concrete class. --- IVerifyClient.cs | 61 +++++++++++++++++++++ TelesignEnterprise.csproj | 67 +++++++++++++++++++++++ VerifyClient.cs | 108 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 IVerifyClient.cs create mode 100644 TelesignEnterprise.csproj create mode 100644 VerifyClient.cs diff --git a/IVerifyClient.cs b/IVerifyClient.cs new file mode 100644 index 0000000..b7a47ff --- /dev/null +++ b/IVerifyClient.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using Telesign; + +namespace TelesignEnterprise +{ + /// + /// The Verify API delivers phone-based verification and two-factor authentication using a time-based, one-time passcode + /// sent via SMS message, Voice call or Push Notification. + /// + public interface IVerifyClient + { + /// + /// The SMS Verify API delivers phone-based verification and two-factor authentication using a time-based, + /// one-time passcode sent over SMS. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-sms for detailed API documentation. + /// + RestClient.TelesignResponse Sms(string phoneNumber, Dictionary parameters = null); + + /// + /// The Voice Verify API delivers patented phone-based verification and two-factor authentication using a one-time + /// passcode sent over verify_voice message. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-call for detailed API documentation. + /// + RestClient.TelesignResponse Voice(string phoneNumber, Dictionary parameters = null); + + /// + /// The Smart Verify web service simplifies the process of verifying user identity by integrating several TeleSign + /// web services into a single API call. This eliminates the need for you to make multiple calls to the TeleSign + /// Verify resource. + /// + /// See https://developer.telesign.com/docs/rest_api-smart-verify for detailed API documentation. + /// + RestClient.TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null); + + /// + /// The Push Verify web service allows you to provide on-device transaction authorization for your end users. It + /// works by delivering authorization requests to your end users via push notification, and then by receiving their + /// permission responses via their mobile device's wireless Internet connection. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-push for detailed API documentation. + /// + RestClient.TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null); + + /// + /// Retrieves the verification result for any verify resource. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-transaction-callback for detailed API documentation. + /// + RestClient.TelesignResponse Status(string referenceId, Dictionary parameters = null); + + /// + /// Notifies TeleSign that a verification was successfully delivered to the user in order to help improve the + /// quality of message delivery routes. + /// + /// See https://developer.telesign.com/docs/completion-service-for-verify-products for detailed API documentation. + /// + RestClient.TelesignResponse Completion(string referenceId, Dictionary parameters = null); + } +} \ No newline at end of file diff --git a/TelesignEnterprise.csproj b/TelesignEnterprise.csproj new file mode 100644 index 0000000..000c2ad --- /dev/null +++ b/TelesignEnterprise.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {57AC6F58-E6ED-44D4-8F62-78A5EC6DFA1E} + Library + Properties + TelesignEnterprise + TelesignEnterprise + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + ..\packages\Telesign.2.1.0\lib\net452\Telesign.dll + True + + + + + + + + + + + + + Designer + + + + + \ No newline at end of file diff --git a/VerifyClient.cs b/VerifyClient.cs new file mode 100644 index 0000000..31c441c --- /dev/null +++ b/VerifyClient.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Net; +using Telesign; + +namespace TelesignEnterprise +{ + + public class VerifyClient : RestClient, IVerifyClient + { + private const string VERIFY_SMS_RESOURCE = "/v1/verify/sms"; + private const string VERIFY_VOICE_RESOURCE = "/v1/verify/call"; + private const string VERIFY_SMART_RESOURCE = "/v1/verify/smart"; + private const string VERIFY_PUSH_RESOURCE = "/v2/verify/push"; + private const string VERIFY_STATUS_RESOURCE = "/v1/verify/{0}"; + private const string VERIFY_COMPLETION_RESOURCE = "/v1/verify/completion/{0}"; + + public VerifyClient(string customerId, + string apiKey) + : base(customerId, + apiKey, + restEndpoint: "https://rest-ww.telesign.com") + { } + + public VerifyClient(string customerId, + string apiKey, + string restEndpoint) + : base(customerId, + apiKey, + restEndpoint) + { } + + public VerifyClient(string customerId, + string apiKey, + string restEndpoint, + int timeout, + WebProxy proxy, + string proxyUsername, + string proxyPassword) + : base(customerId, + apiKey, + restEndpoint: restEndpoint, + timeout: timeout, + proxy: proxy, + proxyUsername: proxyUsername, + proxyPassword: proxyPassword) + { } + + public TelesignResponse Sms(string phoneNumber, Dictionary parameters = null) + { + if (parameters == null) + { + parameters = new Dictionary(); + } + + parameters.Add("phone_number", phoneNumber); + + return this.Post(VERIFY_SMS_RESOURCE, parameters); + } + + public TelesignResponse Voice(string phoneNumber, Dictionary parameters = null) + { + if (parameters == null) + { + parameters = new Dictionary(); + } + + parameters.Add("phone_number", phoneNumber); + + return this.Post(VERIFY_VOICE_RESOURCE, parameters); + } + + public TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null) + { + if (parameters == null) + { + parameters = new Dictionary(); + } + + parameters.Add("phone_number", phoneNumber); + parameters.Add("ucid", ucid); + + return this.Post(VERIFY_SMART_RESOURCE, parameters); + } + + public TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null) + { + if (parameters == null) + { + parameters = new Dictionary(); + } + + parameters.Add("phone_number", phoneNumber); + parameters.Add("ucid", ucid); + + return this.Post(VERIFY_PUSH_RESOURCE, parameters); + } + + public TelesignResponse Status(string referenceId, Dictionary parameters = null) + { + return this.Get(string.Format(VERIFY_STATUS_RESOURCE, referenceId), parameters); + } + + public TelesignResponse Completion(string referenceId, Dictionary parameters = null) + { + return this.Put(string.Format(VERIFY_COMPLETION_RESOURCE, referenceId), parameters); + } + } +} From 59b1bd101da49590b678a2b2648ddf2f2a35397f Mon Sep 17 00:00:00 2001 From: ammaraltahan Date: Thu, 22 Mar 2018 17:05:04 -0400 Subject: [PATCH 2/5] introduce an interface IVerifyClient for testing, it is much easier to mock an interface than a concrete class. --- TelesignEnterprise/IVerifyClient.cs | 61 ++++++++++ TelesignEnterprise/TelesignEnterprise.csproj | 119 ++++++++++--------- TelesignEnterprise/VerifyClient.cs | 55 ++------- 3 files changed, 128 insertions(+), 107 deletions(-) create mode 100644 TelesignEnterprise/IVerifyClient.cs diff --git a/TelesignEnterprise/IVerifyClient.cs b/TelesignEnterprise/IVerifyClient.cs new file mode 100644 index 0000000..b7a47ff --- /dev/null +++ b/TelesignEnterprise/IVerifyClient.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using Telesign; + +namespace TelesignEnterprise +{ + /// + /// The Verify API delivers phone-based verification and two-factor authentication using a time-based, one-time passcode + /// sent via SMS message, Voice call or Push Notification. + /// + public interface IVerifyClient + { + /// + /// The SMS Verify API delivers phone-based verification and two-factor authentication using a time-based, + /// one-time passcode sent over SMS. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-sms for detailed API documentation. + /// + RestClient.TelesignResponse Sms(string phoneNumber, Dictionary parameters = null); + + /// + /// The Voice Verify API delivers patented phone-based verification and two-factor authentication using a one-time + /// passcode sent over verify_voice message. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-call for detailed API documentation. + /// + RestClient.TelesignResponse Voice(string phoneNumber, Dictionary parameters = null); + + /// + /// The Smart Verify web service simplifies the process of verifying user identity by integrating several TeleSign + /// web services into a single API call. This eliminates the need for you to make multiple calls to the TeleSign + /// Verify resource. + /// + /// See https://developer.telesign.com/docs/rest_api-smart-verify for detailed API documentation. + /// + RestClient.TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null); + + /// + /// The Push Verify web service allows you to provide on-device transaction authorization for your end users. It + /// works by delivering authorization requests to your end users via push notification, and then by receiving their + /// permission responses via their mobile device's wireless Internet connection. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-push for detailed API documentation. + /// + RestClient.TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null); + + /// + /// Retrieves the verification result for any verify resource. + /// + /// See https://developer.telesign.com/docs/rest_api-verify-transaction-callback for detailed API documentation. + /// + RestClient.TelesignResponse Status(string referenceId, Dictionary parameters = null); + + /// + /// Notifies TeleSign that a verification was successfully delivered to the user in order to help improve the + /// quality of message delivery routes. + /// + /// See https://developer.telesign.com/docs/completion-service-for-verify-products for detailed API documentation. + /// + RestClient.TelesignResponse Completion(string referenceId, Dictionary parameters = null); + } +} \ No newline at end of file diff --git a/TelesignEnterprise/TelesignEnterprise.csproj b/TelesignEnterprise/TelesignEnterprise.csproj index 5a42691..000c2ad 100644 --- a/TelesignEnterprise/TelesignEnterprise.csproj +++ b/TelesignEnterprise/TelesignEnterprise.csproj @@ -1,66 +1,67 @@ - - - - - Debug - AnyCPU - {57AC6F58-E6ED-44D4-8F62-78A5EC6DFA1E} - Library - Properties - TelesignEnterprise - TelesignEnterprise - v4.5.2 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - ..\packages\Telesign.2.1.0\lib\net452\Telesign.dll - True - - - - - - - - - - - - Designer - - - + + + + + Debug + AnyCPU + {57AC6F58-E6ED-44D4-8F62-78A5EC6DFA1E} + Library + Properties + TelesignEnterprise + TelesignEnterprise + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + ..\packages\Telesign.2.1.0\lib\net452\Telesign.dll + True + + + + + + + + + + + + + Designer + + + + --> \ No newline at end of file diff --git a/TelesignEnterprise/VerifyClient.cs b/TelesignEnterprise/VerifyClient.cs index 1908796..31c441c 100644 --- a/TelesignEnterprise/VerifyClient.cs +++ b/TelesignEnterprise/VerifyClient.cs @@ -4,13 +4,9 @@ namespace TelesignEnterprise { - /// - /// The Verify API delivers phone-based verification and two-factor authentication using a time-based, one-time passcode - /// sent via SMS message, Voice call or Push Notification. - /// - public class VerifyClient : RestClient + + public class VerifyClient : RestClient, IVerifyClient { - private const string VERIFY_SMS_RESOURCE = "/v1/verify/sms"; private const string VERIFY_VOICE_RESOURCE = "/v1/verify/call"; private const string VERIFY_SMART_RESOURCE = "/v1/verify/smart"; @@ -48,13 +44,7 @@ public VerifyClient(string customerId, proxyUsername: proxyUsername, proxyPassword: proxyPassword) { } - - /// - /// The SMS Verify API delivers phone-based verification and two-factor authentication using a time-based, - /// one-time passcode sent over SMS. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-sms for detailed API documentation. - /// + public TelesignResponse Sms(string phoneNumber, Dictionary parameters = null) { if (parameters == null) @@ -66,13 +56,7 @@ public TelesignResponse Sms(string phoneNumber, Dictionary param return this.Post(VERIFY_SMS_RESOURCE, parameters); } - - /// - /// The Voice Verify API delivers patented phone-based verification and two-factor authentication using a one-time - /// passcode sent over verify_voice message. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-call for detailed API documentation. - /// + public TelesignResponse Voice(string phoneNumber, Dictionary parameters = null) { if (parameters == null) @@ -85,13 +69,6 @@ public TelesignResponse Voice(string phoneNumber, Dictionary par return this.Post(VERIFY_VOICE_RESOURCE, parameters); } - /// - /// The Smart Verify web service simplifies the process of verifying user identity by integrating several TeleSign - /// web services into a single API call. This eliminates the need for you to make multiple calls to the TeleSign - /// Verify resource. - /// - /// See https://developer.telesign.com/docs/rest_api-smart-verify for detailed API documentation. - /// public TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null) { if (parameters == null) @@ -104,14 +81,7 @@ public TelesignResponse Smart(string phoneNumber, string ucid, Dictionary - /// The Push Verify web service allows you to provide on-device transaction authorization for your end users. It - /// works by delivering authorization requests to your end users via push notification, and then by receiving their - /// permission responses via their mobile device's wireless Internet connection. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-push for detailed API documentation. - /// + public TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null) { if (parameters == null) @@ -124,23 +94,12 @@ public TelesignResponse Push(string phoneNumber, string ucid, Dictionary - /// Retrieves the verification result for any verify resource. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-transaction-callback for detailed API documentation. - /// + public TelesignResponse Status(string referenceId, Dictionary parameters = null) { return this.Get(string.Format(VERIFY_STATUS_RESOURCE, referenceId), parameters); } - - /// - /// Notifies TeleSign that a verification was successfully delivered to the user in order to help improve the - /// quality of message delivery routes. - /// - /// See https://developer.telesign.com/docs/completion-service-for-verify-products for detailed API documentation. - /// + public TelesignResponse Completion(string referenceId, Dictionary parameters = null) { return this.Put(string.Format(VERIFY_COMPLETION_RESOURCE, referenceId), parameters); From 20655670c00829d1ce4dc1e750d00479bc5279a2 Mon Sep 17 00:00:00 2001 From: ammaraltahan Date: Thu, 22 Mar 2018 17:07:26 -0400 Subject: [PATCH 3/5] Delete TelesignEnterprise.csproj --- TelesignEnterprise.csproj | 67 --------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 TelesignEnterprise.csproj diff --git a/TelesignEnterprise.csproj b/TelesignEnterprise.csproj deleted file mode 100644 index 000c2ad..0000000 --- a/TelesignEnterprise.csproj +++ /dev/null @@ -1,67 +0,0 @@ - - - - - Debug - AnyCPU - {57AC6F58-E6ED-44D4-8F62-78A5EC6DFA1E} - Library - Properties - TelesignEnterprise - TelesignEnterprise - v4.5.2 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - ..\packages\Telesign.2.1.0\lib\net452\Telesign.dll - True - - - - - - - - - - - - - Designer - - - - - \ No newline at end of file From c0ec86283eeda7b030294ab15c954f53df44f516 Mon Sep 17 00:00:00 2001 From: ammaraltahan Date: Thu, 22 Mar 2018 17:07:36 -0400 Subject: [PATCH 4/5] Delete VerifyClient.cs --- VerifyClient.cs | 108 ------------------------------------------------ 1 file changed, 108 deletions(-) delete mode 100644 VerifyClient.cs diff --git a/VerifyClient.cs b/VerifyClient.cs deleted file mode 100644 index 31c441c..0000000 --- a/VerifyClient.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.Collections.Generic; -using System.Net; -using Telesign; - -namespace TelesignEnterprise -{ - - public class VerifyClient : RestClient, IVerifyClient - { - private const string VERIFY_SMS_RESOURCE = "/v1/verify/sms"; - private const string VERIFY_VOICE_RESOURCE = "/v1/verify/call"; - private const string VERIFY_SMART_RESOURCE = "/v1/verify/smart"; - private const string VERIFY_PUSH_RESOURCE = "/v2/verify/push"; - private const string VERIFY_STATUS_RESOURCE = "/v1/verify/{0}"; - private const string VERIFY_COMPLETION_RESOURCE = "/v1/verify/completion/{0}"; - - public VerifyClient(string customerId, - string apiKey) - : base(customerId, - apiKey, - restEndpoint: "https://rest-ww.telesign.com") - { } - - public VerifyClient(string customerId, - string apiKey, - string restEndpoint) - : base(customerId, - apiKey, - restEndpoint) - { } - - public VerifyClient(string customerId, - string apiKey, - string restEndpoint, - int timeout, - WebProxy proxy, - string proxyUsername, - string proxyPassword) - : base(customerId, - apiKey, - restEndpoint: restEndpoint, - timeout: timeout, - proxy: proxy, - proxyUsername: proxyUsername, - proxyPassword: proxyPassword) - { } - - public TelesignResponse Sms(string phoneNumber, Dictionary parameters = null) - { - if (parameters == null) - { - parameters = new Dictionary(); - } - - parameters.Add("phone_number", phoneNumber); - - return this.Post(VERIFY_SMS_RESOURCE, parameters); - } - - public TelesignResponse Voice(string phoneNumber, Dictionary parameters = null) - { - if (parameters == null) - { - parameters = new Dictionary(); - } - - parameters.Add("phone_number", phoneNumber); - - return this.Post(VERIFY_VOICE_RESOURCE, parameters); - } - - public TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null) - { - if (parameters == null) - { - parameters = new Dictionary(); - } - - parameters.Add("phone_number", phoneNumber); - parameters.Add("ucid", ucid); - - return this.Post(VERIFY_SMART_RESOURCE, parameters); - } - - public TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null) - { - if (parameters == null) - { - parameters = new Dictionary(); - } - - parameters.Add("phone_number", phoneNumber); - parameters.Add("ucid", ucid); - - return this.Post(VERIFY_PUSH_RESOURCE, parameters); - } - - public TelesignResponse Status(string referenceId, Dictionary parameters = null) - { - return this.Get(string.Format(VERIFY_STATUS_RESOURCE, referenceId), parameters); - } - - public TelesignResponse Completion(string referenceId, Dictionary parameters = null) - { - return this.Put(string.Format(VERIFY_COMPLETION_RESOURCE, referenceId), parameters); - } - } -} From 55f0a214520e9cbdef475a49dd5cd2de4a03211d Mon Sep 17 00:00:00 2001 From: ammaraltahan Date: Thu, 22 Mar 2018 17:07:47 -0400 Subject: [PATCH 5/5] Delete IVerifyClient.cs --- IVerifyClient.cs | 61 ------------------------------------------------ 1 file changed, 61 deletions(-) delete mode 100644 IVerifyClient.cs diff --git a/IVerifyClient.cs b/IVerifyClient.cs deleted file mode 100644 index b7a47ff..0000000 --- a/IVerifyClient.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections.Generic; -using Telesign; - -namespace TelesignEnterprise -{ - /// - /// The Verify API delivers phone-based verification and two-factor authentication using a time-based, one-time passcode - /// sent via SMS message, Voice call or Push Notification. - /// - public interface IVerifyClient - { - /// - /// The SMS Verify API delivers phone-based verification and two-factor authentication using a time-based, - /// one-time passcode sent over SMS. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-sms for detailed API documentation. - /// - RestClient.TelesignResponse Sms(string phoneNumber, Dictionary parameters = null); - - /// - /// The Voice Verify API delivers patented phone-based verification and two-factor authentication using a one-time - /// passcode sent over verify_voice message. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-call for detailed API documentation. - /// - RestClient.TelesignResponse Voice(string phoneNumber, Dictionary parameters = null); - - /// - /// The Smart Verify web service simplifies the process of verifying user identity by integrating several TeleSign - /// web services into a single API call. This eliminates the need for you to make multiple calls to the TeleSign - /// Verify resource. - /// - /// See https://developer.telesign.com/docs/rest_api-smart-verify for detailed API documentation. - /// - RestClient.TelesignResponse Smart(string phoneNumber, string ucid, Dictionary parameters = null); - - /// - /// The Push Verify web service allows you to provide on-device transaction authorization for your end users. It - /// works by delivering authorization requests to your end users via push notification, and then by receiving their - /// permission responses via their mobile device's wireless Internet connection. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-push for detailed API documentation. - /// - RestClient.TelesignResponse Push(string phoneNumber, string ucid, Dictionary parameters = null); - - /// - /// Retrieves the verification result for any verify resource. - /// - /// See https://developer.telesign.com/docs/rest_api-verify-transaction-callback for detailed API documentation. - /// - RestClient.TelesignResponse Status(string referenceId, Dictionary parameters = null); - - /// - /// Notifies TeleSign that a verification was successfully delivered to the user in order to help improve the - /// quality of message delivery routes. - /// - /// See https://developer.telesign.com/docs/completion-service-for-verify-products for detailed API documentation. - /// - RestClient.TelesignResponse Completion(string referenceId, Dictionary parameters = null); - } -} \ No newline at end of file