(() => 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