public HttpClient(EsendexCredentials credentials, Uri uri, IHttpRequestHelper httpRequestHelper, IHttpResponseHelper httpResponseHelper) { HttpRequestHelper = httpRequestHelper; HttpResponseHelper = httpResponseHelper; Credentials = credentials; Uri = uri; }
private static void GetContactsByGroupExample(EsendexCredentials credentials) { var groupService = new GroupService(credentials); try { var collection = groupService.GetGroups(_accountReference, PageIndex, PageSize); var contacts = new PagedContactCollection(); var groupId = ""; foreach (var item in collection.Groups.Where(item => item.Name == "Test group")) { groupId = item.Id.ToString(); break; } if (groupId == "") { return; } contacts = groupService.GetContactsFromGroup(_accountReference, groupId, 1, 15); foreach (var item in contacts.Contacts) { Console.WriteLine("\tContact Id:{0}\tNumber:{1}", item.Id, item.PhoneNumber); } } catch (WebException ex) { Console.Write(ex.Message); } }
private static void GetInboxMessagesExample(EsendexCredentials credentials, MessageBodyService messageBodyService) { var inboxService = new InboxService(credentials); try { var collection = inboxService.GetMessages(_accountReference, PageIndex, PageSize); foreach (var item in collection.Messages) { if (messageBodyService != null) { messageBodyService.LoadBodyText(item.Body); Console.WriteLine("\tMessage Id:{0}\tSummary:{1}\n\tBody:{2}\n", item.Id, item.Summary, item.Body.BodyText); } else { Console.WriteLine("\tMessage Id:{0}\tSummary:{1}", item.Id, item.Summary); } } } catch (WebException ex) { Console.Write(ex.Message); } }
public void DefaultConstructor() { // Arrange EsendexCredentials credentials = new EsendexCredentials("username", "password"); // Act SessionService serviceInstance = new SessionService(credentials); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf<RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf<XmlSerialiser>()); }
public void DefaultConstructor() { // Arrange EsendexCredentials credentials = new EsendexCredentials("username", "password"); // Act InboxService serviceInstance = new InboxService(credentials); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>()); }
public void DefaultDIConstructor_WithSessionId() { // Arrange var sessionId = Guid.NewGuid(); // Act var credentials = new EsendexCredentials(sessionId); // Assert Assert.IsFalse(credentials.UseProxy); Assert.AreEqual(sessionId, credentials.SessionId); }
public void DefaultDIConstructor_WithSessionId() { // Arrange Guid sessionId = Guid.NewGuid(); // Act EsendexCredentials credentials = new EsendexCredentials(sessionId); // Assert Assert.IsFalse(credentials.UseProxy); Assert.AreEqual(sessionId, credentials.SessionId); }
public void DefaultDIConstructor_WithSessionIdAndProxy() { // Arrange var sessionId = Guid.NewGuid(); var proxy = new WebProxy(); // Act var credentials = new EsendexCredentials(sessionId, proxy); // Assert Assert.AreEqual(proxy, credentials.WebProxy); Assert.AreEqual(sessionId, credentials.SessionId); }
public void DefaultConstructor() { // Arrange bool ensureMessageIdsInResult = false; EsendexCredentials credentials = new EsendexCredentials("username", "password"); // Act MessagingService serviceInstance = new MessagingService(ensureMessageIdsInResult, credentials); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf<RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf<XmlSerialiser>()); Assert.IsFalse(serviceInstance.EnsureMessageIdsInResult); }
public void DefaultConstructor() { // Arrange bool ensureMessageIdsInResult = false; EsendexCredentials credentials = new EsendexCredentials("username", "password"); // Act MessagingService serviceInstance = new MessagingService(ensureMessageIdsInResult, credentials); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>()); Assert.IsFalse(serviceInstance.EnsureMessageIdsInResult); }
public void DefaultDIConstructor_UsernameAndPasswordAndProxy() { // Arrange string username = "******"; string password = "******"; WebProxy proxy = new WebProxy(); // Act EsendexCredentials credentials = new EsendexCredentials(username, password, proxy); // Assert Assert.AreEqual(username, credentials.Username); Assert.AreEqual(password, credentials.Password); Assert.AreEqual(proxy, credentials.WebProxy); }
public void DefaultDIConstructor_ShouldAcceptDefaultWebProxy() { // Arrange var username = "******"; var password = "******"; var proxy = WebRequest.DefaultWebProxy; // Act var credentials = new EsendexCredentials(username, password, proxy); // Assert Assert.AreEqual(username, credentials.Username); Assert.AreEqual(password, credentials.Password); Assert.AreEqual(proxy, credentials.WebProxy); }
public void DefaultDIConstructor_UsernameAndPasswordAndProxy() { // Arrange var username = "******"; var password = "******"; var proxy = new WebProxy(); // Act var credentials = new EsendexCredentials(username, password, proxy); // Assert Assert.AreEqual(username, credentials.Username); Assert.AreEqual(password, credentials.Password); Assert.AreEqual(proxy, credentials.WebProxy); }
public void DefaultDIConstructor_ShouldAcceptDefaultWebProxy() { // Arrange string username = "******"; string password = "******"; var proxy = WebRequest.DefaultWebProxy; // Act EsendexCredentials credentials = new EsendexCredentials(username, password, proxy); // Assert Assert.AreEqual(username, credentials.Username); Assert.AreEqual(password, credentials.Password); Assert.AreEqual(proxy, credentials.WebProxy); }
private static void AddContactToGroup(EsendexCredentials credentials) { var groupService = new GroupService(credentials); var contactService = new ContactService(credentials); try { var guid = new Guid("{YOUR Contact GUID}"); var contact = contactService.GetContact(guid); groupService.AddContactToGroup(_accountReference, "{YOUR Group GUID}", contact); } catch (WebException ex) { Console.Write(ex.Message); } }
public void DefaultDIConstructor() { // Arrange var uri = new Uri("http://tempuri.org"); var credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); // Act var restClientInstance = new RestClient(httpClient); // Assert Assert.That(restClientInstance.HttpClient, Is.InstanceOf <HttpClient>()); }
public void DefaultDIConstructor() { // Arrange Uri uri = new Uri("http://tempuri.org"); EsendexCredentials credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); // Act RestClient restClientInstance = new RestClient(httpClient); // Assert Assert.That(restClientInstance.HttpClient, Is.InstanceOf<HttpClient>()); }
public void DefaultDIConstructor_WithNullProxy() { // Arrange WebProxy proxy = null; // Act try { var credentails = new EsendexCredentials("username", "password", proxy); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("proxy", ex.ParamName); } }
public void AddCredentials(IHttpWebRequestAdapter httpRequest, EsendexCredentials credentials) { if (credentials.UseSessionAuthentication) { string value = string.Format("Basic {0}", Convert.ToBase64String(new UTF8Encoding().GetBytes(credentials.SessionId.Value.ToString()))); httpRequest.Headers.Add(HttpRequestHeader.Authorization, value); } else { CredentialCache credentialCache = new CredentialCache(); credentialCache.Add(httpRequest.RequestUri, "Basic", new NetworkCredential(credentials.Username, credentials.Password)); httpRequest.Credentials = credentialCache; } }
public void AddCredentials_WithHttpWebRequestAdapterAndBasicEsendexCredentials() { // Arrange EsendexCredentials credentials = new EsendexCredentials("username", "password"); IHttpWebRequestAdapter httpRequest = new HttpWebRequestAdapter(uri); // Act helper.AddCredentials(httpRequest, credentials); // Assert string username = httpRequest.Credentials.GetCredential(uri, "Basic").UserName; string password = httpRequest.Credentials.GetCredential(uri, "Basic").Password; Assert.AreEqual(credentials.Username, username); Assert.AreEqual(credentials.Password, password); }
public void DefaultDIConstructor_WithNullProxy() { // Arrange WebProxy proxy = null; // Act try { EsendexCredentials credentails = new EsendexCredentials("username", "password", proxy); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("proxy", ex.ParamName); } }
public void DefaultDIConstructor_WithEmptyUsernameAndPassword() { // Arrange string username = null; string password = string.Empty; // Act try { EsendexCredentials credentails = new EsendexCredentials(username, password); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("username", ex.ParamName); } }
public void DefaultDIConstructor_WithEmptyUsernameAndPassword() { // Arrange string username = null; var password = string.Empty; // Act try { var credentails = new EsendexCredentials(username, password); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("username", ex.ParamName); } }
public void AddCredentials_WithHttpWebRequestAdapterAndSessionEsendexCredentials() { // Arrange var sessionId = Guid.NewGuid(); var expectedHeaderValue = string.Format("Basic {0}", Convert.ToBase64String(new UTF8Encoding().GetBytes(sessionId.ToString()))); var credentials = new EsendexCredentials(sessionId); IHttpWebRequestAdapter httpRequest = new HttpWebRequestAdapter(_uri); // Act _helper.AddCredentials(httpRequest, credentials); // Assert var actualHeaderValue = httpRequest.Headers.Get("Authorization"); Assert.AreEqual(expectedHeaderValue, actualHeaderValue); }
public void DefaultDIConstructor() { // Arrange EsendexCredentials credentials = new EsendexCredentials("username", "password"); Uri uri = new Uri("http://tempuri.org"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); // Act HttpClient clientInstance = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); // Assert Assert.That(clientInstance.Credentials, Is.InstanceOf <EsendexCredentials>()); Assert.That(clientInstance.HttpRequestHelper, Is.InstanceOf <HttpRequestHelper>()); Assert.That(clientInstance.HttpResponseHelper, Is.InstanceOf <HttpResponseHelper>()); Assert.That(clientInstance.Uri, Is.InstanceOf <Uri>()); }
public void DefaultDIConstructor() { // Arrange var credentials = new EsendexCredentials("username", "password"); var uri = new Uri("http://tempuri.org"); var httpRequestHelper = new HttpRequestHelper(); var httpResponseHelper = new HttpResponseHelper(); // Act var clientInstance = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); // Assert Assert.That(clientInstance.Credentials, Is.InstanceOf<EsendexCredentials>()); Assert.That(clientInstance.HttpRequestHelper, Is.InstanceOf<HttpRequestHelper>()); Assert.That(clientInstance.HttpResponseHelper, Is.InstanceOf<HttpResponseHelper>()); Assert.That(clientInstance.Uri, Is.InstanceOf<Uri>()); }
private static void GetGroupsExample(EsendexCredentials credentials) { var groupService = new GroupService(credentials); try { var collection = groupService.GetGroups(_accountReference, PageIndex, PageSize); foreach (var item in collection.Groups) { Console.WriteLine("\tGroup Id:{0}\tName:{1}", item.Id, item.Name); } } catch (WebException ex) { Console.Write(ex.Message); } }
private static void GetContactsExample(EsendexCredentials credentials) { var contactService = new ContactService(credentials); try { var collection = contactService.GetContacts(_accountReference, PageIndex, PageSize); foreach (var item in collection.Contacts) { Console.WriteLine("\tContact Id:{0}\tQuickname:{1}", item.Id, item.QuickName); } } catch (WebException ex) { Console.Write(ex.Message); } }
public void DefaultDIConstructor() { // Arrange Uri uri = new Uri("http://tempuri.org"); EsendexCredentials credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); IRestClient restClient = new RestClient(httpClient); ISerialiser serialiser = new XmlSerialiser(); // Act InboxService serviceInstance = new InboxService(restClient, serialiser); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>()); }
public void DefaultDIConstructor() { // Arrange Uri uri = new Uri("http://tempuri.org"); EsendexCredentials credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); IRestClient restClient = new RestClient(httpClient); ISerialiser serialiser = new XmlSerialiser(); // Act SessionService serviceInstance = new SessionService(restClient, serialiser); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf<RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf<XmlSerialiser>()); }
public void DefaultDIConstructor() { // Arrange var uri = new Uri("http://tempuri.org"); var credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); IRestClient restClient = new RestClient(httpClient); ISerialiser serialiser = new XmlSerialiser(); // Act var serviceInstance = new MessagingService(restClient, serialiser, true); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>()); Assert.IsTrue(serviceInstance.EnsureMessageIdsInResult); }
public void DefaultDIConstructor() { // Arrange var uri = new Uri("http://tempuri.org"); var credentials = new EsendexCredentials("username", "password"); IHttpRequestHelper httpRequestHelper = new HttpRequestHelper(); IHttpResponseHelper httpResponseHelper = new HttpResponseHelper(); IHttpClient httpClient = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper); IRestClient restClient = new RestClient(httpClient); ISerialiser serialiser = new XmlSerialiser(); // Act var serviceInstance = new MessagingService(restClient, serialiser, true); // Assert Assert.That(serviceInstance.RestClient, Is.InstanceOf<RestClient>()); Assert.That(serviceInstance.Serialiser, Is.InstanceOf<XmlSerialiser>()); Assert.IsTrue(serviceInstance.EnsureMessageIdsInResult); }
private static void SendMessageExample(EsendexCredentials credentials) { var message = new SmsMessage(_sendTo, "This is a test message from the .Net SDK...", _accountReference); var messagingService = new MessagingService(true, credentials); try { var messageResult = messagingService.SendMessage(message); Console.WriteLine("\tMessage Batch Id: {0}", messageResult.BatchId); foreach (var messageId in messageResult.MessageIds) { Console.WriteLine("\t\tMessage Uri: {0}", messageId.Uri); } } catch (WebException ex) { Console.Write(ex.Message); } }
public static Dictionary <object, object> Send(Dictionary <object, object> requestParams) { // TODO: get credentials from config settings EsendexCredentials credentials = new EsendexCredentials("*****@*****.**", "XAvHA7Tdf433"); // TODO: get accountReference EX0111208 from config settings SmsMessage message = new SmsMessage((string)requestParams["Phone"], (string)requestParams["Text"], "EX0111208"); MessagingService messagingService = new MessagingService(true, credentials); try { MessagingResult result = messagingService.SendMessage(message); /*Console.WriteLine("Sent Message Batch Id: {0}", result.BatchId); * * foreach (ResourceLink messageId in result.MessageIds) * { * Console.WriteLine("Message Uri: {0}", messageId.Uri); * }*/ return(new Dictionary <object, object>() { { "RESULT", ESMSGatewayResult.OK }, { "ERROR", string.Empty }, { "ERRORMESSAGE", string.Empty } }); } catch (WebException ex) { return(new Dictionary <object, object>() { { "RESULT", ESMSGatewayResult.ERROR }, { "ERROR", "ERROR" }, { "ERRORMESSAGE", ex.Message } }); } }
internal SurveysService(string baseUrl, EsendexCredentials credentials) { _baseUrl = new Uri(baseUrl); _credentials = credentials; }
internal OptOutsService(string url, EsendexCredentials esendexCredentials) { _baseUrl = new Uri(url); _credentials = esendexCredentials; }
/// <summary> /// Initialises a new instance of the InboxService /// </summary> /// <param name="credentials">A com.esendex.sdk.EsendexCredentials instance containing your username and password.</param> public OptOutsService(EsendexCredentials credentials) : this(BASE_URL, credentials) { }
/// <summary> /// Initialises a new instance of the InboxService /// </summary> /// <param name="credentials">A com.esendex.sdk.EsendexCredentials instance that contains access credentials.</param> public InboxService(EsendexCredentials credentials) : base(credentials) { }
/// <summary> /// Initialises a new instance of the com.esendex.sdk.contacts.ContactService /// </summary> /// <param name="credentials">A com.esendex.sdk.EsendexCredentials instance that contains access credentials.</param> public ContactService(EsendexCredentials credentials) : base(credentials) { }
/// <summary> /// Initialises a new instance of the com.esendex.sdk.session.SessionService /// </summary> public SessionService(EsendexCredentials credentials) : base(credentials) { }
static void Main(string[] args) { var helpRequested = false; var sendMessage = false; var optionSet = new OptionSet { {"u|user="******"Username to use", user => _username = user}, {"p|pass="******"Password for Username", pass => _password = pass}, {"a|account=", "Account Reference to use", reference => _accountReference = reference}, { "s|send=", "Send a message to the provided number", sendTo => { sendMessage = true; _sendTo = sendTo; } }, {"b|bodies+", "Retrieve message bodies", v => _getBodies = true}, { "h|help", "Help about the command line interface", key => { helpRequested = key != null; } } }; try { optionSet.Parse(args); if (!helpRequested && (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(_accountReference))) throw new ApplicationException("Samples require username, password and account reference be given"); } catch (Exception e) { Console.WriteLine(e.Message); helpRequested = true; } if (helpRequested) { ShowUsage(optionSet); return; } EsendexCredentials credentials; try { credentials = new EsendexCredentials(_username, _password); var sessionService = new SessionService(credentials); credentials.SessionId = sessionService.CreateSession(); } catch (WebException ex) { Console.Write(ex.Message); return; } if (sendMessage) { Console.WriteLine("Send Message Example\r\n"); SendMessageExample(credentials); } MessageBodyService messageBodyService = null; if (_getBodies) { messageBodyService = new MessageBodyService(credentials); } Console.WriteLine(); Console.WriteLine("Sent Messages Example\r\n"); GetSentMessagesExample(credentials, messageBodyService); Console.WriteLine(); Console.WriteLine("Inbox Messages Example\r\n"); GetInboxMessagesExample(credentials, messageBodyService); Console.WriteLine(); Console.WriteLine("Contacts Example\r\n"); GetContactsExample(credentials); Console.WriteLine(); Console.WriteLine("Press enter to continue ... "); Console.ReadLine(); }
public SurveysService(EsendexCredentials credentials) : this(SURVEYS_BASE_URL, credentials) { }
/// <summary> /// Initialises a new instance of the com.esendex.sdk.groups.GroupService /// </summary> /// <param name="credentials">A com.esendex.sdk.EsendexCredentials instance that contains access credentials.</param> public GroupService(EsendexCredentials credentials) : base(credentials) { }
static void Main(string[] args) { var helpRequested = false; var sendMessage = false; var optionSet = new OptionSet { { "u|user="******"Username to use", user => _username = user }, { "p|pass="******"Password for Username", pass => _password = pass }, { "a|account=", "Account Reference to use", reference => _accountReference = reference }, { "s|send=", "Send a message to the provided number", sendTo => { sendMessage = true; _sendTo = sendTo; } }, { "b|bodies+", "Retrieve message bodies", v => _getBodies = true }, { "h|help", "Help about the command line interface", key => { helpRequested = key != null; } } }; try { optionSet.Parse(args); if (!helpRequested && (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(_accountReference))) { throw new ApplicationException("Samples require username, password and account reference be given"); } } catch (Exception e) { Console.WriteLine(e.Message); helpRequested = true; } if (helpRequested) { ShowUsage(optionSet); return; } EsendexCredentials credentials; try { credentials = new EsendexCredentials(_username, _password); var sessionService = new SessionService(credentials); credentials.SessionId = sessionService.CreateSession(); } catch (WebException ex) { Console.Write(ex.Message); return; } if (sendMessage) { Console.WriteLine("Send Message Example\r\n"); SendMessageExample(credentials); } MessageBodyService messageBodyService = null; if (_getBodies) { messageBodyService = new MessageBodyService(credentials); } Console.WriteLine(); Console.WriteLine("Sent Messages Example\r\n"); GetSentMessagesExample(credentials, messageBodyService); Console.WriteLine(); Console.WriteLine("Inbox Messages Example\r\n"); GetInboxMessagesExample(credentials, messageBodyService); Console.WriteLine(); Console.WriteLine("Contacts Example\r\n"); GetContactsExample(credentials); Console.WriteLine(); Console.WriteLine("Groups Example\r\n"); GetGroupsExample(credentials); Console.WriteLine(); Console.WriteLine("Contacts in Group Example\r\n"); GetContactsByGroupExample(credentials); AddContactToGroup(credentials); Console.WriteLine(); Console.WriteLine("Press enter to continue ... "); Console.ReadLine(); }
public MessageBodyService(EsendexCredentials credentials) : base(credentials) { }