diff --git a/samples/Program.cs b/samples/Program.cs index 3a1f457..78739c2 100644 --- a/samples/Program.cs +++ b/samples/Program.cs @@ -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,6 +101,16 @@ 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(); @@ -106,16 +118,11 @@ static void Main(string[] args) 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,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(); + + 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); + } + } } } \ No newline at end of file diff --git a/source/Constants.cs b/source/Constants.cs index 1640987..17196e8 100644 --- a/source/Constants.cs +++ b/source/Constants.cs @@ -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"; + } } \ No newline at end of file diff --git a/source/EsendexCredentials.cs b/source/EsendexCredentials.cs index c4bb109..cfb1294 100644 --- a/source/EsendexCredentials.cs +++ b/source/EsendexCredentials.cs @@ -1,114 +1,114 @@ -using System; -using System.Net; -using System.Text; - -namespace com.esendex.sdk -{ - /// - /// Represents authentication details required to access Esendex services. - /// - [Serializable] - public class EsendexCredentials - { - internal EsendexCredentials() - { - } - - /// - /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials - /// - /// Your Esendex username. - /// Your Esendex password. - /// - 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; - } - - /// - /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials - /// - /// A System.Guid instance containing the session id. - public EsendexCredentials(Guid sessionId) - { - SessionId = sessionId; - } - - /// - /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials - /// - /// A System.Guid instance containing the session id. - /// A System.Net.WebProxy instance that contains proxy information required by the local network. - /// - public EsendexCredentials(Guid sessionId, IWebProxy proxy) - : this(sessionId) - { - SetProxy(proxy); - } - - /// - /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials - /// - /// A System.String instance that contains the Esendex username. - /// A System.String instance that contains the Esendex password. - /// A System.Net.WebProxy instance that contains proxy information required by the local network. - /// - public EsendexCredentials(string username, string password, IWebProxy proxy) - : this(username, password) - { - SetProxy(proxy); - } - - /// - /// Gets the Esendex username. - /// - public string Username { get; private set; } - - /// - /// Gets the Esendex password. - /// - public string Password { get; private set; } - - /// - /// Gets the proxy information. - /// - public IWebProxy WebProxy { get; private set; } - - /// - /// Returns true if a System.Net.WebProxy instance was supplied to the constructor; otherwise, false. - /// - public bool UseProxy - { - get { return WebProxy != null; } - } - - /// - /// Returns true if a System.Guid instance was supplied to the constructor; otherwise, false. - /// - public bool UseSessionAuthentication - { - get { return SessionId.HasValue; } - } - - /// - /// Gets or sets a System.Guid instance containing the session id. - /// - 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 +{ + /// + /// Represents authentication details required to access Esendex services. + /// + [Serializable] + public class EsendexCredentials + { + internal EsendexCredentials() + { + } + + /// + /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials + /// + /// Your Esendex username. + /// Your Esendex password. + /// + 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; + } + + /// + /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials + /// + /// A System.Guid instance containing the session id. + public EsendexCredentials(Guid sessionId) + { + SessionId = sessionId; + } + + /// + /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials + /// + /// A System.Guid instance containing the session id. + /// A System.Net.WebProxy instance that contains proxy information required by the local network. + /// + public EsendexCredentials(Guid sessionId, IWebProxy proxy) + : this(sessionId) + { + SetProxy(proxy); + } + + /// + /// Initialises a new instance of the com.esendex.sdk.EsendexCredentials + /// + /// A System.String instance that contains the Esendex username. + /// A System.String instance that contains the Esendex password. + /// A System.Net.WebProxy instance that contains proxy information required by the local network. + /// + public EsendexCredentials(string username, string password, IWebProxy proxy) + : this(username, password) + { + SetProxy(proxy); + } + + /// + /// Gets the Esendex username. + /// + public string Username { get; private set; } + + /// + /// Gets the Esendex password. + /// + public string Password { get; private set; } + + /// + /// Gets the proxy information. + /// + public IWebProxy WebProxy { get; private set; } + + /// + /// Returns true if a System.Net.WebProxy instance was supplied to the constructor; otherwise, false. + /// + public bool UseProxy + { + get { return WebProxy != null; } + } + + /// + /// Returns true if a System.Guid instance was supplied to the constructor; otherwise, false. + /// + public bool UseSessionAuthentication + { + get { return SessionId.HasValue; } + } + + /// + /// Gets or sets a System.Guid instance containing the session id. + /// + 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)); + } + } } \ No newline at end of file diff --git a/source/Properties/AssemblyInfo.cs b/source/Properties/AssemblyInfo.cs index efb8ba2..4065b3b 100644 --- a/source/Properties/AssemblyInfo.cs +++ b/source/Properties/AssemblyInfo.cs @@ -34,5 +34,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.0")] -[assembly: AssemblyFileVersion("3.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.1")] +[assembly: AssemblyFileVersion("3.0.1")] + diff --git a/source/com.esendex.sdk.csproj b/source/com.esendex.sdk.csproj index dddfad4..8941440 100644 --- a/source/com.esendex.sdk.csproj +++ b/source/com.esendex.sdk.csproj @@ -78,6 +78,12 @@ + + + + + + @@ -118,12 +124,13 @@ + - - - + + + @@ -135,10 +142,10 @@ - - - - + + + + @@ -156,8 +163,8 @@ - - + + diff --git a/source/contacts/ContactCollection.cs b/source/contacts/ContactCollection.cs index e360e97..7983d12 100644 --- a/source/contacts/ContactCollection.cs +++ b/source/contacts/ContactCollection.cs @@ -30,6 +30,17 @@ public ContactCollection(Contact contact) Items.Add(contact); } + /// + /// Initialises a new instance of the com.esendex.sdk.contacts.ContactCollection + /// + /// A com.esendex.sdk.contacts.Contact.Id instance that contains a contacts guid. + public ContactCollection(string id) + { + if (id == null) throw new ArgumentNullException("contact"); + + ItemsId.Add(id); + } + /// /// Initialises a new instance of the com.esendex.sdk.contacts.ContactCollection /// @@ -46,6 +57,12 @@ public ContactCollection(IEnumerable contacts) /// [XmlElement("contact")] public List Items = new List(); + /// + /// instance that contains the contacts guid.]]> + /// + [XmlElement("contactid")] + public List ItemsId = new List(); + /// /// Determines whether the specified System.Object are considered equal. /// diff --git a/source/groups/Group.cs b/source/groups/Group.cs new file mode 100644 index 0000000..89084dc --- /dev/null +++ b/source/groups/Group.cs @@ -0,0 +1,83 @@ +using System; +using System.Xml.Serialization; + +namespace com.esendex.sdk.groups +{ + /// + /// Represents a contact. + /// + [Serializable] + [XmlRoot("contactgroup", Namespace = Constants.API_NAMESPACE)] + public class Group + { + /// + /// Initialises a new instance of the com.esendex.sdk.groups.group + /// + /// A System.String instance that contains the quick name. + /// + public Group(string accountReference, string name) + : this() + { + if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); + + AccountReference = accountReference; + Name = name; + } + + /// + /// Initialises a new instance of the com.esendex.sdk.groups.group + /// + public Group() + { + } + + /// + /// Gets or sets a the Id. + /// + [XmlAttribute("id")] + public Guid Id { get; set; } + + public bool ShouldSerializeId() + { + return Id != Guid.Empty; + } + + /// + /// Gets or sets the name. + /// + [XmlElement("name")] + public string Name { get; set; } + + /// + /// Gets or sets the account reference. + /// + [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; + } + } + } +} \ No newline at end of file diff --git a/source/groups/GroupCollection.cs b/source/groups/GroupCollection.cs new file mode 100644 index 0000000..46221c8 --- /dev/null +++ b/source/groups/GroupCollection.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Serialization; + +namespace com.esendex.sdk.groups +{ + /// + /// Represents a collecion of groups. + /// + [Serializable] + [XmlRoot("contactgroups", Namespace = Constants.API_NAMESPACE)] + public class GroupCollection + { + /// + /// Initialises a new instance of the com.esendex.sdk.groups.GroupCollection + /// + public GroupCollection() + { + } + + /// + /// Initialises a new instance of the com.esendex.sdk.groups.GroupCollection + /// + /// A com.esendex.sdk.groups.Group instance that contains a contact. + public GroupCollection(Group group) + { + if (group == null) throw new ArgumentNullException("contactgroup"); + + Items.Add(group); + } + + /// + /// Initialises a new instance of the com.esendex.sdk.groups.GroupCollection + /// + /// instance that contains the groups.]]> + public GroupCollection(IEnumerable groups) + { + if (groups == null) throw new ArgumentNullException("contactgroups"); + + Items.AddRange(groups); + } + + /// + /// instance that contains the groups.]]> + /// + [XmlElement("contact")] public List Items = new List(); + + /// + /// Determines whether the specified System.Object are considered equal. + /// + /// The System.Object to compare with the current System.Object + /// true if the specified System.Object is equal to the current System.Object; otherwise, false. + public override bool Equals(object obj) + { + var other = obj as GroupCollection; + + if (other == null) return false; + + if (Items.Count != other.Items.Count) return false; + + for (var i = 0; i < Items.Count; i++) + { + if (Items.ElementAt(i) != other.Items.ElementAt(i)) return false; + } + + return true; + } + + /// + /// Serves as a hash function for a particular type. + /// + /// A hash code for the current System.Object + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/source/groups/GroupResponse.cs b/source/groups/GroupResponse.cs new file mode 100644 index 0000000..de823f4 --- /dev/null +++ b/source/groups/GroupResponse.cs @@ -0,0 +1,11 @@ +using System.Xml.Serialization; + +namespace com.esendex.sdk.groups +{ + [XmlRoot("response", Namespace = Constants.API_NAMESPACE)] + public class GroupResponse + { + [XmlElement("contactgroup")] + public Group Group { get; set; } + } +} \ No newline at end of file diff --git a/source/groups/GroupService.cs b/source/groups/GroupService.cs new file mode 100644 index 0000000..3599752 --- /dev/null +++ b/source/groups/GroupService.cs @@ -0,0 +1,153 @@ +using System; +using com.esendex.sdk.contacts; +using com.esendex.sdk.http; +using com.esendex.sdk.rest; +using com.esendex.sdk.rest.resources; +using com.esendex.sdk.utilities; + +namespace com.esendex.sdk.groups +{ + /// + /// Defines methods to manage groups. + /// + public class GroupService : ServiceBase, IGroupService + { + /// + /// Initialises a new instance of the GroupService + /// + /// Your Esendex username. + /// Your Esendex password. + public GroupService(string username, string password) + : this(new EsendexCredentials(username, password)) + { + } + + /// + /// Initialises a new instance of the com.esendex.sdk.groups.GroupService + /// + /// A com.esendex.sdk.EsendexCredentials instance that contains access credentials. + public GroupService(EsendexCredentials credentials) + : base(credentials) + { + } + + internal GroupService(IRestClient restClient, ISerialiser serialiser) + : base(restClient, serialiser) + { + } + + /// + /// Creates a com.esendex.sdk.groups.Group instance and returns the new com.esendex.sdk.groups.Group instance. + /// + /// A com.esendex.sdk.groups.Group instance that contains the group. + /// A com.esendex.sdk.groups.Group instance that contains the group with an Id assigned. + /// + /// + public Group CreateGroup(Group group) + { + var requestXml = Serialiser.Serialise(group); + + RestResource resource = new GroupsResource(requestXml); + + return MakeRequest(HttpMethod.POST, resource) + .Group; + } + + /// + /// Returns true if the group was successfully deleted; otherwise, false. + /// + /// A System.Guid instance that contains the Id of a group. + /// true, if the group was successfully deleted; otherwise, false. + /// + public bool DeleteGroup(Guid id) + { + RestResource resource = new GroupsResource(id); + + var response = MakeRequest(HttpMethod.DELETE, resource); + + return (response != null); + } + + /// + /// Returns true if the group was successfully updated; otherwise, false. + /// + /// A com.esendex.sdk.groups.Group instance that contains the group. + /// true, if the group was successfully updated; otherwise, false. + /// + /// + public bool UpdateGroup(Group group) + { + var requestXml = Serialiser.Serialise(group); + + RestResource resource = new GroupsResource(group.Id, requestXml); + + var response = MakeRequest(HttpMethod.PUT, resource); + + return (response != null); + } + + /// + /// Gets a com.esendex.sdk.group.Group instance containing a group. + /// + /// A System.Guid instance that contains the Id of a group. + /// A com.esendex.sdk.groups.Group instance that contains the group. + /// + public Group GetGroup(Guid id) + { + RestResource resource = new GroupsResource(id); + + return MakeRequest(HttpMethod.GET, resource); + } + + /// + /// Gets a com.esendex.sdk.group.PagedGroupCollection instance containing groups. + /// + /// The number of the page. + /// The number of items in the page. + /// A com.esendex.sdk.groups.PagedGroupCollection instance that contains the groups. + /// + /// + public PagedGroupCollection GetGroups(string accountReference, int pageNumber, int pageSize) + { + RestResource resource = new GroupsResource(accountReference, pageNumber, pageSize); + + return MakeRequest(HttpMethod.GET, resource); + } + + /// + /// Gets a com.esendex.sdk.group.PagedGroupCollection instance containing groups. + /// + /// The number of the page. + /// The number of the page. + /// The number of items in the page. + /// The number of items in the page. + /// A com.esendex.sdk.groups.PagedGroupCollection instance that contains the groups. + /// + /// + public PagedContactCollection GetContactsFromGroup(string accountReference, string groupId, int pageNumber, int pageSize) + { + RestResource resource = new GroupsResource(accountReference, groupId, pageNumber, pageSize); + + return MakeRequest(HttpMethod.GET, resource); + } + + /// + /// Posts a com.esendex.sdk.contacts.Contact to a com.esendex.sdk.groups.Group. + /// + /// The number of the page. + /// The number of items in the page. + /// + /// A com.esendex.sdk.groups.PagedGroupCollection instance that contains the groups. + /// + /// + public bool AddContactToGroup(string accountReference, string groupId, Contact contact) + { + var contactColletion = new ContactCollection(); + contactColletion.ItemsId.Add(contact.Id.ToString()); + + RestResource resource = new GroupsResource(accountReference, groupId, Serialiser.Serialise(contactColletion)); + var response = MakeRequest(HttpMethod.POST, resource); + return response != null; + } + } +} \ No newline at end of file diff --git a/source/groups/IGroupService.cs b/source/groups/IGroupService.cs new file mode 100644 index 0000000..e9907b8 --- /dev/null +++ b/source/groups/IGroupService.cs @@ -0,0 +1,54 @@ +using System; + +namespace com.esendex.sdk.groups +{ + /// + /// Defines methods to manage contacts. + /// + public interface IGroupService + { + /// + /// Creates a com.esendex.sdk.contacts.Contact instance and returns the new com.esendex.sdk.contacts.Contact instance. + /// + /// A com.esendex.sdk.contacts.Contact instance that contains the contact. + /// A com.esendex.sdk.contacts.Contact instance that contains the contact with an Id assigned. + /// + /// + Group CreateGroup(Group group); + + /// + /// Returns true if the contact was successfully deleted; otherwise, false. + /// + /// A System.Guid instance that contains the Id of a contact. + /// true, if the contact was successfully deleted; otherwise, false. + /// + bool DeleteGroup(Guid id); + + /// + /// Returns true if the contact was successfully updated; otherwise, false. + /// + /// A com.esendex.sdk.contacts.Contact instance that contains the contact. + /// true, if the contact was successfully updated; otherwise, false. + /// + /// + bool UpdateGroup(Group group); + + /// + /// Gets a com.esendex.sdk.contact.Contact instance containing a contact. + /// + /// A System.Guid instance that contains the Id of a contact. + /// A com.esendex.sdk.contacts.Contact instance that contains the contact. + /// + Group GetGroup(Guid id); + + /// + /// Gets a com.esendex.sdk.contact.PagedContactCollection instance containing contacts. + /// + /// The number of the page. + /// The number of items in the page. + /// A com.esendex.sdk.contacts.PagedContactCollection instance that contains the contacts. + /// + /// + PagedGroupCollection GetGroups(string accountReference, int pageNumber, int pageSize); + } +} \ No newline at end of file diff --git a/source/groups/PagedGroupCollection.cs b/source/groups/PagedGroupCollection.cs new file mode 100644 index 0000000..356b335 --- /dev/null +++ b/source/groups/PagedGroupCollection.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Xml.Serialization; +using com.esendex.sdk.core; + +namespace com.esendex.sdk.groups +{ + /// + /// Represents a paged collection of contacts. + /// + [Serializable] + [XmlRoot("contactgroups", Namespace = Constants.API_NAMESPACE)] + public class PagedGroupCollection : PagedCollection + { + public PagedGroupCollection() + { + Items = new List(); + } + + /// + /// instance that contains the groups.]]> + /// + [XmlElement("contactgroup")] + public List Groups + { + get { return Items; } + set { Items = value; } + } + } +} \ No newline at end of file diff --git a/source/messaging/IMessagingService.cs b/source/models/messaging/IMessagingService.cs similarity index 100% rename from source/messaging/IMessagingService.cs rename to source/models/messaging/IMessagingService.cs diff --git a/source/messaging/Message.cs b/source/models/messaging/Message.cs similarity index 100% rename from source/messaging/Message.cs rename to source/models/messaging/Message.cs diff --git a/source/messaging/MessageBodyService.cs b/source/models/messaging/MessageBodyService.cs similarity index 100% rename from source/messaging/MessageBodyService.cs rename to source/models/messaging/MessageBodyService.cs diff --git a/source/messaging/MessageCollection.cs b/source/models/messaging/MessageCollection.cs similarity index 100% rename from source/messaging/MessageCollection.cs rename to source/models/messaging/MessageCollection.cs diff --git a/source/messaging/MessagingResult.cs b/source/models/messaging/MessagingResult.cs similarity index 100% rename from source/messaging/MessagingResult.cs rename to source/models/messaging/MessagingResult.cs diff --git a/source/messaging/MessagingService.cs b/source/models/messaging/MessagingService.cs similarity index 100% rename from source/messaging/MessagingService.cs rename to source/models/messaging/MessagingService.cs diff --git a/source/messaging/SmsMessage.cs b/source/models/messaging/SmsMessage.cs similarity index 100% rename from source/messaging/SmsMessage.cs rename to source/models/messaging/SmsMessage.cs diff --git a/source/messaging/SmsMessageCollection.cs b/source/models/messaging/SmsMessageCollection.cs similarity index 100% rename from source/messaging/SmsMessageCollection.cs rename to source/models/messaging/SmsMessageCollection.cs diff --git a/source/messaging/VoiceMessage.cs b/source/models/messaging/VoiceMessage.cs similarity index 100% rename from source/messaging/VoiceMessage.cs rename to source/models/messaging/VoiceMessage.cs diff --git a/source/messaging/VoiceMessageCollection.cs b/source/models/messaging/VoiceMessageCollection.cs similarity index 100% rename from source/messaging/VoiceMessageCollection.cs rename to source/models/messaging/VoiceMessageCollection.cs diff --git a/source/messaging/VoiceMessageLanguage.cs b/source/models/messaging/VoiceMessageLanguage.cs similarity index 100% rename from source/messaging/VoiceMessageLanguage.cs rename to source/models/messaging/VoiceMessageLanguage.cs diff --git a/source/rest/resources/ContactsResource.cs b/source/rest/resources/ContactsResource.cs index b0029ef..ef826f8 100644 --- a/source/rest/resources/ContactsResource.cs +++ b/source/rest/resources/ContactsResource.cs @@ -40,6 +40,22 @@ public ContactsResource(string accountReference, int pageNumber, int pageSize) ResourcePath += string.Format("?accountReference={0}&startIndex={1}&count={2}", accountReference, startIndex, pageSize); } + public ContactsResource(string accountReference, int pageNumber, int pageSize, string groupName) + { + if (pageNumber < 1) throw new ArgumentException("Page number must be greater than zero.", "pageNumber"); + if (pageSize < 1) throw new ArgumentException("Page size must be greater than zero.", "pageSize"); + + var startIndex = ((--pageNumber) * pageSize); + + ResourcePath += string.Format("?accountReference={0}&startIndex={1}&count={2}", accountReference, startIndex, pageSize); + } + + public ContactsResource(string accountReference, string groupId, string content) + :base(content) + { + ResourcePath += string.Format("/{0}/contacts?accountReference={1}", groupId, accountReference); + } + private void AppendWithId(Guid id) { ResourcePath += string.Format("/{0}", id); diff --git a/source/rest/resources/GroupsResource.cs b/source/rest/resources/GroupsResource.cs new file mode 100644 index 0000000..7d701eb --- /dev/null +++ b/source/rest/resources/GroupsResource.cs @@ -0,0 +1,64 @@ +using System; +using com.esendex.sdk.contacts; + +namespace com.esendex.sdk.rest.resources +{ + internal class GroupsResource : RestResource + { + public override string ResourceName + { + get { return "contactgroups"; } + } + + public override string ResourceVersion + { + get { return "v2.0"; } + } + + public GroupsResource(Guid id) + { + AppendWithId(id); + } + + public GroupsResource(string content) + : base(content) + { + } + + public GroupsResource(Guid id, string content) + : base(content) + { + AppendWithId(id); + } + + public GroupsResource(string accountReference, int pageNumber, int pageSize) + { + if (pageNumber < 1) throw new ArgumentException("Page number must be greater than zero.", "pageNumber"); + if (pageSize < 1) throw new ArgumentException("Page size must be greater than zero.", "pageSize"); + + var startIndex = ((--pageNumber)*pageSize); + + ResourcePath += string.Format("?accountReference={0}&startIndex={1}&count={2}", accountReference, startIndex, pageSize); + } + + public GroupsResource(string accountReference, string groupId, int pageNumber, int pageSize) + { + if (pageNumber < 1) throw new ArgumentException("Page number must be greater than zero.", "pageNumber"); + if (pageSize < 1) throw new ArgumentException("Page size must be greater than zero.", "pageSize"); + var startIndex = ((--pageNumber) * pageSize); + + ResourcePath += string.Format("/{0}/contacts?accountReference={1}&startIndex={2}&count={3}", groupId, accountReference, startIndex, pageSize); + } + + public GroupsResource(string accountReference, string groupId, string content) + :base(content) + { + ResourcePath += string.Format("/{0}/contacts?accountReference={1}", groupId, accountReference); + } + + private void AppendWithId(Guid id) + { + ResourcePath += string.Format("/{0}", id); + } + } +} \ No newline at end of file diff --git a/source/sent/SentMessage.cs b/source/sent/SentMessage.cs index 72ba036..8fa7e72 100644 --- a/source/sent/SentMessage.cs +++ b/source/sent/SentMessage.cs @@ -51,12 +51,6 @@ public bool ShouldSerializeDeliveredAt() [XmlElement("username")] public string Username { get; set; } - /// - /// Gets or sets the FailureReason which contains failure reason information of the message. - /// - [XmlElement("failurereason")] - public FailureReason FailureReason { get; set; } - internal SentMessage() { } diff --git a/test/com.esendex.sdk.test.csproj b/test/com.esendex.sdk.test.csproj index 3e40c5b..fb6a540 100644 --- a/test/com.esendex.sdk.test.csproj +++ b/test/com.esendex.sdk.test.csproj @@ -75,7 +75,7 @@ ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll True - + False ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll diff --git a/test/sent/SentServiceTests.cs b/test/sent/SentServiceTests.cs index 8ca9e15..a4aef54 100644 --- a/test/sent/SentServiceTests.cs +++ b/test/sent/SentServiceTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net; using com.esendex.sdk.http; using com.esendex.sdk.rest; @@ -167,86 +166,6 @@ public void GetMessages_WithPageNumberAndPageSizeAndAccountReference_ReturnsSent // Assert Assert.AreEqual(pageNumber, actualResult.PageNumber); Assert.AreEqual(pageSize, actualResult.PageSize); - } - - [Test] - public void GetMessages_WithFailedMessage_ReturnsSentMessagesWithFailureReason() - { - // Arrange - var pageNumber = 1; - var pageSize = 15; - var accountReference = "accountReference"; - - RestResource resource = new MessageHeadersResource(accountReference, pageNumber, pageSize); - - var response = new RestResponse - { - StatusCode = HttpStatusCode.OK, - Content = "serialisedItem" - }; - - var sentMessage = new SentMessage {FailureReason = new FailureReason {Code = 80, Description = "yolo", PermanentFailure = true}}; - - var expectedResult = new SentMessageCollection - { - PageNumber = pageNumber, - PageSize = pageSize, - Messages = new List {sentMessage} - }; - - mockRestClient - .Setup(rc => rc.Get(resource)) - .Returns(response); - - mockSerialiser - .Setup(s => s.Deserialise(response.Content)) - .Returns(expectedResult); - - // Act - var actualResult = service.GetMessages(accountReference, pageNumber, pageSize); - - // Assert - Assert.AreEqual(pageNumber, actualResult.PageNumber); - Assert.AreEqual(pageSize, actualResult.PageSize); - - Assert.That(actualResult.Messages[0].FailureReason.Code, Is.EqualTo(sentMessage.FailureReason.Code)); - Assert.That(actualResult.Messages[0].FailureReason.Description, Is.EqualTo(sentMessage.FailureReason.Description)); - Assert.That(actualResult.Messages[0].FailureReason.PermanentFailure, Is.EqualTo(sentMessage.FailureReason.PermanentFailure)); - } - - [Test] - public void GetMessage_WithFailedMessage_ReturnsSentMessagesWithFailureReason() - { - - var messageId = Guid.NewGuid(); - - RestResource resource = new MessageHeadersResource(messageId); - - var response = new RestResponse - { - StatusCode = HttpStatusCode.OK, - Content = "serialisedItem" - }; - - var sentMessage = new SentMessage { Id = messageId, FailureReason = new FailureReason { Code = 80, Description = "yolo", PermanentFailure = true } }; - - - mockRestClient - .Setup(rc => rc.Get(resource)) - .Returns(response); - - mockSerialiser - .Setup(s => s.Deserialise(response.Content)) - .Returns(sentMessage); - - - // Act - var result = service.GetMessage(sentMessage.Id); - - // Assert - Assert.That(result.FailureReason.Code, Is.EqualTo(sentMessage.FailureReason.Code)); - Assert.That(result.FailureReason.Description, Is.EqualTo(sentMessage.FailureReason.Description)); - Assert.That(result.FailureReason.PermanentFailure, Is.EqualTo(sentMessage.FailureReason.PermanentFailure)); } } } \ No newline at end of file