From 3b7ab3f75dc69d96ad5f0d0d4e8eb50e25bfbb77 Mon Sep 17 00:00:00 2001 From: kmossco Date: Mon, 8 Jan 2018 00:12:31 +0000 Subject: [PATCH 1/2] added netstandard support + updated nunit --- README.md | 466 +++++++++++------- .../Intercom.Integration.Tests.csproj | 50 -- .../Intercom.Tests.Integration.csproj | 16 + src/Intercom.Tests.Integration/Test.cs | 0 src/Intercom.Tests.Integration/TestBase.cs | 0 .../packages.config | 4 - src/Intercom.Tests/Clients/AdminClientTest.cs | 6 +- .../Clients/AdminConversationsClientTest.cs | 9 +- .../Clients/CompanyClientTest.cs | 20 +- .../Clients/ContactClientTest.cs | 12 +- .../Clients/ConversationsClientTest.cs | 3 +- .../Clients/EventsClientTest.cs | 9 +- src/Intercom.Tests/Clients/NotesClientTest.cs | 24 +- .../Clients/SegmentsClientTest.cs | 0 src/Intercom.Tests/Clients/TagsClientTest.cs | 12 +- src/Intercom.Tests/Clients/UserClientTest.cs | 12 +- .../Clients/UserConversationsClientTest.cs | 9 +- .../ListJonConverterTest.cs | 6 +- .../MetadataJsonConverterTest.cs | 3 +- .../AppCountJsonConverterTest.cs | 3 +- .../CompanyCountJsonConverterTest.cs | 6 +- ...ConversationAdminCountJsonConverterTest.cs | 6 +- .../ConversationAppCountJsonConverterTest.cs | 6 +- .../UserCountJsonConverterTest.cs | 6 +- src/Intercom.Tests/Core/ClientTest.cs | 0 .../Data/AdminConversationMessageTest.cs | 0 .../Data/AdminConversationReplyTest.cs | 0 src/Intercom.Tests/Data/MetadataTest.cs | 6 +- .../Data/UserConversationMessageTest.cs | 0 .../Data/UserConversationReplyTest.cs | 0 src/Intercom.Tests/Intercom.Tests.csproj | 117 +---- src/Intercom.Tests/TestBase.cs | 0 src/Intercom.Tests/packages.config | 7 - src/Intercom.sln | 35 +- src/Intercom/Clients/VisitorsClient.cs | 1 - src/Intercom/Data/AdminConversationReply.cs | 2 +- src/Intercom/Data/Company.cs | 4 + src/Intercom/Data/Conversation.cs | 5 + src/Intercom/Data/ConversationPart.cs | 6 +- src/Intercom/Data/Customer.cs | 9 + src/Intercom/Data/SocialProfile.cs | 2 +- src/Intercom/Data/UserConversationReply.cs | 4 +- src/Intercom/Data/Visitor.cs | 24 +- src/Intercom/Intercom.csproj | 152 +----- src/Intercom/Properties/AssemblyInfo.cs | 27 - .../{Intercom.nuspec => intercom.nuspec} | 2 +- src/Intercom/packages.config | 5 - 47 files changed, 459 insertions(+), 637 deletions(-) delete mode 100644 src/Intercom.Tests.Integration/Intercom.Integration.Tests.csproj create mode 100644 src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj mode change 100644 => 100755 src/Intercom.Tests.Integration/Test.cs mode change 100644 => 100755 src/Intercom.Tests.Integration/TestBase.cs delete mode 100644 src/Intercom.Tests.Integration/packages.config mode change 100644 => 100755 src/Intercom.Tests/Clients/AdminClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/AdminConversationsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/CompanyClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/ContactClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/ConversationsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/EventsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/NotesClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/SegmentsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/TagsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/UserClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Clients/UserConversationsClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs mode change 100644 => 100755 src/Intercom.Tests/Core/ClientTest.cs mode change 100644 => 100755 src/Intercom.Tests/Data/AdminConversationMessageTest.cs mode change 100644 => 100755 src/Intercom.Tests/Data/AdminConversationReplyTest.cs mode change 100644 => 100755 src/Intercom.Tests/Data/MetadataTest.cs mode change 100644 => 100755 src/Intercom.Tests/Data/UserConversationMessageTest.cs mode change 100644 => 100755 src/Intercom.Tests/Data/UserConversationReplyTest.cs mode change 100644 => 100755 src/Intercom.Tests/TestBase.cs delete mode 100644 src/Intercom.Tests/packages.config create mode 100644 src/Intercom/Data/Customer.cs delete mode 100644 src/Intercom/Properties/AssemblyInfo.cs rename src/Intercom/{Intercom.nuspec => intercom.nuspec} (95%) delete mode 100644 src/Intercom/packages.config diff --git a/README.md b/README.md index c7bf1a7..45dc223 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ - [Resources](#resources) - [Authorization](#authorization) - [Usage](#usage) - - [Idioms](#idioms) - - [Roadmap](#roadmap) + - [Todo](#todo) + - [Pull Requests](#pull-requests) ## Add a dependency @@ -31,7 +31,6 @@ Resources this API supports: - [Notes](#notes) - [Conversations](#conversations) - [Counts](#counts) -- [Webhooks](#webhooks) Each of these resources is represented through the dotnet client by a Class as `ResourceClient`. @@ -40,12 +39,13 @@ Each of these resources is represented through the dotnet client by a Class as ` ## Authorization +> If you already have an access token you can find it [here](https://app.intercom.com/developers/_). If you want to create or learn more about access tokens then you can find more info [here](https://developers.intercom.io/docs/personal-access-tokens). + You can set the `Personal Access Token` via creating an `Authentication` object by invoking the single paramter constructor: ```cs UsersClient usersClient = new UsersClient(new Authentication("MyPersonalAccessToken")); ``` -If you already have an access token you can find it [here](https://app.intercom.com/developers/_). If you want to create or learn more about access tokens then you can find more info [here](https://developers.intercom.io/docs/personal-access-tokens). If you are building a third party application you will need to implement OAuth by following the steps for [setting-up-oauth](https://developers.intercom.io/page/setting-up-oauth) for Intercom. @@ -53,201 +53,350 @@ If you are building a third party application you will need to implement OAuth b ### Users - +**Create UsersClient instance** ```cs -// Create UsersClient instance UsersClient usersClient = new UsersClient(new Authentication("MyPersonalAccessToken")); +``` -// Create a user +**Create user** +```cs User user = usersClient.Create(new User() { user_id = "my_id", name = "first last" }); +``` -// View a user (by id, user_id or email) +**View a user (by id, user_id or email)** +```cs User user = usersClient.View("100300231"); User user = usersClient.View(new User() { email = "example@example.com" }); User user = usersClient.View(new User() { id = "100300231" }); User user = usersClient.View(new User() { user_id = "my_id" }); +``` + +**Update a user with a company** +```cs +User user = usersClient.Update(new User() { + email = "example@example.com", + companies = new List() { + new Company() { company_id = "new_company" } } }); +``` + +**Update user's custom attributes** +```cs +Dictionary customAttributes = new Dictionary(); +customAttributes.Add("total", "100.00"); +customAttributes.Add("account_level", "1"); -// List users and iterating through users, up to 10k records (for all records use the Scroll API) +User user = usersClient.View("100300231"); +user.custom_attributes = customAttributes; + +user = usersClient.Update(user); +``` + +**List users and iterating through them** +
Limited to up to 10k records, if you want to list more records please use the Scroll API + +```cs Users users = usersClient.List(); foreach(User u in users.users) Console.WriteLine(u.email); +``` -// List users via Scroll API +**List users by Tag, Segment, Company** +```cs +Dictionary parameters = new Dictionary(); +parameters.Add("segment_id", "57553e93a32843ca09000277"); +Users users = usersClient.List(parameters); +``` + +**List users via the Scroll API** +```cs Users users = usersClient.Scroll(); String scroll_param_value = users.scroll_param; Users users = usersClient.Scroll(scroll_param_value); +``` -// Update a user with a new company (with user assigned company_id) -User user = usersClient.Update(new User() { - email = "example@example.com", - companies = new List() { - new Company() { company_id = "new_company" } } }); - -// Note that when adding a company plan you need to create it as an object -// (But its only the name of the plan that can be set) -Plan companyPlan = new Plan{ - name = "Stop_Avengers"}; - -User user_test = usersClient.Update(new User() { - email = "abrown@hydra.io", - companies = new List() { - new Company() { company_id = "11", name = "Hydra", plan = companyPlan } }}); - -// Delete a user +**Delete a user** +```cs usersClient.Delete("100300231"); // with intercom generated user's id usersClient.Delete(new User() { email = "example@example.com" }); usersClient.Delete(new User() { user_id = "my_id" }); +``` -// Update User's LastSeenAt (multiple ways for updating) +**Update User's LastSeenAt (multiple ways)** +```cs User user = usersClient.UpdateLastSeenAt("100300231"); User user = usersClient.UpdateLastSeenAt(new User() { id = "100300231" }); User user = usersClient.UpdateLastSeenAt("100300231", 1462110718); User user = usersClient.UpdateLastSeenAt(new User() { id = "100300231" }, 1462110718); +``` -// Update user's custom attributes -Dictionary customAttributes = new Dictionary(); -customAttributes.Add("total", "100.00"); -customAttributes.Add("account_level", "1"); - -User user = usersClient.View("100300231"); -user.custom_attributes = customAttributes; - -user = usersClient.Update(user); - -// Increment User's Session +**Increment User's Session** +```cs usersClient.IncrementUserSession(new User() { id = "100300231" }); +``` -// Removing User's companies +**Removing User's companies** +```cs User user = usersClient.RemoveCompanyFromUser("100300231", new List() { "true_company" }); - ``` +*** + ### Contacts +**Create ContactsClient instance** ```cs -// Create ContactsClient instance ContactsClient contactsClient = new ContactsClient(new Authentication("MyPersonalAccessToken")); +``` -// Create a contact +**Create a contact** +```cs Contact contact = contactsClient.Create(new Contact() { }); Contact contact = contactsClient.Create(new Contact() { name = "lead_name" }); +``` -// View a contact (by id, or user_id) +**View a contact (by id, or user_id)** +```cs Contact contact = contactsClient.View("100300231"); Contact contact = contactsClient.View(new Contact() { id = "100300231" }); Contact contact = contactsClient.View(new Contact() { user_id = "my_lead_id" }); +``` -// Update a contact (by id, or user_id) +**Update a contact (by id, or user_id)** +```cs Contact contact = contactsClient.Update( new Contact() { email = "example@example", companies = new List() { new Company() { company_id = "new_company" } } }); +``` -// List contacts and iterating through contacts up to 10k records (for all records use the Scroll API) +**List contacts and iterate through them** +Limited to up to 10k records, if you want to list more records please use the Scroll API +```cs Contacts contacts = contactsClient.List(); foreach (Contact c in contacts.contacts) Console.WriteLine(c.email); +``` + +**List contacts by email** +```cs +Contacts contacts = contactsClient.List("email@example.com"); +``` -// List contacts via Scroll API +**List contacts via Scroll API** +```cs Contacts contacts = contactsClient.Scroll(); String scroll_param_value = contacts.scroll_param; Contacts contacts = contactsClient.Scroll(scroll_param_value); +``` -// Convert a contact to a User -// Note that if the user does not exist they will be created, otherwise they will be merged. +**Convert a contact to a User** +Note that if the user does not exist they will be created, otherwise they will be merged. +```cs User user = contactsClient.Convert(contact, new User() { user_id = "120" }); +``` -// Delete a contact +**Delete a contact** +```cs contactsClient.Delete("100300231"); contactsClient.Delete(new Contact() { id = "100300231" }); contactsClient.Delete(new Contact() { user_id = "my_id" }); ``` +*** + +### Visitors + +**Create VisitorsClient instance** +```cs +VisitorsClient visitorsClient = new VisitorsClient(new Authentication("MyPersonalAccessToken")); +``` + +**View a visitor** +```cs +Visitor visitor = VisitorsClient.View("573479f784c5acde6a000575"); +``` + +**View a visitor by user_id** +```cs +Dictionary parameters = new Dictionary(); +parameters.Add("user_id", "16e690c0-485a-4e87-ae98-a326e788a4f7"); +Visitor visitor = VisitorsClient.View(parameters); +``` + +**Update a visitor** +```cs +Visitor visitor = VisitorsClient.Update(visitor); +``` + +**Delete a visitor** +```cs +Visitor visitor = VisitorsClient.Delete(visitor); +``` + +**Convert to existing user** +```cs +Visitor visitor = VisitorsClient.ConvertToUser(visitor, user); +``` + +**Convert to new user** +```cs +Visitor visitor = VisitorsClient.ConvertToUser(visitor, new User(){ user_id = "25" }); +``` + +**Convert to contact** +```cs +Visitor visitor = VisitorsClient.ConvertToContact(visitor); +``` + +*** + ### Companies +**Create CompanyClient instance** ```cs -// Create CompanyClient instance CompanyClient companyClient = new CompanyClient(new Authentication("MyPersonalAccessToken")); +``` -// Create a company +**Create a company** +```cs Company company = companyClient.Create(new Company()); Company company = companyClient.Create(new Company() { name = "company_name" }); +``` -// View a company (by id, or user_id) +**View a company** +```cs Company company = companyClient.View("100300231"); Company company = companyClient.View(new Company() { id = "100300231" }); Company company = companyClient.View(new Company() { company_id = "my_company_id" }); Company company = companyClient.View(new Company() { name = "my_company_name" }); +``` -// Update a company (by id, or user_id) +**Update a company** +```cs Company company = companyClient.Update( new Company() { company_id = "example@example", monthly_spend = 100 }); +``` -// List companies and iterating through +**List companies** +
Limited to up to 10k records, if you want to list more records please use the Scroll API +```cs Companies companies = companyClient.List(); +``` -// List companies via Scroll API +**List companies via Scroll API** +```cs Companies companies = companyClient.Scroll(); String scrollParam = companies.scroll_param; Companies companies = companyClient.Scroll(scrollParam); foreach (Company c in companies.companies) Console.WriteLine(c.name); +``` -// List a Company's registered users +**List a Company's registered users** +```cs Users users = companyClient.ListUsers(new Company() { id = "100300231" }); Users users = companyClient.ListUsers(new Company() { company_id = "my_company_id" }); ``` +*** + ### Admins +**Create AdminsClient instance** ```cs -// Create AdminsClient instance AdminsClient adminsClient = new AdminsClient(new Authentication("MyPersonalAccessToken")); +``` -// View an admin (by id) +**View an admin** +```cs Admin admin = adminsClient.View("100300231"); Admin admin = adminsClient.View(new Admin() { id = "100300231" }); +``` -// List admins and iterating through +**List admins** +```cs Admins admins = adminsClient.List(); +``` + +*** + +### Tags + +**Create TagsClient instance** +```cs +TagsClient tagsClient = new TagsClient(new Authentication("MyPersonalAccessToken")); +``` + +**Create a tag** +```cs +Tag tag = tagsClient.Create(new Tag() { name = "new_tag" }); +``` -foreach (Admin admin in admins.admins) - Console.WriteLine(admin.name); +**List tags** +```cs +Tags tags = tagsClient.List(); +``` + +**Delete a tag** +```cs +tagsClient.Delete(new Tag() { id = "100300231" }); +``` + +**Tag User, Company or Contact** +```cs +tagsClient.Tag("new_tag", new List() { new Company(){ company_id = "blue" } }); +tagsClient.Tag("new_tag", new List() { new Company(){ id = "5911bd8bf0c7223d2d1d045d" } }); +tagsClient.Tag("new_tag", new List() { new Contact(){ id = "5911bd8bf0c7446d2d1d045d" } }); +tagsClient.Tag("new_tag", new List() { new User(){ id = "5911bd8bf0c7446d2d1d045d", email = "example@example.com", user_id = "25" } }); ``` +**Untag User, Company or Contact** +```cs +tagsClient.Untag("new_tag", new List() { new Company(){ company_id = "1000_company_id" } }); +tagsClient.Untag("new_tag", new List() { new Contact(){ id = "5911bd8bf0c7223d2d1d045d" } }); +tagsClient.Untag("new_tag", new List() { new User(){ user_id = "1000_user_id" } }); +``` + +*** + ### Segments +**Create SegmentsClient instance** ```cs -// Create SegmentsClient instance SegmentsClient segmentsClient = new SegmentsClient(new Authentication("MyPersonalAccessToken")); +``` -// View a segment (by id) +**View a segment (by id)** +```cs Segment segment = segmentsClient.View("100300231"); Segment segment = segmentsClient.View(new Segment() { id = "100300231" }); +``` -// List segments and iterating through +**List segments** +```cs Segments segments = segmentsClient.List(); - -foreach (Segment segment in segments.segments) - Console.WriteLine(segment.name); ``` +*** + ### Notes +**Create NotesClient instance** ```cs -// Create NotesClient instance NotesClient notesClient = new NotesClient(new Authentication("MyPersonalAccessToken")); +``` -// Create a note (by User, body and admin_id) +**Create a note (by User, body and admin_id)** +```cs Note note = notesClient.Create( new Note() { author = new Author() { id = "100300231_admin_id" }, @@ -256,89 +405,37 @@ Note note = notesClient.Create( }); Note note = notesClient.Create(new User() { email = "example@example.com" }, "this is a new note", "100300231_admin_id"); +``` -// View a note +**View a note** +```cs Note note = notesClient.View("2001"); +``` -// List User's notes +**List User's notes** +```cs Notes notes = notesClient.List(new User() { id = "100300231"}); foreach (Note n in notes.notes) Console.WriteLine(n.user.name); ``` -### Counts - -```cs -// Create CountsClient instance -CountsClient countsClient = new CountsClient(new Authentication("MyPersonalAccessToken")); - -// Get AppCount -AppCount appCount = countsClient.GetAppCount(); - -// Get ConversationAppCount -ConversationAppCount conversationAppCount = countsClient.GetConversationAppCount(); - -// Get ConversationAdminCount -ConversationAdminCount conversationAdminCount = countsClient.GetConversationAdminCount(); - -// Get CompanySegmentCount -CompanySegmentCount companySegmentCount = countsClient.GetCompanySegmentCount(); - -// Get CompanyTagCount -CompanyTagCount companyTagCount = countsClient.GetCompanyTagCount(); - -// Get CompanyUserCount -CompanyUserCount companyUserCount = countsClient.GetCompanyUserCount(); - -// Get UserSegmentCount -UserSegmentCount userSegmentCount = countsClient.GetUserSegmentCount(); - -// Get UserTagCount -UserTagCount userTagCount = countsClient.GetUserTagCount(); -``` - -### Tags - -```cs -// Create TagsClient instance -TagsClient tagsClient = new TagsClient(new Authentication("MyPersonalAccessToken")); - -// Create a tag -Tag tag = tagsClient.Create(new Tag() { name = "new_tag" }); - -// List tags and iterate through -Tags tags = tagsClient.List(); - -foreach(Tag t in tags.tags) - Console.WriteLine(t.name); - -// Delete a tag -tagsClient.Delete(new Tag() { id = "100300231" }); - - -// Tag User, Company or Contact (Lead) -tagsClient.Tag("new_tag", new List() { new Company(){ company_id = "blue" } }); -tagsClient.Tag("new_tag", new List() { new Company(){ id = "5911bd8bf0c7223d2d1d045d" } }); -tagsClient.Tag("new_tag", new List() { new Contact(){ id = "5911bd8bf0c7446d2d1d045d" } }); -tagsClient.Tag("new_tag", new List() { new User(){ id = "5911bd8bf0c7446d2d1d045d", email = "example@example.com", user_id = "25" } }); - -// Untag User, Company or Contact (Lead) -tagsClient.Untag("new_tag", new List() { new Company(){ company_id = "1000_company_id" } }); -tagsClient.Untag("new_tag", new List() { new Contact(){ id = "5911bd8bf0c7223d2d1d045d" } }); -tagsClient.Untag("new_tag", new List() { new User(){ user_id = "1000_user_id" } }); -``` +*** ### Events +**Create EventsClient instance** ```cs -// Create EventsClient instance EventsClient eventsClient = new EventsClient(new Authentication("MyPersonalAccessToken")); +``` -// Create an event +**Create an event** +```cs Event ev = eventsClient.Create(new Event() { user_id = "1000_user_id", email = "user_email@example.com", event_name = "new_event", created_at = 1462110718 }); +``` -// Create an event with Metadata (Simple, MonetaryAmounts and RichLinks) +**Create an event with Metadata (Simple, MonetaryAmounts and RichLinks)** +```cs Metadata metadata = new Metadata(); metadata.Add("simple", 100); metadata.Add("simple_1", "two"); @@ -346,28 +443,60 @@ metadata.Add("money", new Metadata.MonetaryAmount(100, "eur")); metadata.Add("richlink", new Metadata.RichLink("www.example.com", "value1")); Event ev = eventsClient.Create(new Event() { user_id = "1000_user_id", email = "user_email@example.com", event_name = "new_event", created_at = 1462110718, metadata = metadata }); +``` -// List events by user and iterate through +**List events by user** +```cs Events events = eventsClient.List(new User() { user_id = "my_id" }); +``` + +*** + +### Counts + +**Create CountsClient instance** +```cs +CountsClient countsClient = new CountsClient(new Authentication("MyPersonalAccessToken")); +``` + +**Get AppCount** +```cs +AppCount appCount = countsClient.GetAppCount(); +``` -foreach(Event ev in events.event) - Console.WriteLine(ev.event_name); +**Get Specific Counts** +```cs +ConversationAppCount conversationAppCount = countsClient.GetConversationAppCount(); +ConversationAdminCount conversationAdminCount = countsClient.GetConversationAdminCount(); +CompanySegmentCount companySegmentCount = countsClient.GetCompanySegmentCount(); +CompanyTagCount companyTagCount = countsClient.GetCompanyTagCount(); +CompanyUserCount companyUserCount = countsClient.GetCompanyUserCount(); +UserSegmentCount userSegmentCount = countsClient.GetUserSegmentCount(); +UserTagCount userTagCount = countsClient.GetUserTagCount(); ``` +*** + ### Conversations +**Create ConversationsClient instance** ```cs -// Create ConversationsClient instance ConversationsClient conversationsClient = new ConversationsClient(new Authentication("MyPersonalAccessToken")); +``` -// View any type of conversation +**View any type of conversation** +```cs conversationsClient.View("100300231"); conversationsClient.View("100300231", displayAsPlainText: true); +``` -// Create AdminConversationsClient instance +**Create AdminConversationsClient instance** +```cs AdminConversationsClient adminConversationsClient = new AdminConversationsClient(new Authentication("MyPersonalAccessToken")); +``` -// Create Admin initiated Conversation +**Create Admin initiated Conversation** +```cs AdminConversationMessage admin_message = adminConversationsClient.Create(new AdminConversationMessage( from: new AdminConversationMessage.From("1000_admin_id"), @@ -376,9 +505,10 @@ AdminConversationMessage admin_message = template: AdminConversationMessage.MessageTemplate.PERSONAL, subject: "this is a subject", body: "this is an email body")); +``` - -// Create Admin initiated Conversation's reply +**Create Admin initiated Conversation's reply** +```cs AdminConversationReply admin_reply = adminConversationsClient.Reply( new AdminConversationReply( @@ -386,19 +516,24 @@ AdminConversationReply admin_reply = adminId: "1000_admin_id", messageType: AdminConversationReply.ReplyMessageType.COMMENT, body: "this is a reply body")); +``` - -// Create UserConversationsClient instance +**Create UserConversationsClient instance** +```cs UserConversationsClient userConversationsClient = new UserConversationsClient(new Authentication("MyPersonalAccessToken")); +``` -// Create User initiated Conversation +**Create User initiated Conversation** +```cs UserConversationMessage user_message = userConversationsClient.Create( new UserConversationMessage( from: new UserConversationMessage.From(id: "1000_user_id"), body: "this is a user's message body")); +``` -// Create User initiated Conversation's reply +**Create User initiated Conversation's reply** +```cs UserConversationReply user_reply = userConversationsClient.Reply( new UserConversationReply( @@ -407,29 +542,24 @@ UserConversationReply user_reply = attachementUrls: new List() { "www.example.com/example.png", "www.example.com/example.txt" })); ``` -### Webhooks - -Not yet supported by these bindings. +*** -### Bulk APIs +### Webhooks & Pagination Not yet supported by these bindings. -## Idioms - -### Exceptions - -To be written. - -### Pagination +## Todo -To be written. +- [ ] Increase test coverage +- [ ] Support Pagination +- [ ] Support Webhooks +- [ ] Support Async +- [ ] Have 100% feature parity with curl -## Roadmap +## Pull Requests -- Upgrade the bindings to be compatible with .NET Standard 2.0 -- Support Pagination -- Support Bulk Apis -- Support Webhooks -- Support Async -- Increase test coverage +* **Add tests!** Your patch won't be accepted if it doesn't have tests. +* **Document any change in behaviour.** Make sure the README and any other relevant documentation are kept up-to-date. +* **Create topic branches.** Don't ask us to pull from your master branch. +* **One pull request per feature.** If you want to do more than one thing, send multiple pull requests. +* **Send coherent history.** Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before sending them to us.** diff --git a/src/Intercom.Tests.Integration/Intercom.Integration.Tests.csproj b/src/Intercom.Tests.Integration/Intercom.Integration.Tests.csproj deleted file mode 100644 index ae7dad6..0000000 --- a/src/Intercom.Tests.Integration/Intercom.Integration.Tests.csproj +++ /dev/null @@ -1,50 +0,0 @@ - - - - Debug - AnyCPU - {D5BFF82C-AF15-4528-86DA-D83509ABF64B} - Library - Intercom.Integration.Tests - Intercom.Integration.Tests - v4.5 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - - - - - - - - - - - {A2269678-CBCC-4444-AD9D-5D82ABC52800} - Intercom - - - \ No newline at end of file diff --git a/src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj b/src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj new file mode 100644 index 0000000..e602a30 --- /dev/null +++ b/src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp2.0 + 2.0.0 + + + + + + + + + + + diff --git a/src/Intercom.Tests.Integration/Test.cs b/src/Intercom.Tests.Integration/Test.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests.Integration/TestBase.cs b/src/Intercom.Tests.Integration/TestBase.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests.Integration/packages.config b/src/Intercom.Tests.Integration/packages.config deleted file mode 100644 index c714ef3..0000000 --- a/src/Intercom.Tests.Integration/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/AdminClientTest.cs b/src/Intercom.Tests/Clients/AdminClientTest.cs old mode 100644 new mode 100755 index 4176262..6ab397e --- a/src/Intercom.Tests/Clients/AdminClientTest.cs +++ b/src/Intercom.Tests/Clients/AdminClientTest.cs @@ -24,17 +24,15 @@ public AdminClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void View_WithEmptyString_ThrowException() { - adminsClient.View(String.Empty); + Assert.Throws(() => adminsClient.View(String.Empty)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void View_NoId_ThrowException() { - adminsClient.View(new Admin()); + Assert.Throws(() => adminsClient.View(new Admin())); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/AdminConversationsClientTest.cs b/src/Intercom.Tests/Clients/AdminConversationsClientTest.cs old mode 100644 new mode 100755 index 917f995..e68eb4a --- a/src/Intercom.Tests/Clients/AdminConversationsClientTest.cs +++ b/src/Intercom.Tests/Clients/AdminConversationsClientTest.cs @@ -24,24 +24,21 @@ public AdminConversationsClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Reply_WithNull_ThrowException() { - adminConversationsClient.Reply(null); + Assert.Throws(() => adminConversationsClient.Reply(null)); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - adminConversationsClient.Create(null); + Assert.Throws(() => adminConversationsClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void List_NoId_ThrowException() { - adminConversationsClient.List(new Admin()); + Assert.Throws(() => adminConversationsClient.List(new Admin())); } } } diff --git a/src/Intercom.Tests/Clients/CompanyClientTest.cs b/src/Intercom.Tests/Clients/CompanyClientTest.cs old mode 100644 new mode 100755 index fa050e7..24d88a3 --- a/src/Intercom.Tests/Clients/CompanyClientTest.cs +++ b/src/Intercom.Tests/Clients/CompanyClientTest.cs @@ -23,38 +23,40 @@ public CompanyClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - companyClient.Create(null); + Assert.Throws(() => companyClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Delete_MoreThan100CustomAtt_ThrowException() { Dictionary custom_attributes = new Dictionary(); for (int i = 0; i < 105; i++) - custom_attributes.Add("field", "value"); + custom_attributes.Add($"field{i}", "value"); - companyClient.Create(new Company() { custom_attributes = custom_attributes } ); + Assert.Throws(() => + { + companyClient.Create(new Company() { custom_attributes = custom_attributes }); + }); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Create_CustomAttInvalidChars_ThrowException() { Dictionary custom_attributes = new Dictionary(); custom_attributes.Add("invalid.ch$ar", "invalid"); - companyClient.Create(new Company() { custom_attributes = custom_attributes } ); + Assert.Throws(() => + { + companyClient.Create(new Company() { custom_attributes = custom_attributes }); + }); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Update_WithNull_ThrowException() { - companyClient.Update(null); + Assert.Throws(() => companyClient.Update(null)); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/ContactClientTest.cs b/src/Intercom.Tests/Clients/ContactClientTest.cs old mode 100644 new mode 100755 index e39b8de..f8ca856 --- a/src/Intercom.Tests/Clients/ContactClientTest.cs +++ b/src/Intercom.Tests/Clients/ContactClientTest.cs @@ -24,31 +24,27 @@ public ContactClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - contactsClient.Create(null); + Assert.Throws(() => contactsClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Update_NoIdOrUserIdOrEmail_ThrowException() { - contactsClient.Update(new Contact()); + Assert.Throws(() => contactsClient.Update(new Contact())); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void ListByEmail_NoEmail_ThrowException() { - contactsClient.List(String.Empty); + Assert.Throws(() => contactsClient.List(String.Empty)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Delete_NoIdOrUserIdOrEmail_ThrowException() { - contactsClient.Delete(new Contact()); + Assert.Throws(() => contactsClient.Delete(new Contact())); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/ConversationsClientTest.cs b/src/Intercom.Tests/Clients/ConversationsClientTest.cs old mode 100644 new mode 100755 index 0ab3769..c2409a9 --- a/src/Intercom.Tests/Clients/ConversationsClientTest.cs +++ b/src/Intercom.Tests/Clients/ConversationsClientTest.cs @@ -23,10 +23,9 @@ public ConversationsClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void View_WithNull_ThrowException() { - conversationsClient.View(null); + Assert.Throws(() => conversationsClient.View(null)); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/EventsClientTest.cs b/src/Intercom.Tests/Clients/EventsClientTest.cs old mode 100644 new mode 100755 index 4f197d5..23c8f2b --- a/src/Intercom.Tests/Clients/EventsClientTest.cs +++ b/src/Intercom.Tests/Clients/EventsClientTest.cs @@ -23,24 +23,21 @@ public EventsClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - eventsClient.Create(null); + Assert.Throws(() => eventsClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void List_NoIdOrUserIdOrEmail_ThrowException() { - eventsClient.List(new User()); + Assert.Throws(() =>eventsClient.List(new User())); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void ListByParams_NoIdOrUserIdOrEmail_ThrowException() { - eventsClient.List(new Dictionary()); + Assert.Throws(() => eventsClient.List(new Dictionary())); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/NotesClientTest.cs b/src/Intercom.Tests/Clients/NotesClientTest.cs old mode 100644 new mode 100755 index e0357a9..689486c --- a/src/Intercom.Tests/Clients/NotesClientTest.cs +++ b/src/Intercom.Tests/Clients/NotesClientTest.cs @@ -23,45 +23,45 @@ public NotesClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - notesClient.Create(null); + Assert.Throws(() => notesClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void CreateWithNote_NoUserIdOrEmail_ThrowException() { - notesClient.Create(new Note() { user = new User() }); + Assert.Throws(() => notesClient.Create(new Note() { user = new User() })); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void CreateWithNote_NoBody_ThrowException() { - notesClient.Create(new Note() { user = new User() { email = "email@example.com" } }); + Assert.Throws(() => + { + notesClient.Create(new Note() { user = new User() { email = "email@example.com" } }); + }); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Create_NoUserIdOrEmail_ThrowException() { - notesClient.Create(new User(), String.Empty); + Assert.Throws(() => notesClient.Create(new User(), String.Empty)); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_NoBody_ThrowException() { - notesClient.Create(new User() { email = "email@example.com" }, String.Empty); + Assert.Throws(() => + { + notesClient.Create(new User() { email = "email@example.com" }, String.Empty); + }); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void List_NoIdOrUserIdOrEmail_ThrowException() { - notesClient.List(new User()); + Assert.Throws(() => notesClient.List(new User())); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/SegmentsClientTest.cs b/src/Intercom.Tests/Clients/SegmentsClientTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Clients/TagsClientTest.cs b/src/Intercom.Tests/Clients/TagsClientTest.cs old mode 100644 new mode 100755 index 785f79b..ca930b4 --- a/src/Intercom.Tests/Clients/TagsClientTest.cs +++ b/src/Intercom.Tests/Clients/TagsClientTest.cs @@ -23,32 +23,28 @@ public TagsClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - tagsClient.Create(null); + Assert.Throws(() => tagsClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Create_NoIdOrName_ThrowException() { - tagsClient.Create(new Tag()); + Assert.Throws(() => tagsClient.Create(new Tag())); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Delete_WithNull_ThrowException() { Tag tag = null; - tagsClient.Delete(tag); + Assert.Throws(() => tagsClient.Delete(tag)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Delete_NoId_ThrowException() { - tagsClient.Delete(new Tag()); + Assert.Throws(() => tagsClient.Delete(new Tag())); } diff --git a/src/Intercom.Tests/Clients/UserClientTest.cs b/src/Intercom.Tests/Clients/UserClientTest.cs old mode 100644 new mode 100755 index 79c0b2d..3eed4a9 --- a/src/Intercom.Tests/Clients/UserClientTest.cs +++ b/src/Intercom.Tests/Clients/UserClientTest.cs @@ -23,31 +23,27 @@ public UserClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - usersClient.Create(null); + Assert.Throws(() => usersClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Create_NoUserIdOrEmail_ThrowException() { - usersClient.Create(new User()); + Assert.Throws(() => usersClient.Create(new User())); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Delete_NoIdOrUserIdOrEmail_ThrowException() { - usersClient.Delete(new User()); + Assert.Throws(() => usersClient.Delete(new User())); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void Update_NoIdOrUserIdOrEmail_ThrowException() { - usersClient.Update(new User()); + Assert.Throws(() => usersClient.Update(new User())); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Clients/UserConversationsClientTest.cs b/src/Intercom.Tests/Clients/UserConversationsClientTest.cs old mode 100644 new mode 100755 index 87621a0..44650c3 --- a/src/Intercom.Tests/Clients/UserConversationsClientTest.cs +++ b/src/Intercom.Tests/Clients/UserConversationsClientTest.cs @@ -23,24 +23,21 @@ public UserConversationsClientTest() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Reply_WithNull_ThrowException() { - userConversationsClient.Reply(null); + Assert.Throws(() => userConversationsClient.Reply(null)); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void Create_WithNull_ThrowException() { - userConversationsClient.Create(null); + Assert.Throws(() => userConversationsClient.Create(null)); } [Test()] - [ExpectedException(typeof(ArgumentException))] public void List_NoIdOrUserIdOrEmail_ThrowException() { - userConversationsClient.List(new User()); + Assert.Throws(() => userConversationsClient.List(new User())); } } } diff --git a/src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs b/src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs old mode 100644 new mode 100755 index 44f3356..4419b31 --- a/src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs +++ b/src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs @@ -39,24 +39,22 @@ public void ReadJson_ForCompanyList_ReturnsValidCount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidSerializationType_ThrowsException() { String input = "{\"companies\":[{\"type\":\"company\",\"company_id\":\"first_company\",\"id\":\"57100\"},{\"type\":\"company\",\"company_id\":\"second_company\",\"id\":\"5800\"},{\"type\":\"company\",\"company_id\":\"third_company\",\"id\":\"5900\"}]}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - listJsonConverter.ReadJson(reader, typeof(List), null, null); + Assert.Throws(() => listJsonConverter.ReadJson(reader, typeof(List), null, null)); } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"compani\",\"company_id\":\"first_company\",\"id\":\"57100\"},{\"type\":\"company\",\"company_id\":\"second_company\",\"id\":\"5800\"},{\"type\":\"company\",\"company_id\":\"third_company\",\"id\":\"5900\"}]}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - listJsonConverter.ReadJson(reader, typeof(List), null, null); + Assert.Throws(() => listJsonConverter.ReadJson(reader, typeof(List), null, null)); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs b/src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs old mode 100644 new mode 100755 index df526d0..31d9342 --- a/src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs @@ -54,14 +54,13 @@ public void ReadJson_InvalidMonetaryAmount_ReturnsZeroAmount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"complex\"\":\"aed\"},\"article_1\":{\"url\tps://example.org/orders/3434-3434\",\"value\":\"click here!\"}}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - metadataJsonConverter.ReadJson(reader, typeof(Metadata), null, null); + Assert.Throws(() => metadataJsonConverter.ReadJson(reader, typeof(Metadata), null, null)); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs b/src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs old mode 100644 new mode 100755 index 0c67f49..44ec1d7 --- a/src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs @@ -38,14 +38,13 @@ public void ReadJson_ForConversationAppCount_ReturnsValidCount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"type\t\":2025082},\"lead\":{\"count\":{\"count\":17},\"segment\":{\"count\":7}}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - appCountJsonConverter.ReadJson(reader, typeof(int), null, null); + Assert.Throws(() => appCountJsonConverter.ReadJson(reader, typeof(int), null, null)); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs b/src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs old mode 100644 new mode 100755 index 308f409..9cb793e --- a/src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs @@ -69,14 +69,16 @@ public void ReadJson_ForCompanyTagCount_ReturnsValidCompanyTag() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"type\":\"count\",\"company\"tag\":[{\"auto\"cool-users-only\":6},{\"CSV Import - 2016-04-26 12:22:47 UTC\":0}]}}\n"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - companyCountJsonConverter.ReadJson(reader, typeof(CompanyTagCount), null, null); + Assert.Throws(() => + { + companyCountJsonConverter.ReadJson(reader, typeof(CompanyTagCount), null, null); + }); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs b/src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs old mode 100644 new mode 100755 index b90b252..2b0f6a8 --- a/src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs @@ -40,14 +40,16 @@ public void ReadJson_ForConversationAppCount_ReturnsValidCount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"type\":\"count\",\"in\":[{\"name\":\"AAA\",\"id\":\"29\",\"open\":3,\"closed\":11},{\"name\":\"BBB\",\"id\":\"10\",\"open\":2,\"closed\":0},{\"name\":\"CCC\",\"id\":\"15\",\"open\":2,\"closed\":2}]}}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - conversationAdminCountJsonConverter.ReadJson(reader, typeof(ConversationAdminCount), null, null); + Assert.Throws(() => + { + conversationAdminCountJsonConverter.ReadJson(reader, typeof(ConversationAdminCount), null, null); + }); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs b/src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs old mode 100644 new mode 100755 index 92f6cc9..e083733 --- a/src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs @@ -42,14 +42,16 @@ public void ReadJson_ForConversationAppCount_ReturnsValidCount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"type\":\"count\\pen\":24,\"closed\":35,\"unassigned\":11,\"assigned\":13}}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - conversationAppCountJsonConverter.ReadJson(reader, typeof(ConversationAppCount), null, null); + Assert.Throws(() => + { + conversationAppCountJsonConverter.ReadJson(reader, typeof(ConversationAppCount), null, null); + }); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs b/src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs old mode 100644 new mode 100755 index 3427090..3daae74 --- a/src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs +++ b/src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs @@ -54,14 +54,16 @@ public void ReadJson_ForUserTag_ReturnsValidCount() } [Test()] - [ExpectedException(typeof(JsonConverterException))] public void ReadJson_InvalidJson_ThrowsException() { String input = "{\"type\":\"count\",\"usted-tag\":0},{\"has_device_token\":1001},{\"Tag 1\":1},{\"test_user_tagged\":2}]}}"; StringReader stringReader = new StringReader(input); JsonReader reader = new JsonTextReader(stringReader); - userCountJsonConverter.ReadJson(reader, typeof(UserTagCount), null, null); + Assert.Throws(() => + { + userCountJsonConverter.ReadJson(reader, typeof(UserTagCount), null, null); + }); } } } \ No newline at end of file diff --git a/src/Intercom.Tests/Core/ClientTest.cs b/src/Intercom.Tests/Core/ClientTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Data/AdminConversationMessageTest.cs b/src/Intercom.Tests/Data/AdminConversationMessageTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Data/AdminConversationReplyTest.cs b/src/Intercom.Tests/Data/AdminConversationReplyTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Data/MetadataTest.cs b/src/Intercom.Tests/Data/MetadataTest.cs old mode 100644 new mode 100755 index 2026e93..1156bf7 --- a/src/Intercom.Tests/Data/MetadataTest.cs +++ b/src/Intercom.Tests/Data/MetadataTest.cs @@ -45,19 +45,17 @@ public void Add_WithNullKey_ThrowException() } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void GetMonetaryAmount_WithNullKey_ThrowException() { Metadata metadata = new Metadata(); - metadata.GetMonetaryAmount(null); + Assert.Throws(() => metadata.GetMonetaryAmount(null)); } [Test()] - [ExpectedException(typeof(ArgumentNullException))] public void GetRichLink_WithNullKey_ThrowException() { Metadata metadata = new Metadata(); - metadata.GetRichLink(null); + Assert.Throws(() => metadata.GetRichLink(null)); } [Test()] diff --git a/src/Intercom.Tests/Data/UserConversationMessageTest.cs b/src/Intercom.Tests/Data/UserConversationMessageTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Data/UserConversationReplyTest.cs b/src/Intercom.Tests/Data/UserConversationReplyTest.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/Intercom.Tests.csproj b/src/Intercom.Tests/Intercom.Tests.csproj index e8d3e5a..1db607a 100644 --- a/src/Intercom.Tests/Intercom.Tests.csproj +++ b/src/Intercom.Tests/Intercom.Tests.csproj @@ -1,98 +1,19 @@ - - - - Debug - AnyCPU - {CC907EDA-7B33-4E85-8E45-60714B79CACB} - Library - Library.Test - Library.Test - v4.5 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - - - - - - full - true - bin\Release - prompt - 4 - false - - - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - - - - - - ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {A2269678-CBCC-4444-AD9D-5D82ABC52800} - Intercom - - - \ No newline at end of file + + + + netcoreapp2.0 + 2.0.0 + + + + + + + + + + + + + + diff --git a/src/Intercom.Tests/TestBase.cs b/src/Intercom.Tests/TestBase.cs old mode 100644 new mode 100755 diff --git a/src/Intercom.Tests/packages.config b/src/Intercom.Tests/packages.config deleted file mode 100644 index e09b759..0000000 --- a/src/Intercom.Tests/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/Intercom.sln b/src/Intercom.sln index 03aedde..6960bbe 100644 --- a/src/Intercom.sln +++ b/src/Intercom.sln @@ -1,11 +1,11 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom", "Intercom\Intercom.csproj", "{A2269678-CBCC-4444-AD9D-5D82ABC52800}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom", "Intercom\Intercom.csproj", "{0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom.Tests", "Intercom.Tests\Intercom.Tests.csproj", "{CC907EDA-7B33-4E85-8E45-60714B79CACB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom.Tests", "Intercom.Tests\Intercom.Tests.csproj", "{F8E42768-5A4D-4220-BC17-2DCA7CDC689D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom.Integration.Tests", "Intercom.Tests.Integration\Intercom.Integration.Tests.csproj", "{D5BFF82C-AF15-4528-86DA-D83509ABF64B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom.Tests.Integration", "Intercom.Tests.Integration\Intercom.Tests.Integration.csproj", "{D1C10D6D-740F-4CAA-AF9B-C74B438A9005}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,17 +13,20 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A2269678-CBCC-4444-AD9D-5D82ABC52800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2269678-CBCC-4444-AD9D-5D82ABC52800}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2269678-CBCC-4444-AD9D-5D82ABC52800}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2269678-CBCC-4444-AD9D-5D82ABC52800}.Release|Any CPU.Build.0 = Release|Any CPU - {CC907EDA-7B33-4E85-8E45-60714B79CACB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CC907EDA-7B33-4E85-8E45-60714B79CACB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CC907EDA-7B33-4E85-8E45-60714B79CACB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CC907EDA-7B33-4E85-8E45-60714B79CACB}.Release|Any CPU.Build.0 = Release|Any CPU - {D5BFF82C-AF15-4528-86DA-D83509ABF64B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D5BFF82C-AF15-4528-86DA-D83509ABF64B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D5BFF82C-AF15-4528-86DA-D83509ABF64B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D5BFF82C-AF15-4528-86DA-D83509ABF64B}.Release|Any CPU.Build.0 = Release|Any CPU + {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Release|Any CPU.Build.0 = Release|Any CPU + {F8E42768-5A4D-4220-BC17-2DCA7CDC689D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8E42768-5A4D-4220-BC17-2DCA7CDC689D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8E42768-5A4D-4220-BC17-2DCA7CDC689D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8E42768-5A4D-4220-BC17-2DCA7CDC689D}.Release|Any CPU.Build.0 = Release|Any CPU + {D1C10D6D-740F-4CAA-AF9B-C74B438A9005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1C10D6D-740F-4CAA-AF9B-C74B438A9005}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1C10D6D-740F-4CAA-AF9B-C74B438A9005}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1C10D6D-740F-4CAA-AF9B-C74B438A9005}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + version = 2.0.0 EndGlobalSection EndGlobal diff --git a/src/Intercom/Clients/VisitorsClient.cs b/src/Intercom/Clients/VisitorsClient.cs index 46fbf59..d589c3e 100644 --- a/src/Intercom/Clients/VisitorsClient.cs +++ b/src/Intercom/Clients/VisitorsClient.cs @@ -99,7 +99,6 @@ public Visitor Update(Visitor visitor) ClientResponse result = null; result = Put(visitor); - return result.Result; } diff --git a/src/Intercom/Data/AdminConversationReply.cs b/src/Intercom/Data/AdminConversationReply.cs index dd02b8e..60ed306 100644 --- a/src/Intercom/Data/AdminConversationReply.cs +++ b/src/Intercom/Data/AdminConversationReply.cs @@ -13,7 +13,7 @@ namespace Intercom.Data { public class AdminConversationReply : Reply { - public string type + public override string type { get { diff --git a/src/Intercom/Data/Company.cs b/src/Intercom/Data/Company.cs index 92f82cf..4e0f982 100644 --- a/src/Intercom/Data/Company.cs +++ b/src/Intercom/Data/Company.cs @@ -1,6 +1,8 @@ using System; using Intercom.Core; using System.Collections.Generic; +using Newtonsoft.Json; +using Intercom.Converters.AttributeConverters; namespace Intercom.Data { @@ -21,5 +23,7 @@ public class Company : Model public string website { get; set; } public string industry { get; set; } public Dictionary custom_attributes { get; set; } + [JsonConverter(typeof(ListJsonConverter))] + public List tags { get; set; } } } diff --git a/src/Intercom/Data/Conversation.cs b/src/Intercom/Data/Conversation.cs index e687143..1551df2 100644 --- a/src/Intercom/Data/Conversation.cs +++ b/src/Intercom/Data/Conversation.cs @@ -13,14 +13,19 @@ public class Conversation : Model { public long created_at { get; set; } public long updated_at { get; set; } + public long? waiting_since { get; set; } + public long? snoozed_until { get; set; } public Assignee assignee { get; set; } public User user { get; set; } public bool open { get; set; } public bool read { get; set; } + public string state { get; set; } + public int total_count { get; set; } public ConversationMessage conversation_message { get; set; } [JsonConverter(typeof(ListJsonConverter))] public List conversation_parts { get; set; } [JsonConverter(typeof(ListJsonConverter))] public List tags { get; set; } + public List customers { get; set; } } } diff --git a/src/Intercom/Data/ConversationPart.cs b/src/Intercom/Data/ConversationPart.cs index f22cd70..0dc894b 100644 --- a/src/Intercom/Data/ConversationPart.cs +++ b/src/Intercom/Data/ConversationPart.cs @@ -1,12 +1,8 @@ using System; using Intercom.Core; using Intercom.Data; - - using Intercom.Clients; - using Intercom.Exceptions; - using System.Collections.Generic; namespace Intercom.Data @@ -18,7 +14,7 @@ public class ConversationPart : Model public long created_at { get; set; } public long updated_at { get; set; } public long notified_at { get; set; } - public object assigned_to { get; set; } + public Assignee assigned_to { get; set; } public Author author { get; set; } public List attachments { get; set; } } diff --git a/src/Intercom/Data/Customer.cs b/src/Intercom/Data/Customer.cs new file mode 100644 index 0000000..1d45572 --- /dev/null +++ b/src/Intercom/Data/Customer.cs @@ -0,0 +1,9 @@ +using System; +using Intercom.Core; + +namespace Intercom.Data +{ + public class Customer : Model + { + } +} diff --git a/src/Intercom/Data/SocialProfile.cs b/src/Intercom/Data/SocialProfile.cs index 0fab79c..32edb03 100644 --- a/src/Intercom/Data/SocialProfile.cs +++ b/src/Intercom/Data/SocialProfile.cs @@ -11,7 +11,7 @@ namespace Intercom.Data { public class SocialProfile : Model { - public string type { get; set; } + public override string type { get; set; } public string username { get; set; } public string url { get; set; } } diff --git a/src/Intercom/Data/UserConversationReply.cs b/src/Intercom/Data/UserConversationReply.cs index b830fc8..ffb7370 100644 --- a/src/Intercom/Data/UserConversationReply.cs +++ b/src/Intercom/Data/UserConversationReply.cs @@ -9,7 +9,7 @@ namespace Intercom.Data { public class UserConversationReply : Reply { - public string type + public override string type { get { @@ -17,7 +17,7 @@ public string type } } - public String message_type + public override String message_type { get { diff --git a/src/Intercom/Data/Visitor.cs b/src/Intercom/Data/Visitor.cs index 2d4730b..46ed680 100644 --- a/src/Intercom/Data/Visitor.cs +++ b/src/Intercom/Data/Visitor.cs @@ -13,30 +13,8 @@ namespace Intercom.Data { - public class Visitor : Model + public class Visitor : User { - public string user_id { get; set; } - public string name { get; set; } - public string email { set; get; } - public string phone { set; get; } - public long? created_at { get; set; } - public long? updated_at { get; set; } - public string last_seen_ip { get; set; } - public bool? unsubscribed_from_emails { get; set; } - public long? last_request_at { get; set; } - public string user_agent_data { get; set; } - public Dictionary custom_attributes { get; set; } - public Avatar avatar { get; set; } - public LocationData location_data { get; set; } - [JsonConverter(typeof(ListJsonConverter))] - public List social_profiles { get; set; } - [JsonConverter(typeof(ListJsonConverter))] - public List segments { get; set; } - [JsonConverter(typeof(ListJsonConverter))] - public List tags { get; set; } - [JsonConverter(typeof(ListJsonConverter))] - public List companies { get; set; } - public Visitor() { } diff --git a/src/Intercom/Intercom.csproj b/src/Intercom/Intercom.csproj index faa800f..179adbf 100644 --- a/src/Intercom/Intercom.csproj +++ b/src/Intercom/Intercom.csproj @@ -1,139 +1,13 @@ - - - - Debug - AnyCPU - {A2269678-CBCC-4444-AD9D-5D82ABC52800} - Library - Library - Library - v4.5 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + netcoreapp2.0 + 2.0.0 + + + + + + + + diff --git a/src/Intercom/Properties/AssemblyInfo.cs b/src/Intercom/Properties/AssemblyInfo.cs deleted file mode 100644 index 08047a9..0000000 --- a/src/Intercom/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle ("Intercom.Dotnet.Client")] -[assembly: AssemblyDescription ("")] -[assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] -[assembly: AssemblyCopyright ("khalil")] -[assembly: AssemblyTrademark ("")] -[assembly: AssemblyCulture ("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion ("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/src/Intercom/Intercom.nuspec b/src/Intercom/intercom.nuspec similarity index 95% rename from src/Intercom/Intercom.nuspec rename to src/Intercom/intercom.nuspec index 57beb41..7538728 100644 --- a/src/Intercom/Intercom.nuspec +++ b/src/Intercom/intercom.nuspec @@ -3,7 +3,7 @@ Intercom.Dotnet.Client Intercom Dotnet Client - 1.0 + 2.0.0 Intercom Intercom false diff --git a/src/Intercom/packages.config b/src/Intercom/packages.config deleted file mode 100644 index b2d1a3f..0000000 --- a/src/Intercom/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From 571e20959e8b072a51b31c33d155bb4fbca20c95 Mon Sep 17 00:00:00 2001 From: Bruno Vieira Date: Sun, 1 Apr 2018 15:28:48 +0100 Subject: [PATCH 2/2] fixed #105 --- README.md | 3 +++ src/Intercom/Clients/UsersClient.cs | 22 ++++++++++++++-------- src/Intercom/Data/User.cs | 8 +------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 45dc223..a699b86 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,9 @@ User user = usersClient.UpdateLastSeenAt(new User() { id = "100300231" }, 146211 **Increment User's Session** ```cs usersClient.IncrementUserSession(new User() { id = "100300231" }); +usersClient.IncrementUserSession("100300231", new List() { "company_is_blue" }}); + +// You can also update a User's session by updating a User record with a "new_session = true" attribute ``` **Removing User's companies** diff --git a/src/Intercom/Clients/UsersClient.cs b/src/Intercom/Clients/UsersClient.cs index 9865689..17702c7 100644 --- a/src/Intercom/Clients/UsersClient.cs +++ b/src/Intercom/Clients/UsersClient.cs @@ -335,20 +335,25 @@ public User IncrementUserSession(String id) return result.Result; } - public User IncrementUserSession(User user) + public User IncrementUserSession(String id, List companyIds) { - if (user == null) + if (String.IsNullOrEmpty(id)) { - throw new ArgumentNullException(nameof(user)); + throw new ArgumentNullException(nameof(id)); } - if (String.IsNullOrEmpty(user.id)) + if (companyIds == null) { - throw new ArgumentException("'user.id' argument is null."); + throw new ArgumentNullException(nameof(companyIds)); + } + + if (!companyIds.Any()) + { + throw new ArgumentException("'companyIds' shouldnt be empty."); } ClientResponse result = null; - String body = JsonConvert.SerializeObject(new { id = user.id, new_session = true }); + String body = JsonConvert.SerializeObject(new { id = id, new_session = true, companies = companyIds.Select(c => new { id = c }) }); result = Post(body); return result.Result; } @@ -417,7 +422,7 @@ private String Transform(User user) name = c.name, monthly_spend = c.monthly_spend, custom_attributes = c.custom_attributes, - plan = c.plan != null ? c.plan.name : String.Empty, + plan = c.plan != null ? c.plan.name : null, remove = c.remove }).ToList(); } @@ -436,7 +441,8 @@ private String Transform(User user) signed_up_at = user.signed_up_at, last_seen_ip = user.last_seen_ip, custom_attributes = user.custom_attributes, - last_seen_user_agent = user.user_agent_data, + new_session = user.new_session, + user_agent_data = user.user_agent_data, last_request_at = user.last_request_at, unsubscribed_from_emails = user.unsubscribed_from_emails }; diff --git a/src/Intercom/Data/User.cs b/src/Intercom/Data/User.cs index 42ab4c7..cbffb37 100644 --- a/src/Intercom/Data/User.cs +++ b/src/Intercom/Data/User.cs @@ -1,12 +1,5 @@ using System; using Intercom.Core; -using Intercom.Data; -using Intercom.Clients; -using Intercom.Exceptions; -using RestSharp; -using RestSharp.Authenticators; -using System.Collections; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using Intercom.Converters.AttributeConverters; @@ -26,6 +19,7 @@ public class User : Model public long? signed_up_at { get; set; } public long? created_at { get; set; } public int? session_count { get; set; } + public bool? new_session { get; set; } public string user_agent_data { get; set; } public object pseudonym { get; set; } public bool? anonymous { get; set; }