From e0b280a5aca97c8f0f0e6a758ccc721854e1160b Mon Sep 17 00:00:00 2001 From: Robert Ramsay Date: Sun, 11 Mar 2018 15:37:09 -0700 Subject: [PATCH 1/4] Replace Dictionary.Add with Item property so that parameters may be overwritten without thowing exceptions --- Telesign.Example/PhoneId/Addons.cs | 9 +++++---- Telesign.Test/RestClientTest.cs | 8 ++++---- Telesign/MessagingClient.cs | 6 +++--- Telesign/PhoneIdClient.cs | 2 +- Telesign/Properties/AssemblyInfo.cs | 2 +- Telesign/RestClient.cs | 14 +++++++------- Telesign/ScoreClient.cs | 4 ++-- Telesign/Telesign.csproj | 3 +++ Telesign/VoiceClient.cs | 8 ++++---- 9 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Telesign.Example/PhoneId/Addons.cs b/Telesign.Example/PhoneId/Addons.cs index c5bc9a8..78912d8 100644 --- a/Telesign.Example/PhoneId/Addons.cs +++ b/Telesign.Example/PhoneId/Addons.cs @@ -12,10 +12,11 @@ static void Main(string[] args) string phoneNumber = "phone_number"; - Dictionary contact = new Dictionary(); - contact.Add("contact", new Dictionary()); - Dictionary parameters = new Dictionary(); - parameters.Add("addons", contact); + Dictionary parameters = { + "addons": [ + "contact" + ], + }; try { PhoneIdClient phoneIdClient = new PhoneIdClient(customerId, apiKey); diff --git a/Telesign.Test/RestClientTest.cs b/Telesign.Test/RestClientTest.cs index a9c1d28..abfd533 100644 --- a/Telesign.Test/RestClientTest.cs +++ b/Telesign.Test/RestClientTest.cs @@ -187,7 +187,7 @@ public void TestRestClientPost() { string testResource = "/test/resource"; Dictionary testParams = new Dictionary(); - testParams.Add("test", "123_\u03ff_test"); + testParams["test"] = "123_\u03ff_test"; RestClient client = new RestClient(this.customerId, this.apiKey, @@ -217,7 +217,7 @@ public void TestRestClientGet() { string testResource = "/test/resource"; Dictionary testParams = new Dictionary(); - testParams.Add("test", "123_\u03ff_test"); + testParams["test"] = "123_\u03ff_test"; RestClient client = new RestClient(this.customerId, this.apiKey, @@ -247,7 +247,7 @@ public void TestRestClientPut() { string testResource = "/test/resource"; Dictionary testParams = new Dictionary(); - testParams.Add("test", "123_\u03ff_test"); + testParams["test"] = "123_\u03ff_test"; RestClient client = new RestClient(this.customerId, this.apiKey, @@ -277,7 +277,7 @@ public void TestRestClientDelete() { string testResource = "/test/resource"; Dictionary testParams = new Dictionary(); - testParams.Add("test", "123_\u03ff_test"); + testParam["test"] = "123_\u03ff_test"; RestClient client = new RestClient(this.customerId, this.apiKey, diff --git a/Telesign/MessagingClient.cs b/Telesign/MessagingClient.cs index b7db5dd..051cb72 100644 --- a/Telesign/MessagingClient.cs +++ b/Telesign/MessagingClient.cs @@ -52,9 +52,9 @@ public TelesignResponse Message(string phoneNumber, string message, string messa if (null == parameters) parameters = new Dictionary(); - parameters.Add("phone_number", phoneNumber); - parameters.Add("message", message); - parameters.Add("message_type", messageType); + parameters["phone_number"] = phoneNumber; + parameters["message"] = message; + parameters["message_type"] = messageType; return Post(MESSAGING_RESOURCE, parameters); } diff --git a/Telesign/PhoneIdClient.cs b/Telesign/PhoneIdClient.cs index bde8b06..049d626 100644 --- a/Telesign/PhoneIdClient.cs +++ b/Telesign/PhoneIdClient.cs @@ -88,7 +88,7 @@ protected TelesignResponse Execute(string resource, HttpMethod method, Dictionar // proper way to set content-type is through content property of the request object if (header.Key == "Content-Type") continue; - request.Headers.Add(header.Key, header.Value); + request.Headers[header.Key] = header.Value; } HttpResponseMessage response = this.httpClient.SendAsync(request).Result; diff --git a/Telesign/Properties/AssemblyInfo.cs b/Telesign/Properties/AssemblyInfo.cs index 27a1833..bb40481 100644 --- a/Telesign/Properties/AssemblyInfo.cs +++ b/Telesign/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Telesign")] [assembly: AssemblyProduct("Telesign")] -[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyCopyright("Copyright © 2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Telesign/RestClient.cs b/Telesign/RestClient.cs index ebed54b..0c72ee6 100644 --- a/Telesign/RestClient.cs +++ b/Telesign/RestClient.cs @@ -191,15 +191,15 @@ public static Dictionary GenerateTelesignHeaders(string customer Dictionary headers = new Dictionary(); - headers.Add("Authorization", authorization); - headers.Add("Date", dateRfc2616); - headers.Add("Content-Type", contentType); - headers.Add("x-ts-auth-method", authMethod); - headers.Add("x-ts-nonce", nonce); + headers["Authorization"] = authorization; + headers["Date"] = dateRfc2616; + headers["Content-Type"] = contentType; + headers["x-ts-auth-method"] = authMethod; + headers["x-ts-nonce"] = nonce; if (userAgent != null) { - headers.Add("User-Agent", userAgent); + headers["User-Agent"] = userAgent; } return headers; @@ -296,7 +296,7 @@ private TelesignResponse Execute(string resource, HttpMethod method, Dictionary< // skip Content-Type, otherwise HttpClient will complain continue; - request.Headers.Add(header.Key, header.Value); + request.Headers[header.Key] = header.Value; } HttpResponseMessage response = this.httpClient.SendAsync(request).Result; diff --git a/Telesign/ScoreClient.cs b/Telesign/ScoreClient.cs index 7dca554..1684544 100644 --- a/Telesign/ScoreClient.cs +++ b/Telesign/ScoreClient.cs @@ -50,8 +50,8 @@ public TelesignResponse Score(string phoneNumber, string accountLifecycleEvent, { if (null == scoreParams) scoreParams = new Dictionary(); - scoreParams.Add("phone_number", phoneNumber); - scoreParams.Add("account_lifecycle_event", accountLifecycleEvent); + scoreParams["phone_number"] = phoneNumber; + scoreParams["account_lifecycle_event"] = accountLifecycleEvent; string resource = string.Format(SCORE_RESOURCE, phoneNumber); diff --git a/Telesign/Telesign.csproj b/Telesign/Telesign.csproj index 60b12e3..3152326 100644 --- a/Telesign/Telesign.csproj +++ b/Telesign/Telesign.csproj @@ -26,6 +26,9 @@ false false true + 2.2.2 + TeleSign + TeleSign true diff --git a/Telesign/VoiceClient.cs b/Telesign/VoiceClient.cs index d2d340d..a1dafea 100644 --- a/Telesign/VoiceClient.cs +++ b/Telesign/VoiceClient.cs @@ -52,9 +52,9 @@ public TelesignResponse Call(string phoneNumber, string message, string messageT if (null == callParams) callParams = new Dictionary(); - callParams.Add("phone_number", phoneNumber); - callParams.Add("message", message); - callParams.Add("message_type", messageType); + callParams["phone_number"] = phoneNumber; + callParams["message"] = message; + callParams["message_type"] = messageType; return Post(VOICE_RESOURCE, callParams); } @@ -68,7 +68,7 @@ public TelesignResponse Status(string referenceId, Dictionary st { if (null == statusParams) statusParams = new Dictionary(); - statusParams.Add("reference_id", referenceId); + statusParams["reference_id"] = referenceId; string resource = string.Format(VOICE_STATUS_RESOURCE, referenceId); From 625478aae7d865e5c487d8341e63bdfbd49b54de Mon Sep 17 00:00:00 2001 From: Robert Ramsay Date: Mon, 12 Mar 2018 11:19:08 -0700 Subject: [PATCH 2/4] Revert invalid modificaiton of request.Headers --- Telesign/PhoneIdClient.cs | 2 +- Telesign/RestClient.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Telesign/PhoneIdClient.cs b/Telesign/PhoneIdClient.cs index 049d626..bde8b06 100644 --- a/Telesign/PhoneIdClient.cs +++ b/Telesign/PhoneIdClient.cs @@ -88,7 +88,7 @@ protected TelesignResponse Execute(string resource, HttpMethod method, Dictionar // proper way to set content-type is through content property of the request object if (header.Key == "Content-Type") continue; - request.Headers[header.Key] = header.Value; + request.Headers.Add(header.Key, header.Value); } HttpResponseMessage response = this.httpClient.SendAsync(request).Result; diff --git a/Telesign/RestClient.cs b/Telesign/RestClient.cs index 0c72ee6..967fa4f 100644 --- a/Telesign/RestClient.cs +++ b/Telesign/RestClient.cs @@ -296,7 +296,7 @@ private TelesignResponse Execute(string resource, HttpMethod method, Dictionary< // skip Content-Type, otherwise HttpClient will complain continue; - request.Headers[header.Key] = header.Value; + request.Headers.Add(header.Key, header.Value); } HttpResponseMessage response = this.httpClient.SendAsync(request).Result; From e09b434c14fa7fc22175fe2d061c32ea8da23d77 Mon Sep 17 00:00:00 2001 From: Robert Ramsay Date: Mon, 12 Mar 2018 11:27:05 -0700 Subject: [PATCH 3/4] Fix dicitonary initialization in example code --- Telesign.Example/PhoneId/Addons.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Telesign.Example/PhoneId/Addons.cs b/Telesign.Example/PhoneId/Addons.cs index 78912d8..6a69ff0 100644 --- a/Telesign.Example/PhoneId/Addons.cs +++ b/Telesign.Example/PhoneId/Addons.cs @@ -12,11 +12,11 @@ static void Main(string[] args) string phoneNumber = "phone_number"; - Dictionary parameters = { - "addons": [ - "contact" - ], + Dictionary parameters = new Dictionary() + { + { "addons", new List() { "contact" } }, }; + try { PhoneIdClient phoneIdClient = new PhoneIdClient(customerId, apiKey); From 0e3131d4ea350b94f1c695fc98c5cf62739d8f09 Mon Sep 17 00:00:00 2001 From: Robert Ramsay Date: Mon, 12 Mar 2018 11:50:23 -0700 Subject: [PATCH 4/4] Fix variable name typo in tests --- Telesign.Test/RestClientTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telesign.Test/RestClientTest.cs b/Telesign.Test/RestClientTest.cs index abfd533..38410e1 100644 --- a/Telesign.Test/RestClientTest.cs +++ b/Telesign.Test/RestClientTest.cs @@ -277,7 +277,7 @@ public void TestRestClientDelete() { string testResource = "/test/resource"; Dictionary testParams = new Dictionary(); - testParam["test"] = "123_\u03ff_test"; + testParams["test"] = "123_\u03ff_test"; RestClient client = new RestClient(this.customerId, this.apiKey,