From b573fb82494ac1a7fd883e06702147fc02edddd2 Mon Sep 17 00:00:00 2001 From: John Doyle Date: Tue, 16 Feb 2016 08:22:09 +0000 Subject: [PATCH 1/6] Added Groups functionality. Add/Delete Groups. Get Contacts from within a certain group. Add a contact to a group --- samples/Program.cs | 90 ++++++++++++- source/Constants.cs | 2 - source/EsendexCredentials.cs | 6 - source/Properties/AssemblyInfo.cs | 4 +- source/com.esendex.sdk.csproj | 28 +--- source/contacts/ContactCollection.cs | 17 +++ source/groups/Group.cs | 83 ++++++++++++ source/groups/GroupCollection.cs | 79 +++++++++++ source/groups/GroupResponse.cs | 11 ++ source/groups/GroupService.cs | 153 ++++++++++++++++++++++ source/groups/IGroupService.cs | 54 ++++++++ source/groups/PagedGroupCollection.cs | 30 +++++ source/rest/resources/ContactsResource.cs | 16 +++ source/rest/resources/GroupsResource.cs | 64 +++++++++ source/sent/SentMessage.cs | 6 - test/com.esendex.sdk.test.csproj | 13 -- test/packages.config | 9 +- test/sent/SentServiceTests.cs | 81 ------------ 18 files changed, 603 insertions(+), 143 deletions(-) create mode 100644 source/groups/Group.cs create mode 100644 source/groups/GroupCollection.cs create mode 100644 source/groups/GroupResponse.cs create mode 100644 source/groups/GroupService.cs create mode 100644 source/groups/IGroupService.cs create mode 100644 source/groups/PagedGroupCollection.cs create mode 100644 source/rest/resources/GroupsResource.cs diff --git a/samples/Program.cs b/samples/Program.cs index 3a1f457..9afb15d 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,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")) + { + 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("6c5e0669-af2e-4682-85c1-bd97a45c590d"); + var contact = contactService.GetContact(guid); + groupService.AddContactToGroup(_accountReference, "1c259623-00bf-4629-af38-b1f770b12634", 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..5f633a4 100644 --- a/source/Constants.cs +++ b/source/Constants.cs @@ -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"; } } \ No newline at end of file diff --git a/source/EsendexCredentials.cs b/source/EsendexCredentials.cs index c4bb109..e56c2ae 100644 --- a/source/EsendexCredentials.cs +++ b/source/EsendexCredentials.cs @@ -1,6 +1,5 @@ using System; using System.Net; -using System.Text; namespace com.esendex.sdk { @@ -105,10 +104,5 @@ private void SetProxy(IWebProxy 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 e542875..b70e176 100644 --- a/source/Properties/AssemblyInfo.cs +++ b/source/Properties/AssemblyInfo.cs @@ -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")] [assembly: InternalsVisibleTo("com.esendex.sdk.test")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/source/com.esendex.sdk.csproj b/source/com.esendex.sdk.csproj index 76bc6fc..86e8dc5 100644 --- a/source/com.esendex.sdk.csproj +++ b/source/com.esendex.sdk.csproj @@ -25,8 +25,6 @@ 3.5 - ..\ - true true @@ -48,9 +46,6 @@ bin\Release\com.esendex.sdk.XML - - ..\packages\Newtonsoft.Json.8.0.2\lib\net35\Newtonsoft.Json.dll - 3.5 @@ -67,8 +62,12 @@ - - + + + + + + @@ -97,10 +96,8 @@ - - - + @@ -109,9 +106,6 @@ - - - @@ -125,7 +119,6 @@ - @@ -136,12 +129,6 @@ - - - - - -