-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
b573fb8
9836136
6096d37
ec01517
91abb7d
2ddde03
eb0b4a1
859a8b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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) | ||
|
@@ -223,5 +230,74 @@ 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(); | ||
|
||
var groupId = ""; | ||
|
||
foreach (var item in collection.Groups.Where(item => item.Name == "Test group")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the group name is unique you can use FirstOrDefault with null check to verify if a group has been found.
|
||
{ | ||
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 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); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,5 @@ 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"; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs re-instating along with the file includes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
|
||
[assembly: AssemblyVersion("2.2.0")] | ||
[assembly: AssemblyFileVersion("2.2.0")] | ||
[assembly: AssemblyVersion("2.0.1")] | ||
[assembly: AssemblyFileVersion("2.0.1")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We follow SEMVER so this will be 2.3.0 as it's a non-breaking feature enhancement |
||
[assembly: InternalsVisibleTo("com.esendex.sdk.test")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Xml.Serialization; | ||
|
||
namespace com.esendex.sdk.groups | ||
{ | ||
/// <summary> | ||
/// Represents a contact. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be amended to groups. |
||
/// </summary> | ||
[Serializable] | ||
[XmlRoot("contactgroup", Namespace = Constants.API_NAMESPACE)] | ||
public class Group | ||
{ | ||
/// <summary> | ||
/// Initialises a new instance of the com.esendex.sdk.groups.group | ||
/// </summary> | ||
/// <param name="name">A System.String instance that contains the quick name.</param> | ||
/// <exception cref="System.ArgumentNullException"></exception> | ||
public Group(string accountReference, string name) | ||
: this() | ||
{ | ||
if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); | ||
|
||
AccountReference = accountReference; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Initialises a new instance of the com.esendex.sdk.groups.group | ||
/// </summary> | ||
public Group() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a the Id. | ||
/// </summary> | ||
[XmlAttribute("id")] | ||
public Guid Id { get; set; } | ||
|
||
public bool ShouldSerializeId() | ||
{ | ||
return Id != Guid.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the name. | ||
/// </summary> | ||
[XmlElement("name")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the account reference. | ||
/// </summary> | ||
[XmlElement("accountreference")] | ||
public string AccountReference { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != GetType()) return false; | ||
return Equals((Group) obj); | ||
} | ||
|
||
protected bool Equals(Group other) | ||
{ | ||
return Id.Equals(other.Id) | ||
&& string.Equals(Name, other.Name) | ||
&& string.Equals(AccountReference, other.AccountReference); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = Id.GetHashCode(); | ||
hashCode = (hashCode*397) ^ (Name != null ? Name.GetHashCode() : 0); | ||
hashCode = (hashCode*397) ^ (AccountReference != null ? AccountReference.GetHashCode() : 0); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.