├── .circleci └── config.yml ├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md └── src ├── Intercom.Tests.Integration ├── Intercom.Tests.Integration.csproj ├── Test.cs └── TestBase.cs ├── Intercom.Tests ├── Clients │ ├── AdminClientTest.cs │ ├── AdminConversationsClientTest.cs │ ├── CompanyClientTest.cs │ ├── ContactClientTest.cs │ ├── ConversationsClientTest.cs │ ├── EventsClientTest.cs │ ├── NotesClientTest.cs │ ├── SegmentsClientTest.cs │ ├── TagsClientTest.cs │ ├── UserClientTest.cs │ └── UserConversationsClientTest.cs ├── Converters │ ├── AttributeConverters │ │ ├── ListJonConverterTest.cs │ │ └── MetadataJsonConverterTest.cs │ └── ClassConverters │ │ ├── AppCountJsonConverterTest.cs │ │ ├── CompanyCountJsonConverterTest.cs │ │ ├── ConversationAdminCountJsonConverterTest.cs │ │ ├── ConversationAppCountJsonConverterTest.cs │ │ └── UserCountJsonConverterTest.cs ├── Core │ └── ClientTest.cs ├── Data │ ├── AdminConversationMessageTest.cs │ ├── AdminConversationReplyTest.cs │ ├── MetadataTest.cs │ ├── Responses │ │ ├── Conversation.json │ │ └── ConversationsList.json │ ├── UserConversationMessageTest.cs │ └── UserConversationReplyTest.cs ├── Intercom.Tests.csproj └── TestBase.cs ├── Intercom.sln ├── Intercom ├── Clients │ ├── AdminConversationsClient.cs │ ├── AdminsClient.cs │ ├── CompanyClient.cs │ ├── ContactsClient.cs │ ├── ConversationsClient.cs │ ├── CountsClient.cs │ ├── EventClient.cs │ ├── NotesClient.cs │ ├── SegmentsClient.cs │ ├── TagsClient.cs │ ├── UserConversationsClient.cs │ ├── UsersClient.cs │ └── VisitorsClient.cs ├── Converters │ ├── AttributeConverters │ │ ├── ListJsonConverter.cs │ │ └── MetadataJsonConverter.cs │ └── ClassConverters │ │ ├── AppCountJsonConverter.cs │ │ ├── CompanyCountJsonConverter.cs │ │ ├── ConversationAdminCountJsonConverter.cs │ │ ├── ConversationAppCountJsonConverter.cs │ │ └── UserCountJsonConverter.cs ├── Core │ ├── Authentication.cs │ ├── Client.cs │ ├── ClientConfiguration.cs │ ├── ClientResponse.cs │ ├── Constants.cs │ ├── Model.cs │ └── Models.cs ├── Data │ ├── Admin.cs │ ├── AdminConversationMessage.cs │ ├── AdminConversationReply.cs │ ├── AdminLastConversationReply.cs │ ├── Admins.cs │ ├── AppCount.cs │ ├── Assignee.cs │ ├── Attachment.cs │ ├── Author.cs │ ├── Avatar.cs │ ├── Companies.cs │ ├── Company.cs │ ├── CompanySegmentCount.cs │ ├── CompanyTagCount.cs │ ├── CompanyUserCount.cs │ ├── Contact.cs │ ├── Contacts.cs │ ├── Conversation.cs │ ├── ConversationAdminCount.cs │ ├── ConversationAppCount.cs │ ├── ConversationMessage.cs │ ├── ConversationPart.cs │ ├── ConversationRating.cs │ ├── ConversationUser.cs │ ├── Conversations.cs │ ├── Count.cs │ ├── Customer.cs │ ├── Error.cs │ ├── Errors.cs │ ├── Event.cs │ ├── Events.cs │ ├── LocationData.cs │ ├── Message.cs │ ├── Metadata.cs │ ├── Note.cs │ ├── Notes.cs │ ├── Pages.cs │ ├── Plan.cs │ ├── Reply.cs │ ├── Segment.cs │ ├── SegmentCount.cs │ ├── Segments.cs │ ├── SocialProfile.cs │ ├── SocialProfiles.cs │ ├── Tag.cs │ ├── TagCount.cs │ ├── Tags.cs │ ├── Teammate.cs │ ├── User.cs │ ├── UserConversationMessage.cs │ ├── UserConversationReply.cs │ ├── UserCount.cs │ ├── UserSegmentCount.cs │ ├── UserTagCount.cs │ ├── Users.cs │ └── Visitor.cs ├── Enums │ ├── MessageType.cs │ └── OrderBy.cs ├── Exceptions │ ├── ApiException.cs │ ├── IntercomException.cs │ └── JsonConverterException.cs ├── Factories │ └── RestClientFactory.cs ├── Intercom.csproj └── intercom.nuspec └── assets └── Intercom.png /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: microsoft/dotnet:2-sdk 6 | 7 | working_directory: ~/repo 8 | 9 | steps: 10 | - checkout 11 | 12 | - run: 13 | name: Unit Tests 14 | command: dotnet test src/Intercom.Tests/Intercom.Tests.csproj 15 | 16 | - run: 17 | name: Integ Tests 18 | command: dotnet test src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | #### Why? 2 | Why are you making this change? 3 | 4 | #### How? 5 | Technical details on your change 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | **/.DS_Store 4 | x 5 | # User-specific files 6 | *.suo 7 | *.user 8 | *.userosscache 9 | *.sln.docstates 10 | 11 | # User-specific files (MonoDevelop/Xamarin Studio) 12 | *.userprefs 13 | 14 | # Build results 15 | [Dd]ebug/ 16 | [Dd]ebugPublic/ 17 | [Rr]elease/ 18 | [Rr]eleases/ 19 | x64/ 20 | x86/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | [Ll]og/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | src/Intercom.Tests/Test.cs 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | *.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | 199 | 200 | # Since there are multiple workflows, uncomment next line to ignore bower_components 201 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 202 | #bower_components/ 203 | 204 | # RIA/Silverlight projects 205 | Generated_Code/ 206 | 207 | # Backup & report files from converting an old project file 208 | # to a newer Visual Studio version. Backup files are not needed, 209 | # because we have git ;-) 210 | _UpgradeReport_Files/ 211 | Backup*/ 212 | UpgradeLog*.XML 213 | UpgradeLog*.htm 214 | 215 | # SQL Server files 216 | *.mdf 217 | *.ldf 218 | 219 | # Business Intelligence projects 220 | *.rdl.data 221 | *.bim.layout 222 | *.bim_*.settings 223 | 224 | # Microsoft Fakes 225 | FakesAssemblies/ 226 | 227 | # GhostDoc plugin setting file 228 | *.GhostDoc.xml 229 | 230 | # Node.js Tools for Visual Studio 231 | .ntvs_analysis.dat 232 | 233 | # Visual Studio 6 build log 234 | *.plg 235 | 236 | # Visual Studio 6 workspace options file 237 | *.opt 238 | 239 | # VSCode 240 | .vscode 241 | 242 | # Visual Studio LightSwitch build output 243 | **/*.HTMLClient/GeneratedArtifacts 244 | **/*.DesktopClient/GeneratedArtifacts 245 | **/*.DesktopClient/ModelManifest.xml 246 | **/*.Server/GeneratedArtifacts 247 | **/*.Server/ModelManifest.xml 248 | _Pvt_Extensions 249 | 250 | # Paket dependency manager 251 | .paket/paket.exe 252 | paket-files/ 253 | 254 | # FAKE - F# Make 255 | .fake/ 256 | 257 | # JetBrains Rider 258 | .idea/ 259 | *.sln.iml 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/Intercom.Tests.Integration/Intercom.Tests.Integration.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0;net452 5 | 3.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Intercom.Tests.Integration/Test.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | 5 | namespace Intercom.Integration.Tests 6 | { 7 | [TestFixture] 8 | public class Test : TestBase 9 | { 10 | 11 | [SetUp] 12 | public void SetUp() 13 | { 14 | CheckForApiCredentials(); 15 | } 16 | 17 | [Test] 18 | public void Testing() 19 | { 20 | } 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/Intercom.Tests.Integration/TestBase.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | 5 | namespace Intercom.Integration.Tests 6 | { 7 | [TestFixture()] 8 | public class TestBase 9 | { 10 | public String AppId; 11 | public String AppKey; 12 | 13 | public void CheckForApiCredentials() 14 | { 15 | this.AppKey = Environment.GetEnvironmentVariable("IntercomAppKey"); 16 | this.AppId = Environment.GetEnvironmentVariable("IntercomAppId"); 17 | 18 | if (String.IsNullOrEmpty(AppKey) || String.IsNullOrEmpty(AppId)) 19 | Assert.Ignore("Intercom.Integration.Tests will be ignored because there are no environment variables defined for IntercomAppKey or IntercomAppId."); 20 | } 21 | 22 | public TestBase() 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/AdminClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class AdminClientTest : TestBase 18 | { 19 | private AdminsClient adminsClient; 20 | 21 | public AdminClientTest() 22 | : base() 23 | { 24 | var auth = new Authentication(AppId, AppKey); 25 | var restClientFactory = new RestClientFactory(auth); 26 | adminsClient = new AdminsClient(restClientFactory); 27 | } 28 | 29 | [Test()] 30 | public void View_WithEmptyString_ThrowException() 31 | { 32 | Assert.Throws(() => adminsClient.View(String.Empty)); 33 | } 34 | 35 | [Test()] 36 | public void View_NoId_ThrowException() 37 | { 38 | Assert.Throws(() => adminsClient.View(new Admin())); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/AdminConversationsClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | // TODO: write tests for AdminConversationsClient 17 | [TestFixture()] 18 | public class AdminConversationsClientTest : TestBase 19 | { 20 | private AdminConversationsClient adminConversationsClient; 21 | 22 | public AdminConversationsClientTest() 23 | { 24 | var auth = new Authentication(AppId, AppKey); 25 | var restClientFactory = new RestClientFactory(auth); 26 | adminConversationsClient = new AdminConversationsClient(restClientFactory); 27 | } 28 | 29 | [Test()] 30 | public void Reply_WithNull_ThrowException() 31 | { 32 | Assert.Throws(() => adminConversationsClient.Reply(null)); 33 | } 34 | 35 | [Test()] 36 | public void Create_WithNull_ThrowException() 37 | { 38 | Assert.Throws(() => adminConversationsClient.Create(null)); 39 | } 40 | 41 | [Test()] 42 | public void List_NoId_ThrowException() 43 | { 44 | Assert.Throws(() => adminConversationsClient.List(new Admin())); 45 | } 46 | 47 | [Test()] 48 | public void ReplyLastConversation_NoReply_ThrowException() 49 | { 50 | Assert.Throws(() => adminConversationsClient.ReplyLastConversation(new AdminLastConversationReply())); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/CompanyClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class CompanyClientTest : TestBase 18 | { 19 | private CompanyClient companyClient; 20 | 21 | public CompanyClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | companyClient = new CompanyClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void Create_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => companyClient.Create(null)); 32 | } 33 | 34 | [Test()] 35 | public void Delete_MoreThan100CustomAtt_ThrowException() 36 | { 37 | Dictionary custom_attributes = new Dictionary(); 38 | 39 | for (int i = 0; i < 105; i++) 40 | custom_attributes.Add($"field{i}", "value"); 41 | 42 | Assert.Throws(() => 43 | { 44 | companyClient.Create(new Company() { custom_attributes = custom_attributes }); 45 | }); 46 | } 47 | 48 | [Test()] 49 | public void Create_CustomAttInvalidChars_ThrowException() 50 | { 51 | Dictionary custom_attributes = new Dictionary(); 52 | custom_attributes.Add("invalid.ch$ar", "invalid"); 53 | Assert.Throws(() => 54 | { 55 | companyClient.Create(new Company() { custom_attributes = custom_attributes }); 56 | }); 57 | } 58 | 59 | [Test()] 60 | public void Update_WithNull_ThrowException() 61 | { 62 | Assert.Throws(() => companyClient.Update(null)); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/ContactClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class ContactClientTest : TestBase 18 | { 19 | private ContactsClient contactsClient; 20 | 21 | public ContactClientTest() 22 | : base() 23 | { 24 | var auth = new Authentication(AppId, AppKey); 25 | var restClientFactory = new RestClientFactory(auth); 26 | contactsClient = new ContactsClient(restClientFactory); 27 | } 28 | 29 | [Test()] 30 | public void Create_WithNull_ThrowException() 31 | { 32 | Assert.Throws(() => contactsClient.Create(null)); 33 | } 34 | 35 | [Test()] 36 | public void Update_NoIdOrUserIdOrEmail_ThrowException() 37 | { 38 | Assert.Throws(() => contactsClient.Update(new Contact())); 39 | } 40 | 41 | [Test()] 42 | public void ListByEmail_NoEmail_ThrowException() 43 | { 44 | Assert.Throws(() => contactsClient.List(String.Empty)); 45 | } 46 | 47 | [Test()] 48 | public void Delete_NoIdOrUserIdOrEmail_ThrowException() 49 | { 50 | Assert.Throws(() => contactsClient.Delete(new Contact())); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/ConversationsClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class ConversationsClientTest : TestBase 18 | { 19 | private ConversationsClient conversationsClient; 20 | 21 | public ConversationsClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | conversationsClient = new ConversationsClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void View_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => conversationsClient.View(null)); 32 | } 33 | 34 | [Test()] 35 | public void ListAll_WithNullParameters_ThrowException() 36 | { 37 | Assert.Throws(() => conversationsClient.ListAll(null)); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/EventsClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class EventsClientTest : TestBase 18 | { 19 | private EventsClient eventsClient; 20 | 21 | public EventsClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | eventsClient = new EventsClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void Create_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => eventsClient.Create(null)); 32 | } 33 | 34 | [Test()] 35 | public void List_NoIdOrUserIdOrEmail_ThrowException() 36 | { 37 | Assert.Throws(() =>eventsClient.List(new User())); 38 | } 39 | 40 | [Test()] 41 | public void ListByParams_NoIdOrUserIdOrEmail_ThrowException() 42 | { 43 | Assert.Throws(() => eventsClient.List(new Dictionary())); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/NotesClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class NotesClientTest : TestBase 18 | { 19 | private NotesClient notesClient; 20 | 21 | public NotesClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | notesClient = new NotesClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void Create_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => notesClient.Create(null)); 32 | } 33 | 34 | [Test()] 35 | public void CreateWithNote_NoUserIdOrEmail_ThrowException() 36 | { 37 | Assert.Throws(() => notesClient.Create(new Note() { user = new User() })); 38 | } 39 | 40 | [Test()] 41 | public void CreateWithNote_NoBody_ThrowException() 42 | { 43 | Assert.Throws(() => 44 | { 45 | notesClient.Create(new Note() { user = new User() { email = "email@example.com" } }); 46 | }); 47 | } 48 | 49 | [Test()] 50 | public void Create_NoUserIdOrEmail_ThrowException() 51 | { 52 | Assert.Throws(() => notesClient.Create(new User(), String.Empty)); 53 | } 54 | 55 | [Test()] 56 | public void Create_NoBody_ThrowException() 57 | { 58 | Assert.Throws(() => 59 | { 60 | notesClient.Create(new User() { email = "email@example.com" }, String.Empty); 61 | }); 62 | } 63 | 64 | [Test()] 65 | public void List_NoIdOrUserIdOrEmail_ThrowException() 66 | { 67 | Assert.Throws(() => notesClient.List(new User())); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/SegmentsClientTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Intercom.Test 4 | { 5 | public class SegmentsClientTest 6 | { 7 | public SegmentsClientTest() 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/TagsClientTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Intercom.Clients; 4 | using Intercom.Core; 5 | using Intercom.Data; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using Moq; 9 | using Newtonsoft.Json; 10 | using NUnit.Framework; 11 | using RestSharp; 12 | using RestSharp.Authenticators; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class TagsClientTest : TestBase 18 | { 19 | private TagsClient tagsClient; 20 | 21 | public TagsClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | tagsClient = new TagsClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void Create_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => tagsClient.Create(null)); 32 | } 33 | 34 | [Test()] 35 | public void Create_NoIdOrName_ThrowException() 36 | { 37 | Assert.Throws(() => tagsClient.Create(new Tag())); 38 | } 39 | 40 | [Test()] 41 | public void Delete_WithNull_ThrowException() 42 | { 43 | Tag tag = null; 44 | Assert.Throws(() => tagsClient.Delete(tag)); 45 | } 46 | 47 | [Test()] 48 | public void Delete_NoId_ThrowException() 49 | { 50 | Assert.Throws(() => tagsClient.Delete(new Tag())); 51 | } 52 | 53 | 54 | [Test()] 55 | public void Tag_NoName_ThrowException() 56 | { 57 | Assert.Throws(() => 58 | { 59 | tagsClient.Tag(String.Empty, new List()); 60 | }); 61 | 62 | Assert.Throws(() => 63 | { 64 | tagsClient.Tag(String.Empty, new List()); 65 | }); 66 | 67 | Assert.Throws(() => 68 | { 69 | tagsClient.Tag(String.Empty, new List()); 70 | }); 71 | } 72 | 73 | [Test()] 74 | public void Tag_NoIds_ThrowException() 75 | { 76 | List contacts = null; 77 | List users = null; 78 | List companies = null; 79 | 80 | Assert.Throws(() => 81 | { 82 | tagsClient.Tag("sample tag", companies); 83 | }); 84 | Assert.Throws(() => 85 | { 86 | tagsClient.Tag("sample tag", contacts); 87 | }); 88 | Assert.Throws(() => 89 | { 90 | tagsClient.Tag("sample tag", users); 91 | }); 92 | } 93 | 94 | [Test()] 95 | public void TagWithEntityType_NoIds_ThrowException() 96 | { 97 | Assert.Throws(() => 98 | { 99 | tagsClient.Tag("sample tag", null, TagsClient.EntityType.Company); 100 | }); 101 | Assert.Throws(() => 102 | { 103 | tagsClient.Tag("sample tag", null, TagsClient.EntityType.User); 104 | }); 105 | Assert.Throws(() => 106 | { 107 | tagsClient.Tag("sample tag", null, TagsClient.EntityType.Contact); 108 | }); 109 | } 110 | 111 | [Test()] 112 | public void Untag_NoName_ThrowException() 113 | { 114 | Assert.Throws(() => 115 | { 116 | tagsClient.Untag(String.Empty, new List()); 117 | }); 118 | 119 | Assert.Throws(() => 120 | { 121 | tagsClient.Untag(String.Empty, new List()); 122 | }); 123 | 124 | Assert.Throws(() => 125 | { 126 | tagsClient.Untag(String.Empty, new List()); 127 | }); 128 | } 129 | 130 | [Test()] 131 | public void Untag_NoIds_ThrowException() 132 | { 133 | List contacts = null; 134 | List users = null; 135 | List companies = null; 136 | 137 | Assert.Throws(() => 138 | { 139 | tagsClient.Untag("sample tag", companies); 140 | }); 141 | Assert.Throws(() => 142 | { 143 | tagsClient.Untag("sample tag", contacts); 144 | }); 145 | Assert.Throws(() => 146 | { 147 | tagsClient.Untag("sample tag", users); 148 | }); 149 | } 150 | 151 | [Test()] 152 | public void UntagWithEntityType_NoIds_ThrowException() 153 | { 154 | Assert.Throws(() => 155 | { 156 | tagsClient.Untag("sample tag", null, TagsClient.EntityType.Company); 157 | }); 158 | Assert.Throws(() => 159 | { 160 | tagsClient.Untag("sample tag", null, TagsClient.EntityType.User); 161 | }); 162 | Assert.Throws(() => 163 | { 164 | tagsClient.Untag("sample tag", null, TagsClient.EntityType.Contact); 165 | }); 166 | } 167 | 168 | } 169 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/UserClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using System.Net; 4 | using Intercom.Core; 5 | using Intercom.Data; 6 | using Intercom.Clients; 7 | using Intercom.Exceptions; 8 | using Intercom.Factories; 9 | using RestSharp; 10 | using RestSharp.Authenticators; 11 | using System.Collections.Generic; 12 | using Newtonsoft.Json; 13 | using Moq; 14 | 15 | namespace Intercom.Test 16 | { 17 | [TestFixture()] 18 | public class UserClientTest : TestBase 19 | { 20 | private UsersClient usersClient; 21 | 22 | public UserClientTest() { } 23 | 24 | private void SetupMock(RestClient restClient = null) 25 | { 26 | var auth = new Authentication(AppId, AppKey); 27 | if (restClient == null) 28 | { 29 | var restClientMock = new Mock(); 30 | restClient = restClientMock.Object; 31 | } 32 | var restClientFactoryMock = new Mock(new object[] { auth }); 33 | restClientFactoryMock.Setup(x => x.RestClient).Returns(restClient); 34 | var restClientFactory = restClientFactoryMock.Object; 35 | usersClient = new UsersClient(restClientFactory); 36 | } 37 | 38 | [Test()] 39 | public void Create_WithNull_ThrowException() 40 | { 41 | SetupMock(); 42 | Assert.Throws(() => usersClient.Create(null)); 43 | } 44 | 45 | [Test()] 46 | public void Create_NoUserIdOrEmail_ThrowException() 47 | { 48 | SetupMock(); 49 | Assert.Throws(() => usersClient.Create(new User())); 50 | } 51 | 52 | [Test()] 53 | public void Archive_NoIdOrUserIdOrEmail_ThrowException() 54 | { 55 | SetupMock(); 56 | Assert.Throws(() => usersClient.Archive(new User())); 57 | } 58 | 59 | [Test()] 60 | public void PermanentlyDeleteUser_NoId_ThrowException() 61 | { 62 | SetupMock(); 63 | Assert.Throws(() => usersClient.PermanentlyDeleteUser(null)); 64 | } 65 | 66 | [Test()] 67 | public void Update_NoIdOrUserIdOrEmail_ThrowException() 68 | { 69 | SetupMock(); 70 | Assert.Throws(() => usersClient.Update(new User())); 71 | } 72 | 73 | [Test()] 74 | public void View_ByStringId_ReturnsObjectAsExpected() 75 | { 76 | var userId = "id"; 77 | var restClientMock = new Mock(); 78 | var restResponse = new RestResponse() 79 | { 80 | StatusCode = HttpStatusCode.OK, 81 | Content = $"{{ \"type\": \"user\", \"id\": \"530370b477ad7120001d\", \"user_id\": \"{userId}\", \"email\": \"wash@serenity.io\" }}", 82 | }; 83 | restClientMock.Setup(x => x.Execute(It.IsAny())).Returns(restResponse); 84 | var restClient = restClientMock.Object; 85 | SetupMock(restClient); 86 | Assert.AreEqual(userId, usersClient.View(userId).user_id); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Intercom.Tests/Clients/UserConversationsClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using Intercom.Factories; 8 | using RestSharp; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class UserConversationsClientTest : TestBase 18 | { 19 | private UserConversationsClient userConversationsClient; 20 | 21 | public UserConversationsClientTest() 22 | { 23 | var auth = new Authentication(AppId, AppKey); 24 | var restClientFactory = new RestClientFactory(auth); 25 | userConversationsClient = new UserConversationsClient(restClientFactory); 26 | } 27 | 28 | [Test()] 29 | public void Reply_WithNull_ThrowException() 30 | { 31 | Assert.Throws(() => userConversationsClient.Reply(null)); 32 | } 33 | 34 | [Test()] 35 | public void Create_WithNull_ThrowException() 36 | { 37 | Assert.Throws(() => userConversationsClient.Create(null)); 38 | } 39 | 40 | [Test()] 41 | public void List_NoIdOrUserIdOrEmail_ThrowException() 42 | { 43 | Assert.Throws(() => userConversationsClient.List(new User())); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/AttributeConverters/ListJonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.AttributeConverters; 7 | using Intercom.Converters.ClassConverters; 8 | using Intercom.Core; 9 | using Intercom.Data; 10 | using Intercom.Exceptions; 11 | using Moq; 12 | using Newtonsoft.Json; 13 | using NUnit.Framework; 14 | using RestSharp; 15 | using RestSharp.Authenticators; 16 | 17 | namespace Intercom.Test 18 | { 19 | [TestFixture()] 20 | public class ListJonConverterTest : TestBase 21 | { 22 | private ListJsonConverter listJsonConverter; 23 | 24 | public ListJonConverterTest() 25 | { 26 | this.listJsonConverter = new ListJsonConverter(); 27 | } 28 | 29 | [Test()] 30 | public void ReadJson_ForCompanyList_ReturnsValidCount() 31 | { 32 | 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\"}]}"; 33 | StringReader stringReader = new StringReader(input); 34 | JsonReader reader = new JsonTextReader(stringReader); 35 | List companies = listJsonConverter.ReadJson(reader, typeof(List), null, null) as List; 36 | 37 | Assert.AreEqual(3, companies.Count); 38 | Assert.AreEqual("first_company", companies.First().company_id); 39 | } 40 | 41 | [Test()] 42 | public void ReadJson_InvalidSerializationType_ThrowsException() 43 | { 44 | 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\"}]}"; 45 | StringReader stringReader = new StringReader(input); 46 | JsonReader reader = new JsonTextReader(stringReader); 47 | Assert.Throws(() => listJsonConverter.ReadJson(reader, typeof(List), null, null)); 48 | } 49 | 50 | [Test()] 51 | public void ReadJson_InvalidJson_ThrowsException() 52 | { 53 | 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\"}]}"; 54 | StringReader stringReader = new StringReader(input); 55 | JsonReader reader = new JsonTextReader(stringReader); 56 | 57 | Assert.Throws(() => listJsonConverter.ReadJson(reader, typeof(List), null, null)); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/AttributeConverters/MetadataJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.AttributeConverters; 7 | using Intercom.Converters.ClassConverters; 8 | using Intercom.Core; 9 | using Intercom.Data; 10 | using Intercom.Exceptions; 11 | using Moq; 12 | using Newtonsoft.Json; 13 | using NUnit.Framework; 14 | using RestSharp; 15 | using RestSharp.Authenticators; 16 | 17 | namespace Intercom.Test 18 | { 19 | [TestFixture()] 20 | public class MetadataJsonConverterTest : TestBase 21 | { 22 | private MetadataJsonConverter metadataJsonConverter; 23 | 24 | public MetadataJsonConverterTest() 25 | { 26 | this.metadataJsonConverter = new MetadataJsonConverter(); 27 | } 28 | 29 | [Test()] 30 | public void ReadJson_ForConversationAppCount_ReturnsValidCount() 31 | { 32 | String input = "{\"number\":1000,\"string_1\":\"123123\",\"number_2\":1000,\"complex\":{\"amount\":3123123,\"currency\":\"aed\"},\"article_1\":{\"url\":\"https://example.org/orders/3434-3434\",\"value\":\"click here!\"}}"; 33 | StringReader stringReader = new StringReader(input); 34 | JsonReader reader = new JsonTextReader(stringReader); 35 | Metadata metadata = metadataJsonConverter.ReadJson(reader, typeof(Metadata), null, null) as Metadata; 36 | 37 | Assert.AreEqual(5, metadata.GetMetadata().Count); 38 | Assert.AreEqual(1, metadata.GetRichLinks().Count); 39 | Assert.AreEqual(1, metadata.GetMonetaryAmounts().Count); 40 | Assert.AreEqual("1000", metadata.GetMetadata("number")); 41 | Assert.AreEqual("123123", metadata.GetMetadata("string_1")); 42 | } 43 | 44 | [Test()] 45 | public void ReadJson_InvalidMonetaryAmount_ReturnsZeroAmount() 46 | { 47 | String input = "{\"complex\":{\"amount\":\"wrong_value\",\"currency\":\"aed\"},\"article_1\":{\"url\":\"https://example.org/orders/3434-3434\",\"value\":\"click here!\"}}"; 48 | StringReader stringReader = new StringReader(input); 49 | JsonReader reader = new JsonTextReader(stringReader); 50 | 51 | Metadata metadata = metadataJsonConverter.ReadJson(reader, typeof(Metadata), null, null) as Metadata; 52 | Metadata.MonetaryAmount monetaryAmount = metadata.GetMonetaryAmount("complex"); 53 | Assert.AreEqual(0, monetaryAmount.amount); 54 | } 55 | 56 | [Test()] 57 | public void ReadJson_InvalidJson_ThrowsException() 58 | { 59 | String input = "{\"complex\"\":\"aed\"},\"article_1\":{\"url\tps://example.org/orders/3434-3434\",\"value\":\"click here!\"}}"; 60 | StringReader stringReader = new StringReader(input); 61 | JsonReader reader = new JsonTextReader(stringReader); 62 | 63 | Assert.Throws(() => metadataJsonConverter.ReadJson(reader, typeof(Metadata), null, null)); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/ClassConverters/AppCountJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.ClassConverters; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Moq; 11 | using Newtonsoft.Json; 12 | using NUnit.Framework; 13 | using RestSharp; 14 | using RestSharp.Authenticators; 15 | 16 | namespace Intercom.Test 17 | { 18 | [TestFixture()] 19 | public class AppCountJsonConverterTest : TestBase 20 | { 21 | private AppCountJsonConverter appCountJsonConverter; 22 | 23 | public AppCountJsonConverterTest() 24 | { 25 | this.appCountJsonConverter = new AppCountJsonConverter(); 26 | } 27 | 28 | [Test()] 29 | public void ReadJson_ForConversationAppCount_ReturnsValidCount() 30 | { 31 | String input = "{\"type\":\"count.hash\",\"company\":{\"count\":6},\"user\":{\"count\":2025082},\"lead\":{\"count\":1},\"tag\":{\"count\":17},\"segment\":{\"count\":7}}"; 32 | StringReader stringReader = new StringReader(input); 33 | JsonReader reader = new JsonTextReader(stringReader); 34 | AppCount appCount = appCountJsonConverter.ReadJson(reader, typeof(int), null, null) as AppCount; 35 | 36 | Assert.AreEqual(6, appCount.company); 37 | Assert.AreEqual(2025082, appCount.user); 38 | } 39 | 40 | [Test()] 41 | public void ReadJson_InvalidJson_ThrowsException() 42 | { 43 | String input = "{\"type\t\":2025082},\"lead\":{\"count\":{\"count\":17},\"segment\":{\"count\":7}}"; 44 | StringReader stringReader = new StringReader(input); 45 | JsonReader reader = new JsonTextReader(stringReader); 46 | 47 | Assert.Throws(() => appCountJsonConverter.ReadJson(reader, typeof(int), null, null)); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/ClassConverters/CompanyCountJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.ClassConverters; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Moq; 11 | using Newtonsoft.Json; 12 | using NUnit.Framework; 13 | using RestSharp; 14 | using RestSharp.Authenticators; 15 | 16 | namespace Intercom.Test 17 | { 18 | [TestFixture()] 19 | public class CompanyCountJsonConverterTest : TestBase 20 | { 21 | private CompanyCountJsonConverter companyCountJsonConverter; 22 | 23 | public CompanyCountJsonConverterTest() 24 | { 25 | this.companyCountJsonConverter = new CompanyCountJsonConverter(); 26 | } 27 | 28 | [Test()] 29 | public void ReadJson_ForCompanySegmentCount_ReturnsValidCount() 30 | { 31 | String input = "{\"type\":\"count\",\"company\":{\"segment\":[{\"New\":0},{\"Active\":1},{\"Slipping Away\":0}]}}"; 32 | StringReader stringReader = new StringReader(input); 33 | JsonReader reader = new JsonTextReader(stringReader); 34 | CompanySegmentCount companySegmentCount = 35 | companyCountJsonConverter.ReadJson(reader, typeof(CompanySegmentCount), null, null) as CompanySegmentCount; 36 | 37 | Assert.IsNotNull(companySegmentCount); 38 | Assert.AreEqual(3, companySegmentCount.segments.Count); 39 | Assert.AreEqual(0, companySegmentCount.segments["New"]); 40 | } 41 | 42 | [Test()] 43 | public void ReadJson_ForCompanyUserCount_ReturnsValidCount() 44 | { 45 | String input = "{\"type\":\"count\",\"company\":{\"user\":[{\"Test company\":2,\"remote_company_id\":\"2\"},{\"Test company 3\":1,\"remote_company_id\":\"3\"},{\"Serenity\":1,\"remote_company_id\":\"366\"},{\"Test company 4\":1,\"remote_company_id\":\"4\"}]}}"; 46 | StringReader stringReader = new StringReader(input); 47 | JsonReader reader = new JsonTextReader(stringReader); 48 | CompanyUserCount companyUserCount = 49 | companyCountJsonConverter.ReadJson(reader, typeof(CompanyUserCount), null, null) as CompanyUserCount; 50 | 51 | Assert.IsNotNull(companyUserCount); 52 | Assert.AreEqual(4, companyUserCount.counts.Count); 53 | Assert.IsTrue(companyUserCount.counts.Any(c => c.name == "Test company" && c.count == 2)); 54 | } 55 | 56 | [Test()] 57 | public void ReadJson_ForCompanyTagCount_ReturnsValidCompanyTag() 58 | { 59 | String input = "{\"type\":\"count\",\"company\":{\"tag\":[{\"automated-tag\":0},{\"cool-users-only\":6},{\"CSV Import - 2016-04-26 12:22:47 UTC\":0}]}}\n"; 60 | StringReader stringReader = new StringReader(input); 61 | JsonReader reader = new JsonTextReader(stringReader); 62 | 63 | CompanyTagCount companyTagCount = 64 | companyCountJsonConverter.ReadJson(reader, typeof(CompanyTagCount), null, null) as CompanyTagCount; 65 | 66 | Assert.IsNotNull(companyTagCount); 67 | Assert.AreEqual(3, companyTagCount.tags.Count ); 68 | Assert.AreEqual(6, companyTagCount.tags["cool-users-only"]); 69 | } 70 | 71 | [Test()] 72 | public void ReadJson_InvalidJson_ThrowsException() 73 | { 74 | String input = "{\"type\":\"count\",\"company\"tag\":[{\"auto\"cool-users-only\":6},{\"CSV Import - 2016-04-26 12:22:47 UTC\":0}]}}\n"; 75 | StringReader stringReader = new StringReader(input); 76 | JsonReader reader = new JsonTextReader(stringReader); 77 | 78 | Assert.Throws(() => 79 | { 80 | companyCountJsonConverter.ReadJson(reader, typeof(CompanyTagCount), null, null); 81 | }); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/ClassConverters/ConversationAdminCountJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.ClassConverters; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Moq; 11 | using Newtonsoft.Json; 12 | using NUnit.Framework; 13 | using RestSharp; 14 | using RestSharp.Authenticators; 15 | 16 | namespace Intercom.Test 17 | { 18 | [TestFixture()] 19 | public class ConversationAdminCountJsonConverterTest : TestBase 20 | { 21 | private ConversationAdminCountJsonConverter conversationAdminCountJsonConverter; 22 | 23 | public ConversationAdminCountJsonConverterTest() 24 | { 25 | this.conversationAdminCountJsonConverter = new ConversationAdminCountJsonConverter(); 26 | } 27 | 28 | [Test()] 29 | public void ReadJson_ForConversationAppCount_ReturnsValidCount() 30 | { 31 | String input = "{\"type\":\"count\",\"conversation\":{\"admin\":[{\"name\":\"AAA\",\"id\":\"29\",\"open\":3,\"closed\":11},{\"name\":\"BBB\",\"id\":\"10\",\"open\":2,\"closed\":0},{\"name\":\"CCC\",\"id\":\"15\",\"open\":2,\"closed\":2}]}}"; 32 | StringReader stringReader = new StringReader(input); 33 | JsonReader reader = new JsonTextReader(stringReader); 34 | ConversationAdminCount conversationAppCount = 35 | conversationAdminCountJsonConverter.ReadJson(reader, typeof(ConversationAdminCount), null, null) as ConversationAdminCount; 36 | 37 | Assert.IsNotNull(conversationAppCount); 38 | Assert.AreEqual(3, conversationAppCount.admins.Count); 39 | Assert.IsTrue(conversationAppCount.admins.Any(a => a.name == "AAA" && a.open == 3)); 40 | } 41 | 42 | [Test()] 43 | public void ReadJson_InvalidJson_ThrowsException() 44 | { 45 | 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}]}}"; 46 | StringReader stringReader = new StringReader(input); 47 | JsonReader reader = new JsonTextReader(stringReader); 48 | 49 | Assert.Throws(() => 50 | { 51 | conversationAdminCountJsonConverter.ReadJson(reader, typeof(ConversationAdminCount), null, null); 52 | }); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/ClassConverters/ConversationAppCountJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.ClassConverters; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Moq; 11 | using Newtonsoft.Json; 12 | using NUnit.Framework; 13 | using RestSharp; 14 | using RestSharp.Authenticators; 15 | 16 | namespace Intercom.Test 17 | { 18 | [TestFixture()] 19 | public class ConversationAppCountJsonConverterTest : TestBase 20 | { 21 | private ConversationAppCountJsonConverter conversationAppCountJsonConverter; 22 | 23 | public ConversationAppCountJsonConverterTest() 24 | { 25 | this.conversationAppCountJsonConverter = new ConversationAppCountJsonConverter(); 26 | } 27 | 28 | [Test()] 29 | public void ReadJson_ForConversationAppCount_ReturnsValidCount() 30 | { 31 | String input = "{\"type\":\"count\",\"conversation\":{\"open\":24,\"closed\":35,\"unassigned\":11,\"assigned\":13}}"; 32 | StringReader stringReader = new StringReader(input); 33 | JsonReader reader = new JsonTextReader(stringReader); 34 | ConversationAppCount conversationAppCount = 35 | conversationAppCountJsonConverter.ReadJson(reader, typeof(ConversationAppCount), null, null) as ConversationAppCount; 36 | 37 | Assert.IsNotNull(conversationAppCount); 38 | Assert.AreEqual(13, conversationAppCount.assigned); 39 | Assert.AreEqual(11, conversationAppCount.unassigned); 40 | Assert.AreEqual(35, conversationAppCount.closed); 41 | Assert.AreEqual(24, conversationAppCount.open); 42 | } 43 | 44 | [Test()] 45 | public void ReadJson_InvalidJson_ThrowsException() 46 | { 47 | String input = "{\"type\":\"count\\pen\":24,\"closed\":35,\"unassigned\":11,\"assigned\":13}}"; 48 | StringReader stringReader = new StringReader(input); 49 | JsonReader reader = new JsonTextReader(stringReader); 50 | 51 | Assert.Throws(() => 52 | { 53 | conversationAppCountJsonConverter.ReadJson(reader, typeof(ConversationAppCount), null, null); 54 | }); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Converters/ClassConverters/UserCountJsonConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Converters.ClassConverters; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Moq; 11 | using Newtonsoft.Json; 12 | using NUnit.Framework; 13 | using RestSharp; 14 | using RestSharp.Authenticators; 15 | 16 | namespace Intercom.Test 17 | { 18 | [TestFixture()] 19 | public class UserCountJsonConverterTest : TestBase 20 | { 21 | private UserCountJsonConverter userCountJsonConverter; 22 | 23 | public UserCountJsonConverterTest() 24 | { 25 | this.userCountJsonConverter = new UserCountJsonConverter(); 26 | } 27 | 28 | [Test()] 29 | public void ReadJson_ForUserSegment_ReturnsValidCount() 30 | { 31 | String input = "{\"type\":\"count\",\"user\":{\"segment\":[{\"Active\":2},{\"New\":0},{\"P1 Test\":0},{\"Slipping Away\":0}]}}"; 32 | StringReader stringReader = new StringReader(input); 33 | JsonReader reader = new JsonTextReader(stringReader); 34 | UserSegmentCount userSegmentCount = 35 | userCountJsonConverter.ReadJson(reader, typeof(UserSegmentCount), null, null) as UserSegmentCount; 36 | 37 | Assert.IsNotNull(userSegmentCount); 38 | Assert.AreEqual( 4, userSegmentCount.segments.Count); 39 | Assert.AreEqual(2, userSegmentCount.segments["Active"]); 40 | } 41 | 42 | [Test()] 43 | public void ReadJson_ForUserTag_ReturnsValidCount() 44 | { 45 | String input = "{\"type\":\"count\",\"user\":{\"tag\":[{\"automated-tag\":0},{\"has_device_token\":1001},{\"Tag 1\":1},{\"test_user_tagged\":2}]}}"; 46 | StringReader stringReader = new StringReader(input); 47 | JsonReader reader = new JsonTextReader(stringReader); 48 | UserTagCount userTagCount = 49 | userCountJsonConverter.ReadJson(reader, typeof(UserTagCount), null, null) as UserTagCount; 50 | 51 | Assert.IsNotNull(userTagCount); 52 | Assert.AreEqual(4, userTagCount.tags.Count); 53 | Assert.IsTrue(userTagCount.tags.Any(c => c.Key == "has_device_token" && c.Value == 1001)); 54 | } 55 | 56 | [Test()] 57 | public void ReadJson_InvalidJson_ThrowsException() 58 | { 59 | String input = "{\"type\":\"count\",\"usted-tag\":0},{\"has_device_token\":1001},{\"Tag 1\":1},{\"test_user_tagged\":2}]}}"; 60 | StringReader stringReader = new StringReader(input); 61 | JsonReader reader = new JsonTextReader(stringReader); 62 | 63 | Assert.Throws(() => 64 | { 65 | userCountJsonConverter.ReadJson(reader, typeof(UserTagCount), null, null); 66 | }); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Core/ClientTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Intercom.Test 4 | { 5 | [TestFixture ()] 6 | public class ClientTest 7 | { 8 | [Test] 9 | public void Test () 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/AdminConversationMessageTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Intercom.Test 4 | { 5 | // TODO: write tests for AdminConversationMessageTest 6 | public class AdminConversationMessageTest 7 | { 8 | public AdminConversationMessageTest() 9 | { 10 | } 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/AdminConversationReplyTest.cs: -------------------------------------------------------------------------------- 1 | using Intercom.Clients; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using NUnit.Framework; 5 | using System.Net; 6 | 7 | namespace Intercom.Test 8 | { 9 | [TestFixture] 10 | public class AdminConversationReplyTest : TestBase 11 | { 12 | [Test] 13 | public void AdminConversationReply() 14 | { 15 | var mock = BuildMockClient(HttpStatusCode.OK, "Conversation.json", new Authentication(AppId, AppKey)); 16 | 17 | var convo = mock.Reply(new AdminConversationReply("147", "25", "comment", "We noticed you using our Product, do you have any questions?")); 18 | 19 | Assert.IsNotNull(convo); 20 | Assert.IsTrue(convo.conversation_message.body.Contains("We noticed you using our Product")); 21 | } 22 | 23 | [Test] 24 | public void ListAdminConversations() 25 | { 26 | var mock = BuildSuccessMockClient("ConversationsList.json", new Authentication(AppId, AppKey)); 27 | 28 | var convo = mock.List(new Admin() { id = "394051" }); 29 | 30 | Assert.IsNotNull(convo); 31 | Assert.AreEqual(1, convo.conversations.Count); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/MetadataTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using Intercom.Core; 4 | using Intercom.Data; 5 | using Intercom.Clients; 6 | using Intercom.Exceptions; 7 | using RestSharp; 8 | using System.Linq; 9 | using RestSharp.Authenticators; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Moq; 13 | 14 | namespace Intercom.Test 15 | { 16 | [TestFixture()] 17 | public class MetadataTest : TestBase 18 | { 19 | public MetadataTest() 20 | { 21 | } 22 | 23 | [Test()] 24 | public void Add_WithNullKey_ThrowException() 25 | { 26 | Metadata metadata = new Metadata(); 27 | 28 | Assert.Throws(() => 29 | { 30 | object obj = null; 31 | metadata.Add(String.Empty, obj); 32 | }); 33 | 34 | Assert.Throws(() => 35 | { 36 | Metadata.RichLink richLink = null; 37 | metadata.Add(String.Empty, richLink); 38 | }); 39 | 40 | Assert.Throws(() => 41 | { 42 | Metadata.MonetaryAmount monetaryAmount = null; 43 | metadata.Add(String.Empty, monetaryAmount); 44 | }); 45 | } 46 | 47 | [Test()] 48 | public void GetMonetaryAmount_WithNullKey_ThrowException() 49 | { 50 | Metadata metadata = new Metadata(); 51 | Assert.Throws(() => metadata.GetMonetaryAmount(null)); 52 | } 53 | 54 | [Test()] 55 | public void GetRichLink_WithNullKey_ThrowException() 56 | { 57 | Metadata metadata = new Metadata(); 58 | Assert.Throws(() => metadata.GetRichLink(null)); 59 | } 60 | 61 | [Test()] 62 | public void GetRichLinks_NoParam_Returns10Entries() 63 | { 64 | Metadata m = new Metadata(); 65 | 66 | for (int i = 0; i < 10; i++) 67 | m.Add(i.ToString(), new Metadata.RichLink(i.ToString(), i.ToString())); 68 | 69 | Assert.AreEqual(10, m.GetRichLinks().Count); 70 | Assert.IsTrue(m.GetRichLinks().Any(rl => rl.url == "1" && rl.value == "1")); 71 | } 72 | 73 | [Test()] 74 | public void GetMonetaryAmounts_NoParam_Returns10Entries() 75 | { 76 | Metadata m = new Metadata(); 77 | 78 | for (int i = 0; i < 10; i++) 79 | m.Add(i.ToString(), new Metadata.MonetaryAmount(i, i.ToString())); 80 | 81 | Assert.AreEqual(10, m.GetMonetaryAmounts().Count); 82 | Assert.IsTrue(m.GetMonetaryAmounts().Any(rl => rl.amount == 1 && rl.currency == "1")); 83 | } 84 | 85 | [Test()] 86 | public void CheckMonetaryAmountEqualRef_NoParam_ShouldNotBeEqual() 87 | { 88 | Metadata m = new Metadata(); 89 | Metadata.MonetaryAmount ma = new Metadata.MonetaryAmount(1, "1"); 90 | 91 | m.Add("1", ma); 92 | Metadata.MonetaryAmount maResult = m.GetMonetaryAmount("1"); 93 | 94 | Assert.AreNotEqual(ma, maResult); 95 | Assert.AreNotSame(ma, maResult); 96 | } 97 | 98 | [Test()] 99 | public void CheckRichLinkEqualRef_NoParam_ShouldNotBeEqual() 100 | { 101 | Metadata m = new Metadata(); 102 | Metadata.RichLink rl = new Metadata.RichLink("1", "1"); 103 | 104 | m.Add("1", rl); 105 | Metadata.RichLink rlResult = m.GetRichLink("1"); 106 | 107 | Assert.AreNotEqual(rl, rlResult); 108 | Assert.AreNotSame(rl, rlResult); 109 | } 110 | 111 | [Test()] 112 | public void GetMetadata_NoParam_Returns10Entries() 113 | { 114 | Metadata m = new Metadata(); 115 | 116 | for (int i = 0; i < 10; i++) 117 | m.Add(i.ToString(), i); 118 | 119 | Assert.AreEqual(10, m.GetMetadata().Count); 120 | Assert.IsTrue(m.GetMetadata().Any(md => md.Value.Equals(1))); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/Responses/Conversation.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "conversation", 3 | "id": "147", 4 | "created_at": 1400850973, 5 | "updated_at": 1400857494, 6 | "waiting_since": 1400857494, 7 | "snoozed_until": null, 8 | "conversation_message": { 9 | "type": "conversation_message", 10 | "subject": "", 11 | "body": "

Hi Alice,

\n\n

We noticed you using our Product, do you have any questions?

\n

- Jane

", 12 | "author": { 13 | "type": "admin", 14 | "id": "25" 15 | }, 16 | "attachments": [ 17 | { 18 | "name": "signature", 19 | "url": "http://example.org/signature.jpg" 20 | } 21 | ] 22 | }, 23 | "user": { 24 | "type": "user", 25 | "id": "536e564f316c83104c000020" 26 | }, 27 | "customers": [ 28 | { 29 | "type": "user", 30 | "id": "58ff3f670f14ab4f1aa83750" 31 | } 32 | ], 33 | "assignee": { 34 | "type": "admin", 35 | "id": "25" 36 | }, 37 | "open": true, 38 | "state": "open", 39 | "read": true, 40 | "conversation_parts": { 41 | "type": "conversation_part.list", 42 | "conversation_parts": [ 43 | //... List of conversation parts 44 | ], 45 | "total_count": 1 46 | }, 47 | "tags": { 48 | "type": "tag.list", 49 | "tags": [] 50 | } 51 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/Responses/ConversationsList.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "conversation.list", 3 | "pages": { 4 | "type": "pages", 5 | "next": "https://api.intercom.io/conversations?per_page=20&page=2", 6 | "page": 1, 7 | "per_page": 20, 8 | "total_pages": 40 9 | }, 10 | "conversations": [ 11 | { 12 | "type": "conversation", 13 | "id": "13257844375", 14 | "created_at": 1507709579, 15 | "updated_at": 1507709579, 16 | "waiting_since": 1507709579, 17 | "snoozed_until": null, 18 | "user": { 19 | "type": "user", 20 | "id": "5813655e889f1c9e64a1155b" 21 | }, 22 | "customers": [ 23 | { 24 | "type": "user", 25 | "id": "5813655e889f1c9e64a1155b" 26 | } 27 | ], 28 | "assignee": { 29 | "type": "nobody_admin", 30 | "id": null 31 | }, 32 | "conversation_message": { 33 | "type": "conversation_message", 34 | "id": "139303349", 35 | "subject": "", 36 | "body": "

test msg

", 37 | "author": { 38 | "type": "user", 39 | "id": "5813655e889f1c9e64a1155b" 40 | }, 41 | "attachments": [], 42 | "url": "https://test.com/index.html" 43 | }, 44 | "open": true, 45 | "state": "open", 46 | "read": true 47 | } 48 | ] 49 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/UserConversationMessageTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Intercom.Test 4 | { 5 | // TODO: write tests for UserConversationMessage 6 | public class UserConversationMessageTest 7 | { 8 | public UserConversationMessageTest() 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Data/UserConversationReplyTest.cs: -------------------------------------------------------------------------------- 1 | using Intercom.Clients; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using NUnit.Framework; 5 | 6 | namespace Intercom.Test 7 | { 8 | [TestFixture] 9 | public class UserConversationReplyTest : TestBase 10 | { 11 | public UserConversationReplyTest() 12 | { 13 | } 14 | 15 | [Test] 16 | public void UserConverstationReply() 17 | { 18 | var mock = BuildSuccessMockClient("Conversation.json", new Authentication(AppId, AppKey)); 19 | 20 | var convo = mock.Reply(new UserConversationReply("147", "We noticed you using our Product, do you have any questions?", "536e564f316c83104c000020")); 21 | 22 | Assert.IsNotNull(convo); 23 | Assert.IsTrue(convo.conversation_message.body.Contains("We noticed you using our Product")); 24 | } 25 | 26 | [Test] 27 | public void ListUserConversations() 28 | { 29 | var mock = BuildSuccessMockClient("ConversationsList.json", new Authentication(AppId, AppKey)); 30 | 31 | var convo = mock.List("536e564f316c83104c000020"); 32 | 33 | Assert.IsNotNull(convo); 34 | Assert.AreEqual(1, convo.conversations.Count); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Intercom.Tests/Intercom.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0;net452 5 | 3.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Always 22 | 23 | 24 | Always 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Intercom.Tests/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using RestSharp; 4 | using System.Net; 5 | using Newtonsoft.Json; 6 | using Moq; 7 | using Moq.Protected; 8 | using System.IO; 9 | using NUnit.Framework; 10 | 11 | namespace Intercom.Test 12 | { 13 | public class TestBase 14 | { 15 | protected String AppId = "DEFAULT"; 16 | protected String AppKey = "DEFAULT"; 17 | 18 | public TestBase() 19 | { 20 | } 21 | 22 | 23 | private static IRestClient MockRestClient(HttpStatusCode httpStatusCode, string jsonFile) where T : new() 24 | { 25 | var json = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "Responses", jsonFile)); 26 | var data = JsonConvert.DeserializeObject(json); 27 | var response = new Mock>(); 28 | response.Setup(_ => _.StatusCode).Returns(httpStatusCode); 29 | response.Setup(_ => _.Data).Returns(data); 30 | response.Setup(_ => _.Content).Returns(json); 31 | 32 | var mockIRestClient = new Mock(); 33 | mockIRestClient 34 | .Setup(x => x.Execute(It.IsAny())) 35 | .Returns(response.Object); 36 | 37 | return mockIRestClient.Object; 38 | } 39 | 40 | protected static TClient BuildMockClient(HttpStatusCode httpStatusCode, string jsonResultFile, params object[] ctorArgs) where TResult : new() where TClient : Client 41 | { 42 | var result = MockRestClient(httpStatusCode, jsonResultFile); 43 | var mock = new Mock(ctorArgs) { CallBase = true }; 44 | mock.Protected().Setup("BuildClient").Returns(result); 45 | return mock.Object; 46 | } 47 | 48 | protected static TClient BuildSuccessMockClient(string jsonResultFile, params object[] ctorArgs) where TResult : new() where TClient : Client 49 | { 50 | return BuildMockClient(HttpStatusCode.OK, jsonResultFile, ctorArgs); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/Intercom.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom", "Intercom\Intercom.csproj", "{0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intercom.Tests", "Intercom.Tests\Intercom.Tests.csproj", "{8A0A6B10-7A58-450F-ADBF-3B54EDE109A1}" 7 | EndProject 8 | Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "Intercom.Tests.Integration", "Intercom.Tests.Integration\Intercom.Tests.Integration.csproj", "{83F213FE-B649-45A3-B80D-23CF4AEFB3B5}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {0142B11B-ED7D-45B4-B9F5-B16CF5DB814C}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {8A0A6B10-7A58-450F-ADBF-3B54EDE109A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {8A0A6B10-7A58-450F-ADBF-3B54EDE109A1}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {8A0A6B10-7A58-450F-ADBF-3B54EDE109A1}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {8A0A6B10-7A58-450F-ADBF-3B54EDE109A1}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {83F213FE-B649-45A3-B80D-23CF4AEFB3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {83F213FE-B649-45A3-B80D-23CF4AEFB3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {83F213FE-B649-45A3-B80D-23CF4AEFB3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {83F213FE-B649-45A3-B80D-23CF4AEFB3B5}.Release|Any CPU.Build.0 = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(MonoDevelopProperties) = preSolution 30 | version = 2.0.0 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /src/Intercom/Clients/AdminConversationsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Clients 14 | { 15 | public class AdminConversationsClient: Client 16 | { 17 | private const String CONVERSATIONS_RESOURCE = "conversations"; 18 | private const String MESSAGES_RESOURCE = "messages"; 19 | private const String REPLY_RESOURCE = "reply"; 20 | 21 | public AdminConversationsClient(RestClientFactory restClientFactory) 22 | : base(CONVERSATIONS_RESOURCE, restClientFactory) 23 | { 24 | } 25 | 26 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use AdminConversationsClient(RestClientFactory restClientFactory)")] 27 | public AdminConversationsClient(Authentication authentication) 28 | : base(INTERCOM_API_BASE_URL, CONVERSATIONS_RESOURCE, authentication) 29 | { 30 | } 31 | 32 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use AdminConversationsClient(RestClientFactory restClientFactory)")] 33 | public AdminConversationsClient(String intercomApiUrl, Authentication authentication) 34 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, CONVERSATIONS_RESOURCE, authentication) 35 | { 36 | } 37 | 38 | public Conversation Reply(AdminConversationReply reply) 39 | { 40 | if (reply == null) 41 | { 42 | throw new ArgumentNullException(nameof(reply)); 43 | } 44 | 45 | ClientResponse result = null; 46 | String body = Serialize(reply); 47 | result = Post(body, resource: CONVERSATIONS_RESOURCE + Path.DirectorySeparatorChar + reply.conversation_id + Path.DirectorySeparatorChar + REPLY_RESOURCE); 48 | return result.Result; 49 | } 50 | 51 | public AdminConversationMessage Create(AdminConversationMessage adminMessage) 52 | { 53 | if (adminMessage == null) 54 | { 55 | throw new ArgumentNullException(nameof(adminMessage)); 56 | } 57 | 58 | ClientResponse result = null; 59 | result = Post(adminMessage, resource: MESSAGES_RESOURCE); 60 | return result.Result; 61 | } 62 | 63 | public Conversations List(Admin admin, bool? open = null, bool? displayAsPlainText = null) 64 | { 65 | if (admin == null) 66 | { 67 | throw new ArgumentNullException(nameof(admin)); 68 | } 69 | 70 | if (String.IsNullOrEmpty(admin.id)) 71 | { 72 | throw new ArgumentException("'admin.id' argument is null or empty."); 73 | } 74 | 75 | ClientResponse result = null; 76 | 77 | Dictionary parameters = new Dictionary(); 78 | parameters.Add(Constants.TYPE, Constants.ADMIN); 79 | 80 | if (open != null && open.HasValue) 81 | { 82 | parameters.Add(Constants.OPEN, open.Value.ToString()); 83 | } 84 | 85 | if (displayAsPlainText != null && displayAsPlainText.HasValue) 86 | { 87 | parameters.Add(Constants.DISPLAY_AS, Constants.PLAIN_TEXT); 88 | } 89 | 90 | parameters.Add(Constants.ADMIN_ID, admin.id); 91 | 92 | result = Get(parameters: parameters); 93 | return result.Result; 94 | } 95 | 96 | public Conversation ReplyLastConversation(AdminLastConversationReply lastConversationReply) 97 | { 98 | if (lastConversationReply.intercom_user_id == null) 99 | { 100 | throw new ArgumentNullException(nameof(lastConversationReply.intercom_user_id)); 101 | } 102 | 103 | ClientResponse result = null; 104 | String body = Serialize(lastConversationReply); 105 | result = Post(body, resource: CONVERSATIONS_RESOURCE + Path.DirectorySeparatorChar + "last" + Path.DirectorySeparatorChar + REPLY_RESOURCE); 106 | return result.Result; 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/AdminsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Clients 14 | { 15 | public class AdminsClient : Client 16 | { 17 | private const String ADMINS_RESOURCE = "admins"; 18 | 19 | public AdminsClient (RestClientFactory restClientFactory) 20 | : base (ADMINS_RESOURCE, restClientFactory) 21 | { 22 | } 23 | 24 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use AdminsClient(RestClientFactory restClientFactory)")] 25 | public AdminsClient(Authentication authentication) 26 | : base(INTERCOM_API_BASE_URL, ADMINS_RESOURCE, authentication) 27 | { 28 | } 29 | 30 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use AdminsClient(RestClientFactory restClientFactory)")] 31 | public AdminsClient(String intercomApiUrl, Authentication authentication) 32 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, ADMINS_RESOURCE, authentication) 33 | { 34 | } 35 | 36 | public Admins List () 37 | { 38 | ClientResponse result = null; 39 | result = Get (); 40 | return result.Result; 41 | } 42 | 43 | public Admins List (Dictionary parameters) 44 | { 45 | if (parameters == null) 46 | { 47 | throw new ArgumentNullException (nameof(parameters)); 48 | } 49 | 50 | if (!parameters.Any()) 51 | { 52 | throw new ArgumentException ("'parameters' argument is empty."); 53 | } 54 | 55 | ClientResponse result = null; 56 | result = Get (); 57 | return result.Result; 58 | } 59 | 60 | public Admin View (String id) 61 | { 62 | if (String.IsNullOrEmpty(id)) 63 | { 64 | throw new ArgumentNullException (nameof(id)); 65 | } 66 | 67 | ClientResponse result = null; 68 | result = Get (resource: ADMINS_RESOURCE + Path.DirectorySeparatorChar + id); 69 | return result.Result; 70 | } 71 | 72 | public Admin View(Admin admin) 73 | { 74 | if (admin == null) { 75 | throw new ArgumentNullException (nameof(admin)); 76 | } 77 | 78 | if (String.IsNullOrEmpty(admin.id)) 79 | { 80 | throw new ArgumentException ("you must provide value for 'admin.id'."); 81 | } 82 | 83 | ClientResponse result = null; 84 | result = Get (resource: ADMINS_RESOURCE + Path.DirectorySeparatorChar + admin.id); 85 | return result.Result; 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/CompanyClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Core; 6 | using Intercom.Data; 7 | using Intercom.Factories; 8 | using Newtonsoft.Json; 9 | 10 | namespace Intercom.Clients 11 | { 12 | // TODO: List companies by Tag or Segment 13 | public class CompanyClient : Client 14 | { 15 | private const String COMPANIES_RESOURCE = "companies"; 16 | 17 | public CompanyClient(RestClientFactory restClientFactory) 18 | : base(COMPANIES_RESOURCE, restClientFactory) 19 | { 20 | } 21 | 22 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use CompanyClient(RestClientFactory restClientFactory)")] 23 | public CompanyClient(Authentication authentication) 24 | : base(INTERCOM_API_BASE_URL, COMPANIES_RESOURCE, authentication) 25 | { 26 | } 27 | 28 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use CompanyClient(RestClientFactory restClientFactory)")] 29 | public CompanyClient(String intercomApiUrl, Authentication authentication) 30 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, COMPANIES_RESOURCE, authentication) 31 | { 32 | } 33 | 34 | public Company Create(Company company) 35 | { 36 | return CreateOrUpdate(company); 37 | } 38 | 39 | public Company Update(Company company) 40 | { 41 | return CreateOrUpdate(company); 42 | } 43 | 44 | private Company CreateOrUpdate(Company company) 45 | { 46 | if (company == null) 47 | { 48 | throw new ArgumentNullException(nameof(company)); 49 | } 50 | 51 | if (company.custom_attributes != null && company.custom_attributes.Any()) 52 | { 53 | if (company.custom_attributes.Count > 100) 54 | throw new ArgumentException("Maximum of 100 fields."); 55 | 56 | foreach (var attr in company.custom_attributes) 57 | { 58 | if (attr.Key.Contains(".") || attr.Key.Contains("$")) 59 | throw new ArgumentException(String.Format("Field names must not contain Periods (.) or Dollar ($) characters. key: {0}", attr.Key)); 60 | 61 | if (attr.Key.Length > 190) 62 | throw new ArgumentException(String.Format("Field names must be no longer than 190 characters. key: {0}", attr.Key)); 63 | 64 | if (attr.Value == null) 65 | throw new ArgumentException(String.Format("'value' is null. key: {0}", attr.Key)); 66 | } 67 | } 68 | 69 | ClientResponse result = null; 70 | result = Post(Transform(company)); 71 | return result.Result; 72 | } 73 | 74 | public Company View(String id) 75 | { 76 | if (String.IsNullOrEmpty(id)) 77 | { 78 | throw new ArgumentNullException(nameof(id)); 79 | } 80 | ClientResponse result = null; 81 | result = Get(resource: COMPANIES_RESOURCE + Path.DirectorySeparatorChar + id); 82 | return result.Result; 83 | } 84 | 85 | public Company View(Company company) 86 | { 87 | if (company == null) 88 | { 89 | throw new ArgumentNullException(nameof(company)); 90 | } 91 | 92 | Dictionary parameters = new Dictionary(); 93 | ClientResponse result = null; 94 | 95 | if (!String.IsNullOrEmpty(company.id)) 96 | { 97 | result = Get(resource: COMPANIES_RESOURCE + Path.DirectorySeparatorChar + company.id); 98 | } 99 | else if (!String.IsNullOrEmpty(company.name)) 100 | { 101 | parameters.Add(Constants.NAME, company.name); 102 | result = Get(parameters: parameters); 103 | } 104 | else if (!String.IsNullOrEmpty(company.company_id)) 105 | { 106 | parameters.Add(Constants.COMPANY_ID, company.company_id); 107 | result = Get(parameters: parameters); 108 | } 109 | else 110 | { 111 | throw new ArgumentException("you need to provide either 'company.id', 'company.company_id' to view a company."); 112 | } 113 | return result.Result; 114 | } 115 | 116 | public Companies List() 117 | { 118 | ClientResponse result = null; 119 | result = Get(); 120 | return result.Result; 121 | } 122 | 123 | public Companies List(Dictionary parameters) 124 | { 125 | if (parameters == null) 126 | { 127 | throw new ArgumentNullException(nameof(parameters)); 128 | } 129 | 130 | if (!parameters.Any()) 131 | { 132 | throw new ArgumentException("'parameters' argument is empty."); 133 | } 134 | 135 | ClientResponse result = null; 136 | result = Get(parameters: parameters); 137 | return result.Result; 138 | } 139 | 140 | public Companies Scroll(String scrollParam = null) 141 | { 142 | Dictionary parameters = new Dictionary(); 143 | ClientResponse result = null; 144 | 145 | if (!String.IsNullOrWhiteSpace(scrollParam)) 146 | { 147 | parameters.Add("scroll_param", scrollParam); 148 | } 149 | 150 | result = Get(parameters: parameters, resource: COMPANIES_RESOURCE + Path.DirectorySeparatorChar + "scroll"); 151 | return result.Result; 152 | } 153 | 154 | public Users ListUsers(Company company) 155 | { 156 | if (company == null) 157 | { 158 | throw new ArgumentNullException(nameof(company)); 159 | } 160 | 161 | Dictionary parameters = new Dictionary(); 162 | ClientResponse result = null; 163 | 164 | if (!String.IsNullOrEmpty(company.id)) 165 | { 166 | String resource = company.id + Path.DirectorySeparatorChar + "users"; 167 | result = Get(resource: COMPANIES_RESOURCE + Path.DirectorySeparatorChar + resource); 168 | } 169 | else if (!String.IsNullOrEmpty(company.company_id)) 170 | { 171 | parameters.Add(Constants.TYPE, Constants.USER); 172 | parameters.Add(Constants.COMPANY_ID, company.company_id); 173 | result = Get(parameters: parameters); 174 | } 175 | else 176 | { 177 | throw new ArgumentException("you need to provide either 'company.id', 'company.company_id' to list users of a company."); 178 | } 179 | 180 | return result.Result; 181 | } 182 | 183 | public Users ListUsers(String companyId) 184 | { 185 | if (String.IsNullOrEmpty(companyId)) 186 | { 187 | throw new ArgumentNullException(nameof(companyId)); 188 | } 189 | 190 | String resource = companyId + Path.DirectorySeparatorChar + "users"; 191 | ClientResponse result = null; 192 | result = Get(resource: COMPANIES_RESOURCE + Path.DirectorySeparatorChar + resource); 193 | return result.Result; 194 | } 195 | 196 | private String Transform(Company company) 197 | { 198 | var body = new 199 | { 200 | remote_created_at = company.remote_created_at, 201 | company_id = company.company_id, 202 | name = company.name, 203 | monthly_spend = company.monthly_spend, 204 | custom_attributes = company.custom_attributes, 205 | plan = company.plan != null ? company.plan.name : null, 206 | website = company.website, 207 | size = company.size, 208 | industry = company.industry 209 | }; 210 | 211 | return JsonConvert.SerializeObject(body, 212 | Formatting.None, 213 | new JsonSerializerSettings 214 | { 215 | NullValueHandling = NullValueHandling.Ignore 216 | }); 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/Intercom/Clients/ContactsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Intercom.Core; 6 | using Intercom.Data; 7 | using Intercom.Factories; 8 | using Newtonsoft.Json; 9 | 10 | namespace Intercom.Clients 11 | { 12 | public class ContactsClient : Client 13 | { 14 | public static class ContactSortBy 15 | { 16 | public const String created_at = "created_at"; 17 | public const String updated_at = "updated_at"; 18 | public const String signed_up_at = "signed_up_at"; 19 | } 20 | 21 | private const String CONTACTS_RESOURCE = "contacts"; 22 | 23 | public ContactsClient (RestClientFactory restClientFactory) 24 | : base (CONTACTS_RESOURCE, restClientFactory) 25 | { 26 | } 27 | 28 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use ContactsClient(RestClientFactory restClientFactory)")] 29 | public ContactsClient(Authentication authentication) 30 | : base(INTERCOM_API_BASE_URL, CONTACTS_RESOURCE, authentication) 31 | { 32 | } 33 | 34 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use ContactsClient(RestClientFactory restClientFactory)")] 35 | public ContactsClient(String intercomApiUrl, Authentication authentication) 36 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, CONTACTS_RESOURCE, authentication) 37 | { 38 | } 39 | 40 | public Contact Create (Contact contact) 41 | { 42 | if (contact == null) { 43 | throw new ArgumentNullException (nameof(contact)); 44 | } 45 | 46 | ClientResponse result = null; 47 | 48 | if(contact == null) 49 | result = Post (String.Empty); 50 | else 51 | result = Post (contact); 52 | 53 | return result.Result; 54 | } 55 | 56 | public Contact Update (Contact contact) 57 | { 58 | if (contact == null) { 59 | throw new ArgumentNullException (nameof(contact)); 60 | } 61 | 62 | if (String.IsNullOrEmpty(contact.id) && String.IsNullOrEmpty(contact.user_id)) 63 | { 64 | throw new ArgumentException("you need to provide either 'id', 'user_id', 'email' to view a user."); 65 | } 66 | 67 | ClientResponse result = null; 68 | result = Post (contact); 69 | return result.Result; 70 | } 71 | 72 | public Contact View (String id) 73 | { 74 | if (String.IsNullOrEmpty (id)) { 75 | throw new ArgumentNullException (nameof(id)); 76 | } 77 | 78 | ClientResponse result = null; 79 | result = Get (resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + id); 80 | return result.Result; 81 | } 82 | 83 | public Contact View (Contact contact) 84 | { 85 | if (contact == null) { 86 | throw new ArgumentNullException (nameof(contact)); 87 | } 88 | 89 | Dictionary parameters = new Dictionary (); 90 | ClientResponse result = null; 91 | 92 | if (!String.IsNullOrEmpty (contact.id)) { 93 | result = Get (resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + contact.id); 94 | } else if (!String.IsNullOrEmpty (contact.user_id)) { 95 | parameters.Add (Constants.USER_ID, contact.user_id); 96 | result = Get (parameters: parameters); 97 | } else { 98 | throw new ArgumentException ("you need to provide either 'contact.id', 'contact.user_id' to view a contact."); 99 | } 100 | 101 | return result.Result; 102 | } 103 | 104 | public Contacts List () 105 | { 106 | ClientResponse result = null; 107 | result = Get (); 108 | return result.Result; 109 | } 110 | 111 | public Contacts List(String email) 112 | { 113 | if (String.IsNullOrEmpty(email)) { 114 | throw new ArgumentNullException (nameof(email)); 115 | } 116 | 117 | Dictionary parameters = new Dictionary(); 118 | parameters.Add(Constants.EMAIL, email); 119 | 120 | ClientResponse result = null; 121 | result = Get (parameters: parameters); 122 | return result.Result; 123 | } 124 | 125 | public Contacts List(Dictionary parameters) 126 | { 127 | if (parameters == null) 128 | { 129 | throw new ArgumentNullException(nameof(parameters)); 130 | } 131 | 132 | if (!parameters.Any()) 133 | { 134 | throw new ArgumentException ("'parameters' argument is empty."); 135 | } 136 | 137 | ClientResponse result = null; 138 | result = Get(parameters: parameters); 139 | return result.Result; 140 | } 141 | 142 | public Contacts Scroll(String scrollParam = null) 143 | { 144 | Dictionary parameters = new Dictionary(); 145 | if (!String.IsNullOrWhiteSpace(scrollParam)) 146 | { 147 | parameters.Add("scroll_param", scrollParam); 148 | } 149 | 150 | ClientResponse result = null; 151 | result = Get(parameters: parameters, resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + "scroll"); 152 | return result.Result; 153 | } 154 | 155 | public Contact Delete (Contact contact) 156 | { 157 | if (contact == null) { 158 | throw new ArgumentNullException (nameof(contact)); 159 | } 160 | 161 | Dictionary parameters = new Dictionary (); 162 | ClientResponse result = null; 163 | 164 | if (!String.IsNullOrEmpty (contact.id)) { 165 | result = Delete (resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + contact.id); 166 | } else if (!String.IsNullOrEmpty (contact.user_id)) { 167 | parameters.Add (Constants.USER_ID, contact.user_id); 168 | result = Delete (parameters: parameters); 169 | } else { 170 | throw new ArgumentException ("you need to provide either 'contact.id', 'contact.user_id' to delete a contact."); 171 | } 172 | 173 | return result.Result; 174 | } 175 | 176 | public Contact Delete (String id) 177 | { 178 | if (String.IsNullOrEmpty (id)) { 179 | throw new ArgumentNullException (nameof(id)); 180 | } 181 | 182 | ClientResponse result = null; 183 | result = Delete (resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + id); 184 | return result.Result; 185 | } 186 | 187 | public User Convert (Contact contact) 188 | { 189 | if (contact == null) 190 | throw new ArgumentNullException ("'contact' argument is null."); 191 | 192 | if (String.IsNullOrEmpty (contact.id) && String.IsNullOrEmpty (contact.user_id)) 193 | throw new ArgumentException ("you need to provide either 'contact.id', 'contact.user_id' to convert a lead."); 194 | 195 | Dictionary contactBody = new Dictionary (); 196 | 197 | if (!String.IsNullOrEmpty (contact.id)) { 198 | contactBody.Add ("id", contact.id); 199 | } else { 200 | contactBody.Add ("user_id", contact.user_id); 201 | } 202 | 203 | var body = new { contact = contactBody }; 204 | 205 | var jsonBody = JsonConvert.SerializeObject (body, 206 | Formatting.None, 207 | new JsonSerializerSettings { 208 | NullValueHandling = NullValueHandling.Ignore 209 | }); 210 | 211 | var result = Post (jsonBody, resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + "convert"); 212 | 213 | return result.Result; 214 | } 215 | 216 | public User Convert (Contact contact, User user) 217 | { 218 | if (contact == null) 219 | throw new ArgumentNullException ("'contact' argument is null."); 220 | 221 | if (user == null) 222 | throw new ArgumentNullException ("'user' argument is null."); 223 | 224 | if (String.IsNullOrEmpty (contact.id) && String.IsNullOrEmpty (contact.user_id)) 225 | throw new ArgumentException ("you need to provide either 'contact.id', 'contact.user_id' to convert a lead."); 226 | 227 | if (String.IsNullOrEmpty (user.id) && String.IsNullOrEmpty (user.user_id) && String.IsNullOrEmpty (user.email)) 228 | throw new ArgumentException ("you need to provide either 'user.id', 'user.user_id', or 'user.email' to convert a lead."); 229 | 230 | Dictionary contactBody = new Dictionary (); 231 | Dictionary userBody = new Dictionary (); 232 | 233 | if (!String.IsNullOrEmpty (user.id)) { 234 | userBody.Add ("id", user.id); 235 | } 236 | else if (!String.IsNullOrEmpty (user.user_id)) { 237 | userBody.Add ("user_id", user.user_id); 238 | } 239 | else { 240 | userBody.Add ("email", user.email); 241 | } 242 | 243 | if (!String.IsNullOrEmpty (contact.id)) { 244 | contactBody.Add ("id", contact.id); 245 | } else { 246 | contactBody.Add ("user_id", contact.user_id); 247 | } 248 | 249 | var body = new { contact = contactBody, user = userBody }; 250 | 251 | var jsonBody = JsonConvert.SerializeObject (body, 252 | Formatting.None, 253 | new JsonSerializerSettings { 254 | NullValueHandling = NullValueHandling.Ignore 255 | }); 256 | 257 | var result = Post (jsonBody, resource: CONTACTS_RESOURCE + Path.DirectorySeparatorChar + "convert" ); 258 | 259 | return result.Result; 260 | } 261 | } 262 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/ConversationsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Clients 14 | { 15 | public class ConversationsClient : Client 16 | { 17 | public static class MessageType 18 | { 19 | public const String ASSIGNMENT = "assignment"; 20 | public const String COMMENT = "comment"; 21 | public const String CLOSE = "close"; 22 | public const String OPEN = "open"; 23 | public const String NOTE = "note"; 24 | } 25 | 26 | private const String CONVERSATIONS_RESOURCE = "conversations"; 27 | 28 | public ConversationsClient( RestClientFactory restClientFactory) 29 | : base(CONVERSATIONS_RESOURCE, restClientFactory) 30 | { 31 | } 32 | 33 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use ConversationsClient(RestClientFactory restClientFactory)")] 34 | public ConversationsClient(Authentication authentication) 35 | : base(INTERCOM_API_BASE_URL, CONVERSATIONS_RESOURCE, authentication) 36 | { 37 | } 38 | 39 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use ConversationsClient(RestClientFactory restClientFactory)")] 40 | public ConversationsClient(String intercomApiUrl, Authentication authentication) 41 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, CONVERSATIONS_RESOURCE, authentication) 42 | { 43 | } 44 | 45 | public Conversation View(String id, bool? displayAsPlainText = null) 46 | { 47 | if (String.IsNullOrEmpty(id)) 48 | { 49 | throw new ArgumentNullException(nameof(id)); 50 | } 51 | 52 | Dictionary parameters = new Dictionary(); 53 | 54 | if (displayAsPlainText != null && displayAsPlainText.HasValue) 55 | { 56 | parameters.Add(Constants.DISPLAY_AS, Constants.PLAIN_TEXT); 57 | } 58 | 59 | ClientResponse result = null; 60 | result = Get(resource: CONVERSATIONS_RESOURCE + Path.DirectorySeparatorChar + id); 61 | return result.Result; 62 | } 63 | 64 | public Conversations ListAll () 65 | { 66 | ClientResponse result = null; 67 | result = Get(resource: CONVERSATIONS_RESOURCE, parameters: null); 68 | return result.Result; 69 | } 70 | 71 | public Conversations ListAll(Dictionary parameters) 72 | { 73 | if (parameters == null) 74 | { 75 | throw new ArgumentNullException(nameof(parameters)); 76 | } 77 | 78 | ClientResponse result = null; 79 | result = Get(resource: CONVERSATIONS_RESOURCE, parameters: parameters); 80 | return result.Result; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Intercom/Clients/CountsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Clients 14 | { 15 | public class CountsClient: Client 16 | { 17 | private const String COUNTS_RESOURCE = "counts"; 18 | 19 | public CountsClient (RestClientFactory restClientFactory) 20 | : base (COUNTS_RESOURCE, restClientFactory) 21 | { 22 | } 23 | 24 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use CountsClient(RestClientFactory restClientFactory)")] 25 | public CountsClient(Authentication authentication) 26 | : base(INTERCOM_API_BASE_URL, COUNTS_RESOURCE, authentication) 27 | { 28 | } 29 | 30 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use CountsClient(RestClientFactory restClientFactory)")] 31 | public CountsClient(String intercomApiUrl, Authentication authentication) 32 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, COUNTS_RESOURCE, authentication) 33 | { 34 | } 35 | 36 | public AppCount GetAppCount() 37 | { 38 | ClientResponse result = null; 39 | result = Get(); 40 | return result.Result; 41 | } 42 | 43 | public ConversationAppCount GetConversationAppCount() 44 | { 45 | Dictionary parameters = new Dictionary(); 46 | parameters.Add(Constants.TYPE, Constants.CONVERSATION); 47 | 48 | ClientResponse result = null; 49 | result = Get(parameters: parameters); 50 | return result.Result; 51 | } 52 | 53 | public ConversationAdminCount GetConversationAdminCount() 54 | { 55 | Dictionary parameters = new Dictionary(); 56 | parameters.Add(Constants.TYPE, Constants.CONVERSATION); 57 | parameters.Add(Constants.COUNT, Constants.ADMIN); 58 | 59 | ClientResponse result = null; 60 | result = Get(parameters: parameters); 61 | return result.Result; 62 | } 63 | 64 | public UserTagCount GetUserTagCount() 65 | { 66 | Dictionary parameters = new Dictionary(); 67 | parameters.Add(Constants.TYPE, Constants.USER); 68 | parameters.Add(Constants.COUNT, Constants.TAG); 69 | 70 | ClientResponse result = null; 71 | result = Get(parameters: parameters); 72 | return result.Result; 73 | } 74 | 75 | public UserSegmentCount GetUserSegmentCount() 76 | { 77 | Dictionary parameters = new Dictionary(); 78 | parameters.Add(Constants.TYPE, Constants.USER); 79 | parameters.Add(Constants.COUNT, Constants.SEGMENT); 80 | 81 | ClientResponse result = null; 82 | result = Get(parameters: parameters); 83 | return result.Result; 84 | } 85 | 86 | public CompanySegmentCount GetCompanySegmentCount() 87 | { 88 | Dictionary parameters = new Dictionary(); 89 | parameters.Add(Constants.TYPE, Constants.COMPANY); 90 | parameters.Add(Constants.COUNT, Constants.SEGMENT); 91 | 92 | ClientResponse result = null; 93 | result = Get(parameters: parameters); 94 | return result.Result; 95 | } 96 | 97 | public CompanyTagCount GetCompanyTagCount() 98 | { 99 | Dictionary parameters = new Dictionary(); 100 | parameters.Add(Constants.TYPE, Constants.COMPANY); 101 | parameters.Add(Constants.COUNT, Constants.TAG); 102 | 103 | ClientResponse result = null; 104 | result = Get(parameters: parameters); 105 | return result.Result; 106 | } 107 | 108 | public CompanyUserCount GetCompanyUserCount() 109 | { 110 | Dictionary parameters = new Dictionary(); 111 | parameters.Add(Constants.TYPE, Constants.COMPANY); 112 | parameters.Add(Constants.COUNT, Constants.USER); 113 | 114 | ClientResponse result = null; 115 | result = Get(parameters: parameters); 116 | return result.Result; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/EventClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Clients 14 | { 15 | public class EventsClient : Client 16 | { 17 | private const String EVENTS_RESOURCE = "events"; 18 | 19 | public EventsClient (RestClientFactory restClientFactory) 20 | : base (EVENTS_RESOURCE, restClientFactory) 21 | { 22 | } 23 | 24 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use EventsClient(RestClientFactory restClientFactory)")] 25 | public EventsClient(Authentication authentication) 26 | : base(INTERCOM_API_BASE_URL, EVENTS_RESOURCE, authentication) 27 | { 28 | } 29 | 30 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use EventsClient(RestClientFactory restClientFactory)")] 31 | public EventsClient(String intercomApiUrl, Authentication authentication) 32 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, EVENTS_RESOURCE, authentication) 33 | { 34 | } 35 | 36 | public Event Create (Event @event) 37 | { 38 | if (@event == null) 39 | { 40 | throw new ArgumentNullException (nameof(@event)); 41 | } 42 | 43 | if (String.IsNullOrEmpty(@event.event_name)) 44 | { 45 | throw new ArgumentException ("'event_name' argument is null or empty."); 46 | } 47 | 48 | if (!@event.created_at.HasValue) 49 | { 50 | throw new ArgumentException ("'created_at' argument must have value."); 51 | } 52 | 53 | ClientResponse result = null; 54 | result = Post (@event); 55 | return result.Result; 56 | } 57 | 58 | public Events List (User user) 59 | { 60 | Dictionary parameters = new Dictionary (); 61 | parameters.Add (Constants.TYPE, "user"); 62 | 63 | ClientResponse result = null; 64 | 65 | if (!String.IsNullOrEmpty (user.id)) { 66 | parameters.Add (Constants.INTERCOM_USER_ID, user.id); 67 | } else if (!String.IsNullOrEmpty (user.user_id)) { 68 | parameters.Add (Constants.USER_ID, user.user_id); 69 | } else if (!String.IsNullOrEmpty (user.email)) { 70 | parameters.Add (Constants.EMAIL, user.email); 71 | } else { 72 | throw new ArgumentException (String.Format ("you should provide at least value for one of these parameters {0}, or {1}, or {2} .", Constants.INTERCOM_USER_ID, Constants.USER_ID, Constants.EMAIL)); 73 | } 74 | 75 | result = Get (parameters: parameters); 76 | return result.Result; 77 | } 78 | 79 | public Events List (Dictionary parameters) 80 | { 81 | if (parameters == null) { 82 | throw new ArgumentNullException (nameof(parameters)); 83 | } 84 | 85 | if (!parameters.Any ()) { 86 | throw new ArgumentException ("'parameters' argument should include at least one parameter key, value."); 87 | } 88 | 89 | if (!parameters.ContainsKey (Constants.INTERCOM_USER_ID) && 90 | !parameters.ContainsKey (Constants.USER_ID) && 91 | !parameters.ContainsKey (Constants.EMAIL)) { 92 | throw new ArgumentException (String.Format ("'parameters' argument should include at least {0}, or {1}, or {2} parameter.", Constants.INTERCOM_USER_ID, Constants.USER_ID, Constants.EMAIL)); 93 | } 94 | 95 | if (!parameters.Contains (new KeyValuePair (Constants.TYPE, "user"))) { 96 | parameters.Add (Constants.TYPE, "user"); 97 | } 98 | 99 | ClientResponse result = null; 100 | result = Get (parameters: parameters); 101 | return result.Result; 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/NotesClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Clients; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Intercom.Factories; 11 | using Newtonsoft.Json; 12 | using RestSharp; 13 | using RestSharp.Authenticators; 14 | 15 | namespace Intercom.Clients 16 | { 17 | public class NotesClient : Client 18 | { 19 | private const String NOTES_RESOURCE = "notes"; 20 | 21 | public NotesClient(RestClientFactory restClientFactory) 22 | : base(NOTES_RESOURCE, restClientFactory) 23 | { 24 | } 25 | 26 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use NotesClient(RestClientFactory restClientFactory)")] 27 | public NotesClient(Authentication authentication) 28 | : base(INTERCOM_API_BASE_URL, NOTES_RESOURCE, authentication) 29 | { 30 | } 31 | 32 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use NotesClient(RestClientFactory restClientFactory)")] 33 | public NotesClient(String intercomApiUrl, Authentication authentication) 34 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, NOTES_RESOURCE, authentication) 35 | { 36 | } 37 | 38 | public Note Create(Note note) 39 | { 40 | if (note == null) 41 | { 42 | throw new ArgumentNullException(nameof(note)); 43 | } 44 | 45 | if (note.user == null) 46 | { 47 | throw new ArgumentException("'note.user' argument is null."); 48 | } 49 | 50 | object u = null; 51 | 52 | if (!String.IsNullOrEmpty(note.user.id)) 53 | u = new { id = note.user.id }; 54 | else if (!String.IsNullOrEmpty(note.user.user_id)) 55 | u = new { user_id = note.user.user_id }; 56 | else if (!String.IsNullOrEmpty(note.user.email)) 57 | u = new { email = note.user.email }; 58 | else 59 | throw new ArgumentException("you need to provide either 'user.id', 'user.user_id', 'user.email' to view a user."); 60 | 61 | if (String.IsNullOrEmpty(note.body)) 62 | { 63 | throw new ArgumentException("'note.body' argument is null or empty."); 64 | } 65 | 66 | if (note.author == null) 67 | { 68 | throw new ArgumentException("'note.author' argument is null."); 69 | } 70 | 71 | if (String.IsNullOrEmpty(note.author.id)) 72 | { 73 | throw new ArgumentException("'note.author.id' argument is null."); 74 | } 75 | 76 | ClientResponse result = null; 77 | 78 | var body = new { 79 | admin_id = note.author.id, 80 | body = note.body, 81 | user = u 82 | }; 83 | 84 | String b = JsonConvert.SerializeObject(body, 85 | Formatting.None, 86 | new JsonSerializerSettings 87 | { 88 | NullValueHandling = NullValueHandling.Ignore 89 | }); 90 | 91 | result = Post(b); 92 | return result.Result; 93 | } 94 | 95 | public Note Create(User user, String body, String adminId = null) 96 | { 97 | if (user == null) 98 | { 99 | throw new ArgumentNullException("user"); 100 | } 101 | 102 | object u = null; 103 | 104 | if (!String.IsNullOrEmpty(user.id)) 105 | u = new { id = user.id }; 106 | else if (!String.IsNullOrEmpty(user.user_id)) 107 | u = new { user_id = user.user_id }; 108 | else if (!String.IsNullOrEmpty(user.email)) 109 | u = new { email = user.email }; 110 | else 111 | throw new ArgumentException("you need to provide either 'user.id', 'user.user_id', 'user.email' to view a user."); 112 | 113 | if (String.IsNullOrEmpty(body)) 114 | { 115 | throw new ArgumentNullException(nameof(body)); 116 | } 117 | 118 | ClientResponse result = null; 119 | 120 | var note = new { 121 | admin_id = adminId, 122 | body = body, 123 | user = u 124 | }; 125 | 126 | String b = JsonConvert.SerializeObject(note, 127 | Formatting.None, 128 | new JsonSerializerSettings 129 | { 130 | NullValueHandling = NullValueHandling.Ignore 131 | }); 132 | 133 | result = Post(b); 134 | 135 | return result.Result; 136 | } 137 | 138 | public Note View(String id) 139 | { 140 | if (String.IsNullOrEmpty(id)) 141 | { 142 | throw new ArgumentNullException(nameof(id)); 143 | } 144 | 145 | ClientResponse result = null; 146 | result = Get(resource: NOTES_RESOURCE + Path.DirectorySeparatorChar + id); 147 | return result.Result; 148 | } 149 | 150 | public Notes List(User user) 151 | { 152 | if (user == null) 153 | { 154 | throw new ArgumentNullException(nameof(user)); 155 | } 156 | 157 | Dictionary parameters = new Dictionary(); 158 | ClientResponse result = null; 159 | 160 | if (!String.IsNullOrEmpty(user.id)) 161 | { 162 | parameters.Add(Constants.ID, user.id); 163 | result = Get(parameters: parameters); 164 | } 165 | else if (!String.IsNullOrEmpty(user.user_id)) 166 | { 167 | parameters.Add(Constants.USER_ID, user.user_id); 168 | result = Get(parameters: parameters); 169 | } 170 | else if (!String.IsNullOrEmpty(user.email)) 171 | { 172 | parameters.Add(Constants.EMAIL, user.email); 173 | result = Get(parameters: parameters); 174 | } 175 | else 176 | { 177 | throw new ArgumentException("you need to provide either 'user.id', 'user.user_id', 'user.email' to view a user."); 178 | } 179 | 180 | return result.Result; 181 | } 182 | 183 | // TODO: Add List function for Notes to allow pagination 184 | } 185 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/SegmentsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Intercom.Factories; 10 | using RestSharp; 11 | 12 | namespace Intercom.Clients 13 | { 14 | public class SegmentsClient: Client 15 | { 16 | private const String SEGMENTS_RESOURCE = "segments"; 17 | 18 | public SegmentsClient(RestClientFactory restClientFactory) 19 | : base(SEGMENTS_RESOURCE, restClientFactory) 20 | { 21 | } 22 | 23 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use SegmentsClient(RestClientFactory restClientFactory)")] 24 | public SegmentsClient(Authentication authentication) 25 | : base(INTERCOM_API_BASE_URL, SEGMENTS_RESOURCE, authentication) 26 | { 27 | } 28 | 29 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use SegmentsClient(RestClientFactory restClientFactory)")] 30 | public SegmentsClient(String intercomApiUrl, Authentication authentication) 31 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, SEGMENTS_RESOURCE, authentication) 32 | { 33 | } 34 | 35 | public Segments List(bool company = false) 36 | { 37 | ClientResponse result = null; 38 | 39 | if (company) 40 | { 41 | Dictionary parameters = new Dictionary(); 42 | parameters.Add(Constants.TYPE, Constants.COMPANY); 43 | result = Get(parameters: parameters); 44 | } 45 | else 46 | { 47 | result = Get(); 48 | } 49 | 50 | return result.Result; 51 | } 52 | 53 | public Segments List(Dictionary parameters) 54 | { 55 | if (parameters == null) 56 | { 57 | throw new ArgumentNullException(nameof(parameters)); 58 | } 59 | 60 | if (!parameters.Any()) 61 | { 62 | throw new ArgumentException ("'parameters' argument is empty."); 63 | } 64 | 65 | ClientResponse result = null; 66 | result = Get(parameters: parameters); 67 | return result.Result; 68 | } 69 | 70 | public Segment View(String id, bool? includeCount = null) 71 | { 72 | if (String.IsNullOrEmpty(id)) 73 | { 74 | throw new ArgumentNullException(nameof(id)); 75 | } 76 | 77 | Dictionary parameters = new Dictionary(); 78 | if (includeCount != null && includeCount.HasValue) 79 | { 80 | parameters.Add("include_count", includeCount.ToString()); 81 | }; 82 | 83 | ClientResponse result = null; 84 | result = Get(parameters: parameters, resource: SEGMENTS_RESOURCE + Path.DirectorySeparatorChar + id); 85 | return result.Result; 86 | } 87 | 88 | public Segment View(Segment segment, bool? includeCount = null) 89 | { 90 | if (segment == null) 91 | { 92 | throw new ArgumentNullException(nameof(segment)); 93 | } 94 | 95 | if (String.IsNullOrEmpty(segment.id)) 96 | { 97 | throw new ArgumentException("you must provide value for 'segment.id'."); 98 | } 99 | 100 | Dictionary parameters = new Dictionary(); 101 | if (includeCount != null && includeCount.HasValue) 102 | { 103 | parameters.Add("include_count", includeCount.ToString()); 104 | }; 105 | 106 | ClientResponse result = null; 107 | result = Get(parameters: parameters, resource: SEGMENTS_RESOURCE + Path.DirectorySeparatorChar + segment.id); 108 | return result.Result; 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/UserConversationsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Clients; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Intercom.Factories; 11 | using RestSharp; 12 | using RestSharp.Authenticators; 13 | 14 | namespace Intercom.Clients 15 | { 16 | public class UserConversationsClient: Client 17 | { 18 | private const String CONVERSATIONS_RESOURCE = "conversations"; 19 | private const String MESSAGES_RESOURCE = "messages"; 20 | private const String REPLY_RESOURCE = "reply"; 21 | 22 | public UserConversationsClient(RestClientFactory restClientFactory) 23 | : base(CONVERSATIONS_RESOURCE, restClientFactory) 24 | { 25 | } 26 | 27 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use UserConversationsClient(RestClientFactory restClientFactory)")] 28 | public UserConversationsClient(Authentication authentication) 29 | : base(INTERCOM_API_BASE_URL, CONVERSATIONS_RESOURCE, authentication) 30 | { 31 | } 32 | 33 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use UserConversationsClient(RestClientFactory restClientFactory)")] 34 | public UserConversationsClient(String intercomApiUrl, Authentication authentication) 35 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, CONVERSATIONS_RESOURCE, authentication) 36 | { 37 | } 38 | 39 | public Conversation Reply(UserConversationReply reply) 40 | { 41 | if (reply == null) 42 | { 43 | throw new ArgumentNullException(nameof(reply)); 44 | } 45 | 46 | ClientResponse result = null; 47 | String body = Serialize(reply); 48 | result = Post(body, resource: CONVERSATIONS_RESOURCE + Path.DirectorySeparatorChar + reply.conversation_id + Path.DirectorySeparatorChar + REPLY_RESOURCE); 49 | return result.Result; 50 | } 51 | 52 | public UserConversationMessage Create(UserConversationMessage userMessage) 53 | { 54 | ClientResponse result = null; 55 | result = Post(userMessage, resource: MESSAGES_RESOURCE); 56 | return result.Result; 57 | } 58 | 59 | public Conversations List( 60 | User user, 61 | bool? unread = null, 62 | bool? displayAsPlainText = null) 63 | { 64 | ClientResponse result = null; 65 | 66 | Dictionary parameters = new Dictionary(); 67 | parameters.Add(Constants.TYPE, Constants.USER); 68 | 69 | if (unread != null && unread.HasValue) 70 | { 71 | parameters.Add(Constants.UNREAD, unread.Value.ToString()); 72 | } 73 | 74 | if (displayAsPlainText != null && displayAsPlainText.HasValue) 75 | { 76 | parameters.Add(Constants.DISPLAY_AS, Constants.PLAIN_TEXT); 77 | } 78 | 79 | if (!String.IsNullOrEmpty(user.id)) 80 | { 81 | parameters.Add(Constants.INTERCOM_USER_ID, user.id); 82 | result = Get(parameters: parameters); 83 | } 84 | else if (!String.IsNullOrEmpty(user.user_id)) 85 | { 86 | parameters.Add(Constants.USER_ID, user.user_id); 87 | result = Get(parameters: parameters); 88 | } 89 | else if (!String.IsNullOrEmpty(user.email)) 90 | { 91 | parameters.Add(Constants.EMAIL, user.email); 92 | result = Get(parameters: parameters); 93 | } 94 | else 95 | { 96 | throw new ArgumentException("you need to provide either 'user.id', 'user.user_id', 'user.email' to view a user."); 97 | } 98 | 99 | result = Get(parameters: parameters); 100 | return result.Result; 101 | } 102 | 103 | public Conversations List( 104 | String intercomUserId = null, 105 | String email = null, 106 | String userId = null, 107 | bool? unread = null, 108 | bool? displayAsPlainText = null) 109 | { 110 | ClientResponse result = null; 111 | 112 | Dictionary parameters = new Dictionary(); 113 | parameters.Add(Constants.TYPE, Constants.USER); 114 | 115 | if (unread != null && unread.HasValue) 116 | { 117 | parameters.Add(Constants.UNREAD, unread.Value.ToString()); 118 | } 119 | 120 | if (displayAsPlainText != null && displayAsPlainText.HasValue) 121 | { 122 | parameters.Add(Constants.DISPLAY_AS, Constants.PLAIN_TEXT); 123 | } 124 | 125 | if (!String.IsNullOrEmpty(intercomUserId)) 126 | { 127 | parameters.Add(Constants.INTERCOM_USER_ID, intercomUserId); 128 | result = Get(parameters: parameters); 129 | } 130 | else if (!String.IsNullOrEmpty(userId)) 131 | { 132 | parameters.Add(Constants.USER_ID, userId); 133 | result = Get(parameters: parameters); 134 | } 135 | else if (!String.IsNullOrEmpty(email)) 136 | { 137 | parameters.Add(Constants.EMAIL, email); 138 | result = Get(parameters: parameters); 139 | } 140 | else 141 | { 142 | throw new ArgumentException("you need to provide either 'id', 'user_id', 'email' to view a user."); 143 | } 144 | 145 | result = Get(parameters: parameters); 146 | return result.Result; 147 | } 148 | } 149 | } -------------------------------------------------------------------------------- /src/Intercom/Clients/VisitorsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Intercom.Clients; 7 | using Intercom.Core; 8 | using Intercom.Data; 9 | using Intercom.Exceptions; 10 | using Intercom.Factories; 11 | using RestSharp; 12 | using RestSharp.Authenticators; 13 | using Newtonsoft.Json; 14 | 15 | namespace Intercom.Clients 16 | { 17 | public class VisitorsClient : Client 18 | { 19 | private const String VISITORS_RESOURCE = "visitors"; 20 | private const String VISITORS_CONVERT = "convert"; 21 | 22 | public VisitorsClient(RestClientFactory restClientFactory) 23 | : base(VISITORS_RESOURCE, restClientFactory) 24 | { 25 | } 26 | 27 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use VisitorsClient(RestClientFactory restClientFactory)")] 28 | public VisitorsClient(Authentication authentication) 29 | : base(INTERCOM_API_BASE_URL, VISITORS_RESOURCE, authentication) 30 | { 31 | } 32 | 33 | [Obsolete("This constructor is deprecated as of 3.0.0 and will soon be removed, please use VisitorsClient(RestClientFactory restClientFactory)")] 34 | public VisitorsClient(String intercomApiUrl, Authentication authentication) 35 | : base(String.IsNullOrEmpty(intercomApiUrl) ? INTERCOM_API_BASE_URL : intercomApiUrl, VISITORS_RESOURCE, authentication) 36 | { 37 | } 38 | 39 | public Visitor View(Dictionary parameters) 40 | { 41 | if (parameters == null) 42 | { 43 | throw new ArgumentNullException(nameof(parameters)); 44 | } 45 | 46 | if (!parameters.Any()) 47 | { 48 | throw new ArgumentException("'parameters' argument should include user_id parameter."); 49 | } 50 | 51 | ClientResponse result = null; 52 | 53 | result = Get(parameters: parameters); 54 | return result.Result; 55 | } 56 | 57 | public Visitor View(String id) 58 | { 59 | if (String.IsNullOrEmpty(id)) 60 | { 61 | throw new ArgumentNullException(nameof(id)); 62 | } 63 | 64 | ClientResponse result = null; 65 | result = Get(resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + id); 66 | return result.Result; 67 | } 68 | 69 | public Visitor View(Visitor visitor) 70 | { 71 | if (visitor == null) 72 | { 73 | throw new ArgumentNullException(nameof(visitor)); 74 | } 75 | 76 | Dictionary parameters = new Dictionary(); 77 | ClientResponse result = null; 78 | 79 | if (!String.IsNullOrEmpty(visitor.id)) 80 | { 81 | result = Get(resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + visitor.id); 82 | } 83 | else if (!String.IsNullOrEmpty(visitor.user_id)) 84 | { 85 | parameters.Add(Constants.USER_ID, visitor.user_id); 86 | result = Get(parameters: parameters); 87 | } 88 | else 89 | { 90 | throw new ArgumentException("you need to provide either 'visitor.id', 'visitor.user_id' to view a visitor."); 91 | } 92 | 93 | return result.Result; 94 | } 95 | 96 | public Visitor Update(Visitor visitor) 97 | { 98 | if (visitor == null) 99 | { 100 | throw new ArgumentNullException(nameof(visitor)); 101 | } 102 | 103 | if (String.IsNullOrEmpty(visitor.id) && String.IsNullOrEmpty(visitor.user_id)) 104 | { 105 | throw new ArgumentException("you need to provide either 'visitor.id', 'visitor.user_id' to update a visitor."); 106 | } 107 | 108 | ClientResponse result = null; 109 | result = Put(visitor); 110 | return result.Result; 111 | } 112 | 113 | public Visitor Delete(Visitor visitor) 114 | { 115 | if (visitor == null) 116 | { 117 | throw new ArgumentNullException(nameof(visitor)); 118 | } 119 | 120 | if (String.IsNullOrEmpty(visitor.id)) 121 | { 122 | throw new ArgumentException("'visitor.id' argument is null."); 123 | } 124 | 125 | Dictionary parameters = new Dictionary(); 126 | ClientResponse result = null; 127 | result = Delete(resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + visitor.id); 128 | return result.Result; 129 | } 130 | 131 | public Visitor Delete(String id) 132 | { 133 | if (String.IsNullOrEmpty(id)) 134 | { 135 | throw new ArgumentNullException(nameof(id)); 136 | } 137 | 138 | ClientResponse result = null; 139 | result = Delete(resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + id); 140 | return result.Result; 141 | } 142 | 143 | public User ConvertToUser(Visitor visitor, User user) 144 | { 145 | if (visitor == null) 146 | { 147 | throw new ArgumentNullException(nameof(visitor)); 148 | } 149 | 150 | if (user == null) 151 | { 152 | throw new ArgumentNullException(nameof(user)); 153 | } 154 | 155 | object userBody = null; 156 | 157 | if (!String.IsNullOrEmpty (user.id)) 158 | userBody = new { id = user.id }; 159 | else if (!String.IsNullOrEmpty (user.user_id)) 160 | userBody = new { user_id = user.user_id }; 161 | else if (!String.IsNullOrEmpty (user.email)) 162 | userBody = new { email = user.email }; 163 | else 164 | throw new ArgumentException ("you need to provide either 'user.id', 'user.user_id', or 'user.email' to convert a visitor."); 165 | 166 | object visitorBody = null; 167 | 168 | if (!String.IsNullOrEmpty (visitor.id)) 169 | visitorBody = new { id = visitor.id}; 170 | else if (!String.IsNullOrEmpty (visitor.user_id)) 171 | visitorBody = new {user_id = visitor.user_id }; 172 | else if (!String.IsNullOrEmpty (visitor.email)) 173 | visitorBody = new { email = visitor.email }; 174 | else 175 | throw new ArgumentException ("you need to provide either 'visitor.id', 'visitor.user_id', or 'visitor.email' to convert a visitor."); 176 | 177 | var body = new { 178 | visitor = visitorBody, 179 | user = userBody, 180 | type = "user" 181 | }; 182 | 183 | String b = JsonConvert.SerializeObject (body, 184 | Formatting.None, 185 | new JsonSerializerSettings { 186 | NullValueHandling = NullValueHandling.Ignore 187 | }); 188 | 189 | ClientResponse result = null; 190 | result = Post(b, resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + VISITORS_CONVERT); 191 | return result.Result; 192 | } 193 | 194 | public Contact ConvertToContact(Visitor visitor) 195 | { 196 | if (visitor == null) { 197 | throw new ArgumentNullException (nameof(visitor)); 198 | } 199 | 200 | object visitorBody = null; 201 | 202 | if (!String.IsNullOrEmpty (visitor.id)) 203 | visitorBody = new { id = visitor.id }; 204 | else if (!String.IsNullOrEmpty (visitor.user_id)) 205 | visitorBody = new { user_id = visitor.user_id }; 206 | else if (!String.IsNullOrEmpty (visitor.email)) 207 | visitorBody = new { email = visitor.email }; 208 | else 209 | throw new ArgumentException ("you need to provide either 'visitor.id', 'visitor.user_id', or 'visitor.email' to convert a visitor."); 210 | 211 | var body = new { 212 | visitor = visitorBody, 213 | type = "lead" 214 | }; 215 | 216 | String b = JsonConvert.SerializeObject (body, 217 | Formatting.None, 218 | new JsonSerializerSettings { 219 | NullValueHandling = NullValueHandling.Ignore 220 | }); 221 | 222 | ClientResponse result = null; 223 | result = Post (b, resource: VISITORS_RESOURCE + Path.DirectorySeparatorChar + VISITORS_CONVERT); 224 | return result.Result; 225 | } 226 | } 227 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/AttributeConverters/ListJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using RestSharp; 12 | 13 | namespace Intercom.Converters.AttributeConverters 14 | { 15 | public class ListJsonConverter : JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return objectType == typeof(User); 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject jobject = null; 28 | 29 | try 30 | { 31 | jobject = JObject.Load(reader); 32 | Object result = null; 33 | 34 | if (objectType == typeof(List)) 35 | result = GetList(jobject, "companies"); 36 | else if (objectType == typeof(List)) 37 | result = GetList(jobject, "social_profiles"); 38 | else if (objectType == typeof(List)) 39 | result = GetList(jobject, "tags"); 40 | else if (objectType == typeof(List)) 41 | result = GetList(jobject, "segments"); 42 | else if (objectType == typeof(List)) 43 | result = GetList(jobject, "conversation_parts"); 44 | 45 | return result; 46 | } 47 | catch (Exception ex) 48 | { 49 | throw new JsonConverterException("Error while serializing AppCount endpoint json result.", ex) 50 | { 51 | Json = jobject == null ? String.Empty : jobject.ToString(), 52 | SerializationType = objectType.FullName 53 | }; 54 | } 55 | } 56 | 57 | public override void WriteJson(JsonWriter writer, 58 | object value, 59 | JsonSerializer serializer) 60 | { 61 | String s = JsonConvert.SerializeObject(value, 62 | Formatting.None, 63 | new JsonSerializerSettings 64 | { 65 | NullValueHandling = NullValueHandling.Ignore 66 | }); 67 | 68 | writer.WriteRawValue(s); 69 | } 70 | 71 | public override bool CanRead 72 | { 73 | get { return true; } 74 | } 75 | 76 | private List GetList(JObject jobject, String key) 77 | where T: class 78 | { 79 | var value = jobject.GetValue(key); 80 | var result = (JsonConvert.DeserializeObject(value.ToString(), typeof(T[])) as T[]).ToList(); 81 | return result; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/AttributeConverters/MetadataJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Core; 6 | using Intercom.Data; 7 | using Intercom.Exceptions; 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | using RestSharp; 11 | using RestSharp.Authenticators; 12 | 13 | namespace Intercom.Converters.AttributeConverters 14 | { 15 | public class MetadataJsonConverter : JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return objectType == typeof(User); 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject jobject = null; 28 | 29 | try 30 | { 31 | jobject = JObject.Load(reader); 32 | Metadata result = new Metadata(); 33 | 34 | foreach (var j in jobject) 35 | { 36 | if (j.Value is JObject) 37 | { 38 | 39 | JObject complex = j.Value as JObject; 40 | 41 | if (complex["url"] != null && complex["value"] != null) 42 | { 43 | result.Add(j.Key, new Metadata.RichLink(complex["url"].Value(), complex["value"].Value())); 44 | } 45 | else if (complex["amount"] != null && complex["currency"] != null) 46 | { 47 | int amount = 0; 48 | int.TryParse(complex["amount"].ToString(), out amount); 49 | 50 | result.Add(j.Key, new Metadata.MonetaryAmount(amount, complex["currency"].ToString())); 51 | } 52 | } 53 | else 54 | { 55 | result.Add(j.Key, j.Value.Value()); 56 | } 57 | } 58 | 59 | return result; 60 | 61 | } 62 | catch (Exception ex) 63 | { 64 | throw new JsonConverterException("Error while serializing AppCount endpoint json result.", ex) 65 | { 66 | Json = jobject == null ? String.Empty : jobject.ToString(), 67 | SerializationType = objectType.FullName 68 | }; 69 | } 70 | } 71 | 72 | public override void WriteJson(JsonWriter writer, 73 | object value, 74 | JsonSerializer serializer) 75 | { 76 | Metadata metadata = value as Metadata; 77 | Dictionary metadataDictionary = metadata.GetMetadata(); 78 | 79 | String s = JsonConvert.SerializeObject(metadataDictionary, 80 | Formatting.None, 81 | new JsonSerializerSettings 82 | { 83 | NullValueHandling = NullValueHandling.Ignore 84 | }); 85 | 86 | writer.WriteRawValue(s); 87 | } 88 | 89 | public override bool CanRead 90 | { 91 | get { return true; } 92 | } 93 | 94 | } 95 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/ClassConverters/AppCountJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using RestSharp; 12 | 13 | namespace Intercom.Converters.ClassConverters 14 | { 15 | public class AppCountJsonConverter: JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return objectType == typeof(AppCount); 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject j = null; 28 | 29 | try 30 | { 31 | j = JObject.Load(reader); 32 | int companyCount = j["company"].Value("count"); 33 | int segmentCount = j["segment"].Value("count"); 34 | int userCount = j["user"].Value("count"); 35 | int tagCount = j["tag"].Value("count"); 36 | int contactCount = j["lead"].Value("count"); 37 | 38 | return new AppCount() 39 | { 40 | company = companyCount, 41 | segment = segmentCount, 42 | tag = tagCount, 43 | user = userCount , 44 | lead = contactCount 45 | }; 46 | } 47 | catch (Exception ex) 48 | { 49 | throw new JsonConverterException("Error while serializing AppCount endpoint json result.", ex) 50 | { 51 | Json = j == null ? String.Empty : j.ToString(), 52 | SerializationType = objectType.FullName 53 | }; 54 | } 55 | } 56 | 57 | public override void WriteJson(JsonWriter writer, 58 | object value, 59 | JsonSerializer serializer) 60 | { 61 | String s = JsonConvert.SerializeObject(value, 62 | Formatting.None, 63 | new JsonSerializerSettings 64 | { 65 | NullValueHandling = NullValueHandling.Ignore 66 | }); 67 | 68 | writer.WriteRawValue(s); 69 | } 70 | 71 | public override bool CanRead 72 | { 73 | get { return true; } 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/ClassConverters/CompanyCountJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using RestSharp; 12 | 13 | namespace Intercom.Converters.ClassConverters 14 | { 15 | public class CompanyCountJsonConverter: JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return true; 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject j = null; 28 | 29 | try 30 | { 31 | j = JObject.Load(reader); 32 | 33 | if (objectType == typeof(CompanyTagCount)) 34 | { 35 | Dictionary count = GetCompanyTagOrSegmentCount(j, j["company"]["tag"] as JArray); 36 | return new CompanyTagCount() { tags = count }; 37 | } 38 | else if (objectType == typeof(CompanySegmentCount)) 39 | { 40 | Dictionary count = GetCompanyTagOrSegmentCount(j, j["company"]["segment"] as JArray); 41 | return new CompanySegmentCount() { segments = count }; 42 | } 43 | else 44 | { 45 | List count = GetCompanyUserCount(j, j["company"]["user"] as JArray); 46 | return new CompanyUserCount() { counts = count }; 47 | } 48 | } 49 | catch (Exception ex) 50 | { 51 | throw new JsonConverterException("Error while serializing CompanyCount endpoint json result.", ex) 52 | { 53 | Json = j == null ? String.Empty : j.ToString(), 54 | SerializationType = objectType.FullName 55 | }; 56 | } 57 | } 58 | 59 | public override void WriteJson(JsonWriter writer, 60 | object value, 61 | JsonSerializer serializer) 62 | { 63 | String s = JsonConvert.SerializeObject(value, 64 | Formatting.None, 65 | new JsonSerializerSettings 66 | { 67 | NullValueHandling = NullValueHandling.Ignore 68 | }); 69 | 70 | writer.WriteRawValue(s); 71 | } 72 | 73 | private Dictionary GetCompanyTagOrSegmentCount(JObject j, JArray result) 74 | { 75 | Dictionary count = new Dictionary(); 76 | 77 | foreach (var r in result) 78 | { 79 | JProperty c = r.First as JProperty; 80 | 81 | if (c != null) 82 | { 83 | int value = 0; 84 | int.TryParse(c.Value.ToString(), out value); 85 | count.Add(c.Name, value); 86 | } 87 | } 88 | 89 | return count; 90 | } 91 | 92 | private List GetCompanyUserCount(JObject j, JArray result) 93 | { 94 | List count = new List(); 95 | 96 | foreach (var r in result) 97 | { 98 | if (r != null) 99 | { 100 | int value = 0; 101 | String name = String.Empty; 102 | String remoteCompanyId = String.Empty; 103 | 104 | remoteCompanyId = r[Constants.REMOTE_COMPANY_ID].Value(); 105 | 106 | JProperty prop = r.First as JProperty; 107 | name = prop.Name; 108 | 109 | int.TryParse(prop.Value.ToString(), out value); 110 | 111 | count.Add( 112 | new UserCount.UserCountEntry() 113 | { 114 | count = value, 115 | name = name, 116 | remote_company_id = remoteCompanyId 117 | }); 118 | } 119 | } 120 | 121 | return count; 122 | } 123 | 124 | public override bool CanRead 125 | { 126 | get { return true; } 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/ClassConverters/ConversationAdminCountJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using RestSharp; 12 | 13 | 14 | namespace Intercom.Converters.ClassConverters 15 | { 16 | public class ConversationAdminCountJsonConverter: JsonConverter 17 | { 18 | public override bool CanConvert(Type objectType) 19 | { 20 | return objectType == typeof(ConversationAdminCount); 21 | } 22 | 23 | public override object ReadJson(JsonReader reader, 24 | Type objectType, 25 | object existingValue, 26 | JsonSerializer serializer) 27 | { 28 | JObject j = null; 29 | 30 | try 31 | { 32 | j = JObject.Load(reader); 33 | JArray result = j["conversation"]["admin"] as JArray; 34 | List admins = new List(); 35 | 36 | foreach (var r in result) 37 | { 38 | int open = 0; 39 | int closed = 0; 40 | int.TryParse(r["open"].Value(), out open); 41 | int.TryParse(r["closed"].Value(), out closed); 42 | 43 | admins.Add(new ConversationAdminCount.AdminCount() 44 | { 45 | id = r["id"].Value(), 46 | name = r["name"].Value(), 47 | open = open, 48 | closed = closed 49 | }); 50 | } 51 | 52 | return new ConversationAdminCount() { admins = admins }; 53 | } 54 | catch (Exception ex) 55 | { 56 | throw new JsonConverterException("Error while serializing ConversationAdminCount endpoint json result.", ex) 57 | { 58 | Json = j == null ? String.Empty : j.ToString(), 59 | SerializationType = objectType.FullName 60 | }; 61 | } 62 | } 63 | 64 | public override void WriteJson(JsonWriter writer, 65 | object value, 66 | JsonSerializer serializer) 67 | { 68 | String s = JsonConvert.SerializeObject(value, 69 | Formatting.None, 70 | new JsonSerializerSettings 71 | { 72 | NullValueHandling = NullValueHandling.Ignore 73 | }); 74 | 75 | writer.WriteRawValue(s); 76 | } 77 | 78 | public override bool CanRead 79 | { 80 | get { return true; } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/ClassConverters/ConversationAppCountJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using RestSharp; 10 | using Newtonsoft.Json; 11 | using Newtonsoft.Json.Linq; 12 | 13 | namespace Intercom.Converters.ClassConverters 14 | { 15 | public class ConversationAppCountJsonConverter: JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return objectType == typeof(ConversationAdminCount); 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject j = null; 28 | 29 | try 30 | { 31 | j = JObject.Load(reader); 32 | JObject result = j["conversation"] as JObject; 33 | ConversationAppCount count = new ConversationAppCount(); 34 | count.assigned = result["assigned"].Value(); 35 | count.unassigned = result["unassigned"].Value(); 36 | count.open = result["open"].Value(); 37 | count.closed = result["closed"].Value(); 38 | return count; 39 | } 40 | catch (Exception ex) 41 | { 42 | throw new JsonConverterException("Error while serializing ConversationAppCount endpoint json result.", ex) 43 | { 44 | Json = j == null ? String.Empty : j.ToString(), 45 | SerializationType = objectType.FullName 46 | }; 47 | } 48 | } 49 | 50 | public override void WriteJson(JsonWriter writer, 51 | object value, 52 | JsonSerializer serializer) 53 | { 54 | String s = JsonConvert.SerializeObject(value, 55 | Formatting.None, 56 | new JsonSerializerSettings 57 | { 58 | NullValueHandling = NullValueHandling.Ignore 59 | }); 60 | 61 | writer.WriteRawValue(s); 62 | } 63 | 64 | public override bool CanRead 65 | { 66 | get { return true; } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/Intercom/Converters/ClassConverters/UserCountJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using RestSharp; 12 | 13 | namespace Intercom.Converters.ClassConverters 14 | { 15 | public class UserCountJsonConverter: JsonConverter 16 | { 17 | public override bool CanConvert(Type objectType) 18 | { 19 | return true; 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, 23 | Type objectType, 24 | object existingValue, 25 | JsonSerializer serializer) 26 | { 27 | JObject j = null; 28 | 29 | try 30 | { 31 | j = JObject.Load(reader); 32 | JArray result = null; 33 | 34 | if (objectType == typeof(UserTagCount)) 35 | result = j["user"]["tag"] as JArray; 36 | else 37 | result = j["user"]["segment"] as JArray; 38 | 39 | Dictionary count = new Dictionary(); 40 | 41 | foreach (var r in result) 42 | { 43 | JProperty prop = r.First as JProperty; 44 | 45 | if (prop != null) 46 | { 47 | int value = 0; 48 | int.TryParse(prop.Value.ToString(), out value); 49 | count.Add(prop.Name, value); 50 | } 51 | } 52 | 53 | if (objectType == typeof(UserTagCount)) 54 | return new UserTagCount() { tags = count }; 55 | else 56 | return new UserSegmentCount() { segments = count }; 57 | } 58 | catch (Exception ex) 59 | { 60 | throw new JsonConverterException("Error while serializing UserCount endpoint json result.", ex) 61 | { 62 | Json = j == null ? String.Empty : j.ToString(), 63 | SerializationType = objectType.FullName 64 | }; 65 | } 66 | } 67 | 68 | public override void WriteJson(JsonWriter writer, 69 | object value, 70 | JsonSerializer serializer) 71 | { 72 | String s = JsonConvert.SerializeObject(value, 73 | Formatting.None, 74 | new JsonSerializerSettings 75 | { 76 | NullValueHandling = NullValueHandling.Ignore 77 | }); 78 | 79 | writer.WriteRawValue(s); 80 | } 81 | 82 | public override bool CanRead 83 | { 84 | get { return true; } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/Intercom/Core/Authentication.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using RestSharp; 7 | 8 | namespace Intercom.Core 9 | { 10 | public class Authentication 11 | { 12 | public String AppId { private set; get;} 13 | public String AppKey{ private set; get;} 14 | public String PersonalAccessToken { private set; get; } 15 | 16 | public Authentication (String personalAccessToken) 17 | { 18 | if (String.IsNullOrEmpty (personalAccessToken)) 19 | throw new ArgumentException ("'PersonalAccessToken' argument is not found."); 20 | 21 | this.PersonalAccessToken = personalAccessToken; 22 | } 23 | 24 | public Authentication (String appId, String appKey) 25 | { 26 | if (String.IsNullOrEmpty (appId)) 27 | throw new ArgumentException ("'appId' argument is not found."); 28 | 29 | if (String.IsNullOrEmpty (appKey)) 30 | throw new ArgumentException ("'appKey' argument is not found."); 31 | 32 | this.AppId = appId; 33 | this.AppKey = appKey; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/Intercom/Core/ClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Core 8 | { 9 | public class ClientConfiguration 10 | { 11 | public String AppKey { private set; get; } 12 | public String AppId { private set; get; } 13 | 14 | public ClientConfiguration () 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Intercom/Core/ClientResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using RestSharp; 7 | 8 | namespace Intercom.Core 9 | { 10 | public class ClientResponse where T : class 11 | { 12 | public T Result { private set; get; } 13 | public Errors Errors { private set; get; } 14 | public IRestResponse Response { private set; get; } 15 | 16 | public ClientResponse(IRestResponse response, T result = null, Errors errors = null) 17 | { 18 | this.Response = response; 19 | this.Result = result; 20 | this.Errors = errors; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Intercom/Core/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Core 8 | { 9 | internal static class Constants 10 | { 11 | public const String USER_ID = "user_id"; 12 | public const String ADMIN_ID = "admin_id"; 13 | public const String COMPANY_ID = "company_id"; 14 | public const String SEGMENT_ID = "segment_id"; 15 | public const String REMOTE_COMPANY_ID = "remote_company_id"; 16 | public const String INTERCOM_USER_ID = "intercom_user_id"; 17 | public const String UPDATE_LAST_REQUEST_AT = "update_last_request_at"; 18 | public const String LAST_REQUEST_AT = "last_request_at"; 19 | public const String ID = "id"; 20 | public const String TYPE = "type"; 21 | public const String NAME = "name"; 22 | public const String EMAIL = "email"; 23 | public const String PHONE = "phone"; 24 | public const String REPLY = "reply"; 25 | public const String USER = "user"; 26 | public const String ADMIN = "admin"; 27 | public const String SEGMENT = "segment"; 28 | public const String COMPANY = "company"; 29 | public const String CONVERSATION = "conversation"; 30 | public const String TAG = "tag"; 31 | public const String UNREAD = "unread"; 32 | public const String OPEN = "open"; 33 | public const String COUNT = "count"; 34 | public const String DISPLAY_AS = "display_as"; 35 | public const String PLAIN_TEXT = "plaintext"; 36 | } 37 | } -------------------------------------------------------------------------------- /src/Intercom/Core/Model.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Core 8 | { 9 | public class Model 10 | { 11 | public virtual string id { set; get; } 12 | public virtual string type { get; set; } 13 | 14 | public Model () 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Intercom/Core/Models.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Intercom.Clients; 4 | using Intercom.Core; 5 | using Intercom.Data; 6 | using Intercom.Exceptions; 7 | 8 | namespace Intercom.Core 9 | { 10 | public class Models 11 | { 12 | public virtual string type { get; set; } 13 | public virtual Pages pages { get; set; } 14 | public virtual int total_count { get; set; } 15 | 16 | public Models () 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Admin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Admin : Model 14 | { 15 | public string name { get; set; } 16 | public string email { get; set; } 17 | 18 | public Admin() 19 | { 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Intercom/Data/AdminConversationMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | 8 | namespace Intercom.Data 9 | { 10 | public class AdminConversationMessage : Message 11 | { 12 | 13 | public class From { 14 | public String id { set; get; } 15 | public String type { private set; get; } 16 | 17 | public From(String id) 18 | { 19 | if(String.IsNullOrEmpty(id)) 20 | throw new ArgumentNullException (nameof(id)); 21 | 22 | this.id = id; 23 | this.type = Message.MessageFromOrToType.ADMIN; 24 | } 25 | } 26 | 27 | public class To { 28 | public String id { set; get; } 29 | public String email { set; get; } 30 | public String user_id { set; get; } 31 | public String type { set; get; } 32 | 33 | public To(String type = Message.MessageFromOrToType.USER, String id = null, String email = null, String user_id = null) 34 | { 35 | if(String.IsNullOrEmpty(type)) 36 | throw new ArgumentNullException (nameof(type)); 37 | 38 | if(String.IsNullOrEmpty(id) && String.IsNullOrEmpty(email) && String.IsNullOrEmpty(user_id)) 39 | throw new ArgumentException ("you need to provide either 'id', 'user_id', 'email' to view a user."); 40 | 41 | if(type != Message.MessageFromOrToType.USER && type != Message.MessageFromOrToType.CONTACT) 42 | throw new ArgumentException ("'type' vale must be either 'contact' or 'user'."); 43 | 44 | this.id = id; 45 | this.email = email; 46 | this.user_id = user_id; 47 | this.type = type; 48 | } 49 | } 50 | 51 | public string message_type { get; set; } 52 | public string subject { get; set; } 53 | public string template { get; set; } 54 | public From from { get; set; } 55 | public To to { get; set; } 56 | 57 | public AdminConversationMessage ( 58 | AdminConversationMessage.From from, 59 | AdminConversationMessage.To to, 60 | String message_type = Message.MessageType.EMAIL, 61 | String template = Message.MessageTemplate.PLAIN, 62 | String subject = "", 63 | String body = "") 64 | { 65 | this.to = to; 66 | this.from = from; 67 | this.message_type = message_type; 68 | this.template = template; 69 | this.subject = subject; 70 | this.body = body; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Intercom/Data/AdminConversationReply.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class AdminConversationReply : Reply 15 | { 16 | public override string type 17 | { 18 | get 19 | { 20 | return Reply.ReplySenderType.ADMIN; 21 | } 22 | } 23 | 24 | public String admin_id { set; get; } 25 | 26 | public String assignee_id { set; get; } 27 | 28 | public AdminConversationReply(String conversationId, 29 | String adminId, 30 | String messageType = Reply.ReplyMessageType.COMMENT, 31 | String body = "", 32 | List attachementUrls = null) 33 | : base(conversationId, messageType, body, attachementUrls) 34 | { 35 | 36 | if (String.IsNullOrEmpty(conversationId)) 37 | throw new ArgumentNullException(nameof(conversationId)); 38 | 39 | if ((messageType == Reply.ReplyMessageType.COMMENT || 40 | messageType == Reply.ReplyMessageType.NOTE) && 41 | String.IsNullOrEmpty(body)) 42 | { 43 | throw new ArgumentException("'body' argument shouldnt be empty when the message type is 'comment' or 'note'."); 44 | } 45 | 46 | this.admin_id = adminId; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/Intercom/Data/AdminLastConversationReply.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Intercom.Data 3 | { 4 | public class AdminLastConversationReply 5 | { 6 | public string admin_id { get; set; } 7 | public string message_type { get; set; } 8 | public string body { get; set; } 9 | public string intercom_user_id { get; set; } 10 | public string type { get; set; } 11 | 12 | public AdminLastConversationReply() 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Intercom/Data/Admins.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | using System.Collections; 13 | 14 | namespace Intercom.Data 15 | { 16 | public class Admins : Models 17 | { 18 | public List admins { set; get; } 19 | 20 | public Admins () 21 | { 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Intercom/Data/AppCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using Newtonsoft.Json; 7 | using Intercom.Converters.ClassConverters; 8 | 9 | namespace Intercom.Data 10 | { 11 | [JsonConverter(typeof(AppCountJsonConverter))] 12 | public class AppCount : Count 13 | { 14 | public int company { set; get; } 15 | public int segment { set; get; } 16 | public int user { set; get; } 17 | public int tag { set; get; } 18 | public int lead { set; get; } 19 | 20 | public AppCount() 21 | { 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Assignee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Assignee : Model 14 | { 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/Intercom/Data/Attachment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class Attachment: Model 10 | { 11 | public string name { get; set; } 12 | public string url { get; set; } 13 | public string content_type { get; set; } 14 | public int? filesize { get; set; } 15 | public object width { get; set; } 16 | public object height { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Author.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class Author : Model 10 | { 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Intercom/Data/Avatar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Avatar 14 | { 15 | public string type { get; set; } 16 | public string image_url { get; set; } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Intercom/Data/Companies.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Clients; 3 | using Intercom.Exceptions; 4 | using System.Collections.Generic; 5 | using Intercom.Core; 6 | using System.Collections; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Companies : Models 11 | { 12 | public List companies { set; get; } 13 | public string scroll_param { get; set; } 14 | 15 | public Companies () 16 | { 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Company.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using System.Collections.Generic; 4 | using Newtonsoft.Json; 5 | using Intercom.Converters.AttributeConverters; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class Company : Model 10 | { 11 | public bool? remove { set; get; } 12 | public string name { get; set; } 13 | public Plan plan { get; set; } 14 | public string company_id { get; set; } 15 | public long? remote_created_at { get; set; } 16 | public long? created_at { get; set; } 17 | public long? updated_at { get; set; } 18 | public long? last_request_at { get; set; } 19 | public decimal? monthly_spend { get; set; } 20 | public int? session_count { get; set; } 21 | public int? user_count { get; set; } 22 | public int? size { get; set; } 23 | public string website { get; set; } 24 | public string industry { get; set; } 25 | public Dictionary custom_attributes { get; set; } 26 | [JsonConverter(typeof(ListJsonConverter))] 27 | public List tags { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Intercom/Data/CompanySegmentCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using Newtonsoft.Json; 11 | using Intercom.Converters.ClassConverters; 12 | 13 | namespace Intercom.Data 14 | { 15 | [JsonConverter(typeof(CompanyCountJsonConverter))] 16 | public class CompanySegmentCount : SegmentCount 17 | { 18 | public CompanySegmentCount() 19 | { 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/Intercom/Data/CompanyTagCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using Newtonsoft.Json; 7 | using Intercom.Converters.AttributeConverters; 8 | using Intercom.Converters.ClassConverters; 9 | 10 | namespace Intercom.Data 11 | { 12 | [JsonConverter(typeof(CompanyCountJsonConverter))] 13 | public class CompanyTagCount : TagCount 14 | { 15 | public CompanyTagCount() 16 | { 17 | } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/Intercom/Data/CompanyUserCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using Newtonsoft.Json; 11 | using Intercom.Converters.ClassConverters; 12 | 13 | namespace Intercom.Data 14 | { 15 | [JsonConverter(typeof(CompanyCountJsonConverter))] 16 | public class CompanyUserCount : UserCount 17 | { 18 | public CompanyUserCount() 19 | { 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/Intercom/Data/Contact.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using Newtonsoft.Json; 7 | using System.Collections.Generic; 8 | using Intercom.Converters.AttributeConverters; 9 | 10 | namespace Intercom.Data 11 | { 12 | public class Contact : User 13 | { 14 | public Contact() 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Contacts.cs: -------------------------------------------------------------------------------- 1 | using Intercom.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Intercom.Data 5 | { 6 | public class Contacts : Models 7 | { 8 | public List contacts { set; get; } 9 | public string scroll_param { get; set; } 10 | 11 | public Contacts() 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Conversation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Intercom.Clients; 4 | using Intercom.Converters.AttributeConverters; 5 | using Intercom.Core; 6 | using Intercom.Data; 7 | using Intercom.Exceptions; 8 | using Newtonsoft.Json; 9 | 10 | namespace Intercom.Data 11 | { 12 | public class Conversation : Model 13 | { 14 | public long created_at { get; set; } 15 | public long updated_at { get; set; } 16 | public long? waiting_since { get; set; } 17 | public long? snoozed_until { get; set; } 18 | public Assignee assignee { get; set; } 19 | public ConversationUser user { get; set; } 20 | public bool open { get; set; } 21 | public bool read { get; set; } 22 | public string state { get; set; } 23 | public int total_count { get; set; } 24 | public ConversationMessage conversation_message { get; set; } 25 | [JsonConverter(typeof(ListJsonConverter))] 26 | public List conversation_parts { get; set; } 27 | [JsonConverter(typeof(ListJsonConverter))] 28 | public List tags { get; set; } 29 | public ConversationRating conversation_rating { get; set; } 30 | public List customers { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationAdminCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Intercom.Converters.ClassConverters; 13 | 14 | namespace Intercom.Data 15 | { 16 | [JsonConverter(typeof(ConversationAdminCountJsonConverter))] 17 | public class ConversationAdminCount 18 | { 19 | public class AdminCount 20 | { 21 | public string id { set; get; } 22 | 23 | public String name { set; get; } 24 | 25 | public int open { set; get; } 26 | 27 | public int closed { set; get ; } 28 | } 29 | 30 | public List admins { set; get; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationAppCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using Newtonsoft.Json; 7 | using Intercom.Converters.ClassConverters; 8 | 9 | namespace Intercom.Data 10 | { 11 | 12 | [JsonConverter(typeof(ConversationAppCountJsonConverter))] 13 | public class ConversationAppCount 14 | { 15 | public int closed { set; get; } 16 | public int open { set; get; } 17 | public int assigned { set; get; } 18 | public int unassigned { set; get; } 19 | 20 | public ConversationAppCount() 21 | { 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class ConversationMessage : Message 15 | { 16 | public string subject { get; set; } 17 | public Author author { get; set; } 18 | public List attachments { get; set; } 19 | public object url { get; set; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationPart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class ConversationPart : Model 11 | { 12 | public string part_type { get; set; } 13 | public string body { get; set; } 14 | public long created_at { get; set; } 15 | public long updated_at { get; set; } 16 | public long notified_at { get; set; } 17 | public Assignee assigned_to { get; set; } 18 | public Author author { get; set; } 19 | public List attachments { get; set; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationRating.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class ConversationRating : Model 11 | { 12 | public string rating { get; set; } 13 | public string remark { get; set; } 14 | public long? created_at { get; set; } 15 | public Customer customer { get; set; } 16 | public Teammate teammate { get; set; } 17 | 18 | public ConversationRating() 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Intercom/Data/ConversationUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class ConversationUser : Model 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Intercom/Data/Conversations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Conversations : Models 11 | { 12 | public List conversations { set; get; } 13 | 14 | public Conversations() 15 | { 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Intercom/Data/Count.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Count 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | 4 | namespace Intercom.Data 5 | { 6 | public class Customer : Model 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Intercom/Data/Error.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Error 14 | { 15 | public string code { get; set; } 16 | public string message { get; set; } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Intercom/Data/Errors.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | 13 | namespace Intercom.Data 14 | { 15 | public class Errors 16 | { 17 | public string type { get; set; } 18 | public string request_id { get; set; } 19 | public List errors { get; set; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Intercom/Data/Event.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | using Newtonsoft.Json; 8 | using Intercom.Converters.AttributeConverters; 9 | 10 | namespace Intercom.Data 11 | { 12 | public class Event : Model 13 | { 14 | public string event_name { get; set; } 15 | public long? created_at { get; set; } 16 | public string user_id { get; set; } 17 | public string email { get; set; } 18 | 19 | [JsonConverter(typeof(MetadataJsonConverter))] 20 | public Metadata metadata { get; set; } 21 | 22 | public Event() 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Events.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using Intercom.Clients; 6 | using Intercom.Core; 7 | using Intercom.Data; 8 | using Intercom.Exceptions; 9 | 10 | namespace Intercom.Data 11 | { 12 | public class Events : Models 13 | { 14 | public List events { set; get; } 15 | 16 | public Events () 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Intercom/Data/LocationData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class LocationData 14 | { 15 | public string type { get; set; } 16 | public string city_name { get; set; } 17 | public string continent_code { get; set; } 18 | public string country_code { get; set; } 19 | public string country_name { get; set; } 20 | public double? latitude { get; set; } 21 | public double? longitude { get; set; } 22 | public object postal_code { get; set; } 23 | public string region_name { get; set; } 24 | public string timezone { get; set; } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Intercom/Data/Message.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Message : Model 11 | { 12 | public static class MessageType 13 | { 14 | public const String IN_APP = "inapp"; 15 | public const String EMAIL = "email"; 16 | } 17 | 18 | public static class MessageTemplate 19 | { 20 | public const String PLAIN = "plain"; 21 | public const String PERSONAL = "personal"; 22 | } 23 | 24 | public static class MessageFromOrToType 25 | { 26 | public const String USER = "user"; 27 | public const String ADMIN = "admin"; 28 | public const String CONTACT = "contact"; 29 | } 30 | 31 | public virtual string body { get; set; } 32 | 33 | public Message () 34 | { 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Metadata.cs: -------------------------------------------------------------------------------- 1 | using Intercom.Core; 2 | using Intercom.Data; 3 | using System; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | 13 | namespace Intercom.Data 14 | { 15 | public class Metadata 16 | { 17 | public class RichLink: ICloneable 18 | { 19 | public String url { set; get; } 20 | 21 | public String value { set; get; } 22 | 23 | public RichLink(String url, String value) 24 | { 25 | if (String.IsNullOrEmpty(url)) 26 | { 27 | throw new ArgumentNullException(nameof(url)); 28 | } 29 | 30 | if (String.IsNullOrEmpty(value)) 31 | { 32 | throw new ArgumentNullException(nameof(value)); 33 | } 34 | 35 | this.url = url; 36 | this.value = value; 37 | } 38 | 39 | public object Clone() 40 | { 41 | return new RichLink(url, value); 42 | } 43 | } 44 | 45 | public class MonetaryAmount :ICloneable 46 | { 47 | public int amount { set; get; } 48 | 49 | public String currency { set; get; } 50 | 51 | public MonetaryAmount(int amount, String currency) 52 | { 53 | if (String.IsNullOrEmpty(currency)) 54 | { 55 | throw new ArgumentNullException(nameof(currency)); 56 | } 57 | 58 | this.amount = amount; 59 | this.currency = currency; 60 | } 61 | 62 | public object Clone() 63 | { 64 | return new MonetaryAmount(amount, currency); 65 | } 66 | } 67 | 68 | private Dictionary data = new Dictionary(); 69 | 70 | // TODO: Implement indexer 71 | public Object this [String key] 72 | { 73 | get 74 | { 75 | return null; 76 | } 77 | set { } 78 | } 79 | 80 | public Metadata() 81 | { 82 | } 83 | 84 | public void Add(String key, object value) 85 | { 86 | 87 | if (String.IsNullOrEmpty(key)) 88 | { 89 | throw new ArgumentNullException(nameof(key)); 90 | } 91 | 92 | if (value == null) 93 | { 94 | throw new ArgumentNullException(nameof(value)); 95 | } 96 | 97 | data.Add(key, value); 98 | } 99 | 100 | public void Add(Dictionary metadata) 101 | { 102 | if (metadata == null) 103 | { 104 | throw new ArgumentNullException(nameof(metadata)); 105 | } 106 | 107 | if (!metadata.Any()) 108 | { 109 | throw new ArgumentException("'metadata' argument is empty."); 110 | } 111 | 112 | foreach (var m in metadata) 113 | { 114 | data.Add(m.Key, m.Value); 115 | } 116 | } 117 | 118 | public void Add(String key, Metadata.RichLink richLink) 119 | { 120 | if (String.IsNullOrEmpty(key)) 121 | { 122 | throw new ArgumentNullException(nameof(key)); 123 | } 124 | 125 | if (richLink == null) 126 | { 127 | throw new ArgumentException("'richLink' argument is null."); 128 | } 129 | 130 | data.Add(key, richLink); 131 | } 132 | 133 | public void Add(String key, Metadata.MonetaryAmount monetaryAmount) 134 | { 135 | if (String.IsNullOrEmpty(key)) 136 | { 137 | throw new ArgumentNullException(nameof(key)); 138 | } 139 | 140 | if (monetaryAmount == null) 141 | { 142 | throw new ArgumentException("'monetaryAmount' argument is null."); 143 | } 144 | 145 | data.Add(key, monetaryAmount); 146 | } 147 | 148 | public Dictionary GetMetadata() 149 | { 150 | Dictionary result = new Dictionary(data.Count, data.Comparer); 151 | 152 | foreach (KeyValuePair entry in data) 153 | result.Add(entry.Key, entry.Value is ICloneable ? ((ICloneable)entry.Value).Clone() : entry.Value); 154 | 155 | return result; 156 | } 157 | 158 | public object GetMetadata(String key) 159 | { 160 | if (String.IsNullOrEmpty(key)) 161 | { 162 | throw new ArgumentNullException(nameof(key)); 163 | } 164 | 165 | object result = null; 166 | 167 | if (data.ContainsKey(key)) 168 | { 169 | result = data[key]; 170 | } 171 | 172 | return result; 173 | } 174 | 175 | public MonetaryAmount GetMonetaryAmount(String key) 176 | { 177 | if (String.IsNullOrEmpty(key)) 178 | { 179 | throw new ArgumentNullException(nameof(key)); 180 | } 181 | 182 | MonetaryAmount result = null; 183 | 184 | if (data.ContainsKey(key) && data[key] is MonetaryAmount) 185 | { 186 | result = ((ICloneable)data[key]).Clone() as MonetaryAmount; 187 | } 188 | 189 | return result; 190 | } 191 | 192 | public List GetMonetaryAmounts() 193 | { 194 | List result = new List(); 195 | 196 | foreach (var d in data) 197 | { 198 | if (d.Value is MonetaryAmount) 199 | result.Add(((ICloneable)d.Value).Clone() as MonetaryAmount); 200 | } 201 | 202 | return result; 203 | } 204 | 205 | public RichLink GetRichLink(String key) 206 | { 207 | if (String.IsNullOrEmpty(key)) 208 | { 209 | throw new ArgumentNullException(nameof(key)); 210 | } 211 | 212 | RichLink result = null; 213 | 214 | if (data.ContainsKey(key) && data[key] is RichLink) 215 | { 216 | result = ((ICloneable)data[key]).Clone() as RichLink; 217 | } 218 | 219 | return result; 220 | } 221 | 222 | public List GetRichLinks() 223 | { 224 | List result = new List(); 225 | 226 | foreach (var d in data) 227 | { 228 | if (d.Value is RichLink) 229 | result.Add(((ICloneable)d.Value).Clone() as RichLink); 230 | } 231 | 232 | return result; 233 | } 234 | } 235 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Note.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class Note : Model 10 | { 11 | public long? created_at { get; set; } 12 | public string body { get; set; } 13 | public Admin author { get; set; } 14 | public User user { get; set; } 15 | 16 | public Note() 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Intercom/Data/Notes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Notes : Models 11 | { 12 | public List notes { set; get; } 13 | 14 | public Notes() 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Pages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Pages : Model 14 | { 15 | public string next { get; set; } 16 | public int page { get; set; } 17 | public int per_page { get; set; } 18 | public int total_pages { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Plan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Plan : Model 14 | { 15 | public string name { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Reply.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class Reply : Model 15 | { 16 | public static class ReplyMessageType 17 | { 18 | public const String ASSIGNMENT = "assignment"; 19 | public const String COMMENT = "comment"; 20 | public const String CLOSE = "close"; 21 | public const String OPEN = "open"; 22 | public const String NOTE = "note"; 23 | } 24 | 25 | public static class ReplySenderType 26 | { 27 | public const String USER = "user"; 28 | public const String ADMIN = "admin"; 29 | } 30 | 31 | public virtual String conversation_id { set; get; } 32 | public virtual String message_type { set; get; } 33 | public virtual String body { set; get; } 34 | public virtual List attachment_urls { get; set; } 35 | 36 | public Reply( 37 | String conversation_id, 38 | String messageType = Reply.ReplyMessageType.COMMENT, 39 | String body = "", 40 | List attachementUrls = null) 41 | { 42 | if (attachementUrls != null && attachementUrls.Count > 5) 43 | { 44 | throw new ArgumentException("'attachment_urls' need to be equal or less than 5 urls."); 45 | } 46 | 47 | this.body = body; 48 | this.conversation_id = conversation_id; 49 | this.message_type = messageType; 50 | this.attachment_urls = attachementUrls; 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/Intercom/Data/Segment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Segment : Model 14 | { 15 | public string name { get; set; } 16 | public long created_at { get; set; } 17 | public long updated_at { get; set; } 18 | public int? count { get; set; } 19 | 20 | public Segment() 21 | { 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/Intercom/Data/SegmentCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class SegmentCount 11 | { 12 | public Dictionary segments = new Dictionary(); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Intercom/Data/Segments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class Segments : Models 15 | { 16 | public List segments { get; set; } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Intercom/Data/SocialProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | namespace Intercom.Data 11 | { 12 | public class SocialProfile : Model 13 | { 14 | public override string type { get; set; } 15 | public string username { get; set; } 16 | public string url { get; set; } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Intercom/Data/SocialProfiles.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class SocialProfiles 15 | { 16 | public string type { get; set; } 17 | public List social_profiles { get; set; } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/Intercom/Data/Tag.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class Tag : Model 14 | { 15 | public string name { get; set; } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Intercom/Data/TagCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class TagCount 15 | { 16 | public Dictionary tags = new Dictionary(); 17 | 18 | public TagCount() 19 | { 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Tags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class Tags 11 | { 12 | public string type { get; set; } 13 | public List tags { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Intercom/Data/Teammate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | 4 | namespace Intercom.Data 5 | { 6 | public class Teammate : Model 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/Intercom/Data/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using System.Collections.Generic; 4 | using Newtonsoft.Json; 5 | using Intercom.Converters.AttributeConverters; 6 | 7 | namespace Intercom.Data 8 | { 9 | public class User : Model 10 | { 11 | public string user_id { get; set; } 12 | public string email { get; set; } 13 | public string phone { get; set; } 14 | public string name { get; set; } 15 | public long? updated_at { get; set; } 16 | public string last_seen_ip { get; set; } 17 | public bool? unsubscribed_from_emails { get; set; } 18 | public long? last_request_at { get; set; } 19 | public long? signed_up_at { get; set; } 20 | public long? created_at { get; set; } 21 | public int? session_count { get; set; } 22 | public bool? new_session { get; set; } 23 | public string user_agent_data { get; set; } 24 | public object pseudonym { get; set; } 25 | public bool? anonymous { get; set; } 26 | public Dictionary custom_attributes { get; set; } 27 | public Avatar avatar { get; set; } 28 | public LocationData location_data { get; set; } 29 | [JsonConverter(typeof(ListJsonConverter))] 30 | public List social_profiles { get; set; } 31 | [JsonConverter(typeof(ListJsonConverter))] 32 | public List companies { get; set; } 33 | [JsonConverter(typeof(ListJsonConverter))] 34 | public List segments { get; set; } 35 | [JsonConverter(typeof(ListJsonConverter))] 36 | public List tags { get; set; } 37 | public string app_id { get; set; } 38 | public long? remote_created_at { get; set; } 39 | public string referrer { get; set; } 40 | public string utm_campaign { get; set; } 41 | public string utm_content { get; set; } 42 | public string utm_medium { get; set; } 43 | public string utm_source { get; set; } 44 | public string utm_term { get; set; } 45 | public bool marked_email_as_spam { get; set; } 46 | public bool has_hard_bounced { get; set; } 47 | public string last_seen_user_agent { get; set; } 48 | 49 | public User() 50 | { 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Intercom/Data/UserConversationMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | 11 | namespace Intercom.Data 12 | { 13 | public class UserConversationMessage : Message 14 | { 15 | 16 | public class From : Model 17 | { 18 | public String email { set; get; } 19 | public String user_id { set; get; } 20 | 21 | public From(String type = Message.MessageFromOrToType.USER, String id = null, String email = null, String user_id = null, User user = null) 22 | { 23 | //Validate type of message 24 | if (String.IsNullOrEmpty(type)) 25 | throw new ArgumentNullException(nameof(type)); 26 | 27 | //Validate required fields related to User 28 | if (String.IsNullOrEmpty(id) && String.IsNullOrEmpty(email) && String.IsNullOrEmpty(user_id)) 29 | throw new ArgumentException("you need to provide either 'id', 'user_id', 'email' to view a user."); 30 | 31 | //Validate User required fields 32 | if (user != null && String.IsNullOrEmpty(user.id) && String.IsNullOrEmpty(user.email) && String.IsNullOrEmpty(user.user_id)) 33 | throw new ArgumentException("you need to provide either 'id', 'user_id', 'email' to view a user."); 34 | 35 | //Validate required types 36 | if (type != Message.MessageFromOrToType.USER && type != Message.MessageFromOrToType.CONTACT) 37 | throw new ArgumentException("'type' value must be either 'contact' or 'user'."); 38 | 39 | if (user != null) 40 | { 41 | this.id = user.id; 42 | this.email = user.email; 43 | this.user_id = user.user_id; 44 | } 45 | else 46 | { 47 | this.id = id; 48 | this.email = email; 49 | this.user_id = user_id; 50 | } 51 | 52 | this.type = type; 53 | } 54 | } 55 | 56 | public From from { set; get; } 57 | 58 | public UserConversationMessage (From from, String body) 59 | { 60 | this.from = from; 61 | this.body = body; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/Intercom/Data/UserConversationReply.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using System.Collections.Generic; 7 | 8 | namespace Intercom.Data 9 | { 10 | public class UserConversationReply : Reply 11 | { 12 | public override string type 13 | { 14 | get 15 | { 16 | return Reply.ReplySenderType.USER; 17 | } 18 | } 19 | 20 | public override String message_type 21 | { 22 | get 23 | { 24 | return Reply.ReplyMessageType.COMMENT; 25 | } 26 | } 27 | 28 | public String email { set; get; } 29 | 30 | public String user_id { set; get; } 31 | 32 | public String intercom_user_id { set; get; } 33 | 34 | public UserConversationReply( 35 | String conversationId, 36 | String body, 37 | String intercomUserId = null, 38 | String email = null, 39 | String userId = null, 40 | List attachementUrls = null) 41 | : base(conversationId, Reply.ReplyMessageType.COMMENT, body, attachementUrls) 42 | { 43 | 44 | if (String.IsNullOrEmpty(conversationId)) 45 | throw new ArgumentNullException(nameof(conversationId)); 46 | 47 | if (String.IsNullOrEmpty(intercomUserId) && String.IsNullOrEmpty(email) && String.IsNullOrEmpty(userId)) 48 | throw new ArgumentException("you need to provide either 'intercomUserId', 'userId', 'email' to view a user."); 49 | 50 | this.email = email; 51 | this.user_id = userId; 52 | this.intercom_user_id = intercomUserId; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Intercom/Data/UserCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | 12 | namespace Intercom.Data 13 | { 14 | public class UserCount 15 | { 16 | public class UserCountEntry { 17 | public int count { set; get; } 18 | public String name { set; get; } 19 | public String remote_company_id { set; get; } 20 | } 21 | 22 | public List counts = new List(); 23 | 24 | public UserCount() 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Intercom/Data/UserSegmentCount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | 5 | 6 | using Intercom.Clients; 7 | 8 | using Intercom.Exceptions; 9 | 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Intercom.Converters.ClassConverters; 13 | 14 | namespace Intercom.Data 15 | { 16 | [JsonConverter(typeof(UserCountJsonConverter))] 17 | public class UserSegmentCount : SegmentCount 18 | { 19 | } 20 | } -------------------------------------------------------------------------------- /src/Intercom/Data/UserTagCount.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Intercom.Converters.ClassConverters; 3 | 4 | namespace Intercom.Data 5 | { 6 | [JsonConverter(typeof(UserCountJsonConverter))] 7 | public class UserTagCount : TagCount 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Users.cs: -------------------------------------------------------------------------------- 1 | using Intercom.Core; 2 | using System.Collections.Generic; 3 | 4 | namespace Intercom.Data 5 | { 6 | public class Users : Models 7 | { 8 | public List users { set; get; } 9 | public string scroll_param { get; set; } 10 | 11 | public Users () 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Intercom/Data/Visitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using RestSharp; 7 | using RestSharp.Authenticators; 8 | using System.Collections; 9 | using System.Linq; 10 | using System.Collections.Generic; 11 | using Newtonsoft.Json; 12 | using Intercom.Converters.AttributeConverters; 13 | 14 | namespace Intercom.Data 15 | { 16 | public class Visitor : User 17 | { 18 | public Visitor() 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Intercom/Enums/MessageType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Library 4 | { 5 | public enum MessageType 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /src/Intercom/Enums/OrderBy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | 7 | namespace Intercom.Core 8 | { 9 | public enum OrderBy 10 | { 11 | Asc, 12 | Dsc 13 | } 14 | } -------------------------------------------------------------------------------- /src/Intercom/Exceptions/ApiException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using RestSharp; 7 | 8 | namespace Intercom.Exceptions 9 | { 10 | public class ApiException : IntercomException 11 | { 12 | public int StatusCode { set; get; } 13 | public String StatusDescription { set; get; } 14 | public String ApiResponseBody { set; get; } 15 | public Errors ApiErrors { set; get; } 16 | 17 | public ApiException () 18 | :base() 19 | { 20 | } 21 | 22 | public ApiException (String message, Exception innerException) 23 | :base(message, innerException) 24 | { 25 | } 26 | 27 | public ApiException (int statusCode, String statusDescription, Errors apiErrors, String apiResponseBody) 28 | :base() 29 | { 30 | this.StatusCode = statusCode; 31 | this.StatusDescription = statusDescription; 32 | this.ApiErrors = apiErrors; 33 | this.ApiResponseBody = apiResponseBody; 34 | } 35 | 36 | public ApiException (String message, Exception innerException, int statusCode, String statusDescription, Errors apiErrors, String apiResponseBody) 37 | :base(message, innerException) 38 | { 39 | this.StatusCode = statusCode; 40 | this.StatusDescription = statusDescription; 41 | this.ApiErrors = apiErrors; 42 | this.ApiResponseBody = apiResponseBody; 43 | } 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /src/Intercom/Exceptions/IntercomException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Intercom.Core; 3 | using Intercom.Data; 4 | using Intercom.Clients; 5 | using Intercom.Exceptions; 6 | using RestSharp; 7 | 8 | namespace Intercom.Exceptions 9 | { 10 | public class IntercomException : Exception 11 | { 12 | public IntercomException () 13 | :base() 14 | { 15 | } 16 | 17 | public IntercomException (String message) 18 | :base(message) 19 | { 20 | } 21 | 22 | public IntercomException (String message, Exception innerException) 23 | :base(message, innerException) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Intercom/Exceptions/JsonConverterException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Intercom.Exceptions 4 | { 5 | public class JsonConverterException : IntercomException 6 | { 7 | public String Json { set; get; } 8 | public String SerializationType { set; get; } 9 | 10 | public JsonConverterException(String message) 11 | :base(message) 12 | { 13 | } 14 | 15 | public JsonConverterException (String message, Exception innerException) 16 | :base(message, innerException) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Intercom/Factories/RestClientFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RestSharp; 3 | using RestSharp.Authenticators; 4 | using Intercom.Core; 5 | 6 | namespace Intercom.Factories 7 | { 8 | public class RestClientFactory 9 | { 10 | 11 | private const String INTERCOM_API_BASE_URL = "https://api.intercom.io/"; 12 | private readonly Authentication _authentication; 13 | private readonly string _url; 14 | private IRestClient _restClient; 15 | 16 | private readonly object padlock = new object(); 17 | 18 | public RestClientFactory(Authentication authentication) 19 | { 20 | _authentication = authentication; 21 | _url = INTERCOM_API_BASE_URL; 22 | } 23 | 24 | public RestClientFactory(Authentication authentication, string url) 25 | { 26 | _authentication = authentication; 27 | _url = url; 28 | } 29 | 30 | public virtual IRestClient RestClient 31 | { 32 | get 33 | { 34 | lock(padlock) 35 | { 36 | if (_restClient != null) 37 | { 38 | return _restClient; 39 | } 40 | ConstructClient(); 41 | return _restClient; 42 | } 43 | } 44 | } 45 | 46 | private void ConstructClient() 47 | { 48 | RestClient client = new RestClient(_url); 49 | 50 | if (!String.IsNullOrEmpty (_authentication.AppId) && !String.IsNullOrEmpty (_authentication.AppKey)) 51 | client.Authenticator = new HttpBasicAuthenticator (_authentication.AppId, _authentication.AppKey); 52 | else 53 | client.Authenticator = new HttpBasicAuthenticator (_authentication.PersonalAccessToken, String.Empty); 54 | 55 | _restClient = client; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/Intercom/Intercom.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net452 5 | 3.0.0 6 | Intercom.Dotnet.Client 7 | https://raw.githubusercontent.com/intercom/intercom-dotnet/master/src/assets/Intercom.png 8 | Intercom 9 | https://github.com/intercom/intercom-dotnet 10 | The official Intercom API client library for .NET 11 | Intercom Dotnet Client 12 | The official Intercom API client library for .NET 13 | true 14 | 15 | 16 | 17 | 18 | 19 | 20 | all 21 | runtime; build; native; contentfiles; analyzers 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Intercom/intercom.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Intercom.Dotnet.Client 5 | Intercom Dotnet Client 6 | 3.0.0 7 | Intercom 8 | Intercom 9 | false 10 | 11 | The official Intercom API client library for .NET 12 | 13 | The official Intercom API client library for .NET 14 | https://github.com/intercom/intercom-dotnet 15 | https://raw.githubusercontent.com/intercom/intercom-dotnet/master/src/assets/Intercom.png 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/assets/Intercom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intercom/intercom-dotnet/c6354a2a07cd46b19b17d6ab1f9e0ef8d3a2ef67/src/assets/Intercom.png --------------------------------------------------------------------------------