diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-16 19:50:44 -0800 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-16 19:50:44 -0800 |
commit | bb49c775d5c50470a6ae553d9bbddeca93e0d224 (patch) | |
tree | 48ef3238dec79c21af1770cee60e6da15858d967 | |
parent | f7610d321d601d5a6b7dabe8af0cfa30bad39fe5 (diff) | |
download | sendgrid-csharp-bb49c775d5c50470a6ae553d9bbddeca93e0d224.zip sendgrid-csharp-bb49c775d5c50470a6ae553d9bbddeca93e0d224.tar.gz sendgrid-csharp-bb49c775d5c50470a6ae553d9bbddeca93e0d224.tar.bz2 |
Use enum instead of String
via deckarep
-rw-r--r-- | SendGrid/SendGrid/Client.cs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/SendGrid/SendGrid/Client.cs b/SendGrid/SendGrid/Client.cs index e642485..bbb4af5 100644 --- a/SendGrid/SendGrid/Client.cs +++ b/SendGrid/SendGrid/Client.cs @@ -15,6 +15,10 @@ namespace SendGrid private string _apiKey; public APIKeys ApiKeys; private Uri _baseUri; + private enum Methods + { + GET, POST, PATCH, DELETE + } /// <summary> /// Create a client that connects to the SendGrid Web API @@ -35,7 +39,7 @@ namespace SendGrid /// <param name="endpoint">Resource endpoint, do not prepend slash</param> /// <param name="data">An JObject representing the resource's data</param> /// <returns>An asyncronous task</returns> - private async Task<HttpResponseMessage> RequestAsync(string method, string endpoint, JObject data) + private async Task<HttpResponseMessage> RequestAsync(Methods method, string endpoint, JObject data) { using (var client = new HttpClient()) { @@ -48,13 +52,13 @@ namespace SendGrid var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/" + version + ";csharp"); - switch (method.ToLower()) + switch (method) { - case "get": + case Methods.GET: return await client.GetAsync(endpoint); - case "post": + case Methods.POST: return await client.PostAsJsonAsync(endpoint, data); - case "patch": + case Methods.PATCH: endpoint = _baseUri + endpoint; StringContent content = new StringContent(data.ToString(), Encoding.UTF8, "application/json"); HttpRequestMessage request = new HttpRequestMessage @@ -64,7 +68,7 @@ namespace SendGrid Content = content }; return await client.SendAsync(request); - case "delete": + case Methods.DELETE: return await client.DeleteAsync(endpoint); default: HttpResponseMessage response = new HttpResponseMessage(); @@ -92,7 +96,7 @@ namespace SendGrid /// <returns>The resulting message from the API call</returns> public HttpResponseMessage Get(string endpoint) { - return RequestAsync("GET", endpoint, null).Result; + return RequestAsync(Methods.GET, endpoint, null).Result; } /// <param name="endpoint">Resource endpoint, do not prepend slash</param> @@ -100,14 +104,14 @@ namespace SendGrid /// <returns>The resulting message from the API call</returns> public HttpResponseMessage Post(string endpoint, JObject data) { - return RequestAsync("POST", endpoint, data).Result; + return RequestAsync(Methods.POST, endpoint, data).Result; } /// <param name="endpoint">Resource endpoint, do not prepend slash</param> /// <returns>The resulting message from the API call</returns> public HttpResponseMessage Delete(string endpoint) { - return RequestAsync("DELETE", endpoint, null).Result; + return RequestAsync(Methods.DELETE, endpoint, null).Result; } /// <param name="endpoint">Resource endpoint, do not prepend slash</param> @@ -115,7 +119,7 @@ namespace SendGrid /// <returns>The resulting message from the API call</returns> public HttpResponseMessage Patch(string endpoint, JObject data) { - return RequestAsync("PATCH", endpoint, data).Result; + return RequestAsync(Methods.PATCH, endpoint, data).Result; } } } |