Last active
December 19, 2019 20:36
-
-
Save slorello89/680f24001854039d5bd6b36924791d09 to your computer and use it in GitHub Desktop.
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
using System; | |
using Newtonsoft.Json; | |
using System.Net.Http; | |
using System.Net; | |
using System.IO; | |
using System.Diagnostics; | |
namespace ConsoleApp15 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
var client = new HttpClient(); | |
const string BASE_URL = "https://api.nexmo.com"; | |
const string VERSION = ""; | |
const string API_KEY = "NEXMO_API_KEY"; | |
const string API_SECRET = "NEXMO_API_SECRET"; | |
const string ACTION = "/verify/templates"; | |
var URL = BASE_URL + VERSION + ACTION + "?api_key=" + API_KEY + "&api_secret=" + API_SECRET; | |
var request = new TemplateRequest() | |
{ | |
ActionType = "sms", | |
LanguageCode = "en-gb", | |
ContactEmail = "foo@bar.com", | |
Template = "Your {brand} verification code is ${pin}" | |
}; | |
var httpWebRequest = (HttpWebRequest)WebRequest.Create(URL); | |
httpWebRequest.ContentType = "application/json"; | |
httpWebRequest.Accept = "application/json"; | |
httpWebRequest.Method = "POST"; | |
using (var sw = new StreamWriter(httpWebRequest.GetRequestStream())) | |
{ | |
var json = JsonConvert.SerializeObject(request); | |
sw.Write(json); | |
} | |
var httpRespone = (HttpWebResponse)httpWebRequest.GetResponse(); | |
using(var sr = new StreamReader(httpRespone.GetResponseStream())) | |
{ | |
var result = sr.ReadToEnd(); | |
var response = JsonConvert.DeserializeObject<TemplateResponse>(result); | |
Debug.WriteLine(response.AccountId + " " + response.Status + " " + response.Template); | |
} | |
} | |
public class TemplateRequest | |
{ | |
[JsonProperty("action_type")] | |
public string ActionType { get; set; } | |
[JsonProperty("lg")] | |
public string LanguageCode { get; set; } | |
[JsonProperty("template")] | |
public string Template { get; set; } | |
[JsonProperty("tyoe")] | |
public string SMSType { get; set; } | |
[JsonProperty("welcome_message")] | |
public string WelcomeMessage { get; set; } | |
[JsonProperty("bye_message")] | |
public string ByeMessage { get; set; } | |
[JsonProperty("contact_email")] | |
public string ContactEmail { get; set; } | |
} | |
public class TemplateResponse | |
{ | |
[JsonProperty("account_id")] | |
public string AccountId { get; set; } | |
[JsonProperty("action_type")] | |
public string ActionType { get; set; } | |
[JsonProperty("bye_message")] | |
public string ByeMessage { get; set; } | |
[JsonProperty("lg")] | |
public string LanguageCode { get; set; } | |
[JsonProperty("status")] | |
public string Status { get; set; } | |
[JsonProperty("template")] | |
public string Template { get; set; } | |
[JsonProperty("type")] | |
public string SmsType { get; set; } | |
[JsonProperty("version")] | |
public string Version { get; set; } | |
[JsonProperty("welcome_message")] | |
public string WelcomeMessage { get; set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment