Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Groups functionality #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 82 additions & 7 deletions samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Net;
using com.esendex.sdk.contacts;
using com.esendex.sdk.groups;
using com.esendex.sdk.inbox;
using com.esendex.sdk.messaging;
using com.esendex.sdk.sent;
Expand Down Expand Up @@ -99,23 +101,28 @@ static void Main(string[] args)
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();
}

private static void ShowUsage(OptionSet optionSet)
{
Console.WriteLine(
@"
Esendex .Net SDK Samples
");
Console.WriteLine(@"Esendex .Net SDK Samples");

optionSet.WriteOptionDescriptions(Console.Out);

Console.WriteLine(@"
Enjoy...
");
Console.WriteLine(@"Enjoy...");
}

private static void SendMessageExample(EsendexCredentials credentials)
Expand Down Expand Up @@ -223,5 +230,73 @@ private static void GetContactsExample(EsendexCredentials credentials)
Console.Write(ex.Message);
}
}

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 GetContactsByGroupExample(EsendexCredentials credentials)
{
var groupService = new GroupService(credentials);

try
{
var collection = groupService.GetGroups(_accountReference, PageIndex, PageSize);
var contacts = new PagedContactCollection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be inlined with the contact creation.


var groupId = "";

var contactGroup = collection.Groups.FirstOrDefault(item => item.Name == "Test group");

if (contactGroup == null)
return;

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 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);
}
}
}
}
34 changes: 17 additions & 17 deletions source/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;

namespace com.esendex.sdk
{
internal static class Constants
{
internal const string API_NAMESPACE = "http://api.esendex.com/ns/";

internal static Uri api_uri;

internal static Uri API_URI
{
get { return api_uri ?? (api_uri = new UriBuilder("https", "api.esendex.com").Uri); }
}

internal static string JSON_MEDIA_TYPE = "application/json; charset=utf-8";
}
using System;
namespace com.esendex.sdk
{
internal static class Constants
{
internal const string API_NAMESPACE = "http://api.esendex.com/ns/";
internal static Uri api_uri;
internal static Uri API_URI
{
get { return api_uri ?? (api_uri = new UriBuilder("https", "api.esendex.com").Uri); }
}
internal static string JSON_MEDIA_TYPE = "application/json; charset=utf-8";
}
}
226 changes: 113 additions & 113 deletions source/EsendexCredentials.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
using System;
using System.Net;
using System.Text;

namespace com.esendex.sdk
{
/// <summary>
/// Represents authentication details required to access Esendex services.
/// </summary>
[Serializable]
public class EsendexCredentials
{
internal EsendexCredentials()
{
}

/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="username">Your Esendex username.</param>
/// <param name="password">Your Esendex password.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(string username, string password)
{
if (string.IsNullOrEmpty(username)) throw new ArgumentNullException("username");
if (string.IsNullOrEmpty(password)) throw new ArgumentNullException("password");

Username = username;
Password = password;
}

/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="sessionId">A System.Guid instance containing the session id.</param>
public EsendexCredentials(Guid sessionId)
{
SessionId = sessionId;
}

/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="sessionId">A System.Guid instance containing the session id.</param>
/// <param name="proxy">A System.Net.WebProxy instance that contains proxy information required by the local network.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(Guid sessionId, IWebProxy proxy)
: this(sessionId)
{
SetProxy(proxy);
}

/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="username">A System.String instance that contains the Esendex username.</param>
/// <param name="password">A System.String instance that contains the Esendex password.</param>
/// <param name="proxy">A System.Net.WebProxy instance that contains proxy information required by the local network.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(string username, string password, IWebProxy proxy)
: this(username, password)
{
SetProxy(proxy);
}

/// <summary>
/// Gets the Esendex username.
/// </summary>
public string Username { get; private set; }

/// <summary>
/// Gets the Esendex password.
/// </summary>
public string Password { get; private set; }

/// <summary>
/// Gets the proxy information.
/// </summary>
public IWebProxy WebProxy { get; private set; }

/// <summary>
/// Returns true if a System.Net.WebProxy instance was supplied to the constructor; otherwise, false.
/// </summary>
public bool UseProxy
{
get { return WebProxy != null; }
}

/// <summary>
/// Returns true if a System.Guid instance was supplied to the constructor; otherwise, false.
/// </summary>
public bool UseSessionAuthentication
{
get { return SessionId.HasValue; }
}

/// <summary>
/// Gets or sets a System.Guid instance containing the session id.
/// </summary>
public Guid? SessionId { get; set; }

private void SetProxy(IWebProxy proxy)
{
if (proxy == null) throw new ArgumentNullException("proxy");

WebProxy = proxy;
}

internal string EncodedValue()
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(UseSessionAuthentication ? SessionId.Value.ToString() : Username + ":" + Password));
}
}
using System;
using System.Net;
using System.Text;
namespace com.esendex.sdk
{
/// <summary>
/// Represents authentication details required to access Esendex services.
/// </summary>
[Serializable]
public class EsendexCredentials
{
internal EsendexCredentials()
{
}
/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="username">Your Esendex username.</param>
/// <param name="password">Your Esendex password.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(string username, string password)
{
if (string.IsNullOrEmpty(username)) throw new ArgumentNullException("username");
if (string.IsNullOrEmpty(password)) throw new ArgumentNullException("password");
Username = username;
Password = password;
}
/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="sessionId">A System.Guid instance containing the session id.</param>
public EsendexCredentials(Guid sessionId)
{
SessionId = sessionId;
}
/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="sessionId">A System.Guid instance containing the session id.</param>
/// <param name="proxy">A System.Net.WebProxy instance that contains proxy information required by the local network.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(Guid sessionId, IWebProxy proxy)
: this(sessionId)
{
SetProxy(proxy);
}
/// <summary>
/// Initialises a new instance of the com.esendex.sdk.EsendexCredentials
/// </summary>
/// <param name="username">A System.String instance that contains the Esendex username.</param>
/// <param name="password">A System.String instance that contains the Esendex password.</param>
/// <param name="proxy">A System.Net.WebProxy instance that contains proxy information required by the local network.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public EsendexCredentials(string username, string password, IWebProxy proxy)
: this(username, password)
{
SetProxy(proxy);
}
/// <summary>
/// Gets the Esendex username.
/// </summary>
public string Username { get; private set; }
/// <summary>
/// Gets the Esendex password.
/// </summary>
public string Password { get; private set; }
/// <summary>
/// Gets the proxy information.
/// </summary>
public IWebProxy WebProxy { get; private set; }
/// <summary>
/// Returns true if a System.Net.WebProxy instance was supplied to the constructor; otherwise, false.
/// </summary>
public bool UseProxy
{
get { return WebProxy != null; }
}
/// <summary>
/// Returns true if a System.Guid instance was supplied to the constructor; otherwise, false.
/// </summary>
public bool UseSessionAuthentication
{
get { return SessionId.HasValue; }
}
/// <summary>
/// Gets or sets a System.Guid instance containing the session id.
/// </summary>
public Guid? SessionId { get; set; }
private void SetProxy(IWebProxy proxy)
{
if (proxy == null) throw new ArgumentNullException("proxy");
WebProxy = proxy;
}
internal string EncodedValue()
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(UseSessionAuthentication ? SessionId.Value.ToString() : Username + ":" + Password));
}
}
}
5 changes: 3 additions & 2 deletions source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("3.0.0")]
[assembly: AssemblyFileVersion("3.0.0")]
[assembly: AssemblyVersion("3.0.1")]
[assembly: AssemblyFileVersion("3.0.1")]

Loading