Skip to content

Commit 08ff2f9

Browse files
committed
Contacts support
1 parent 531a782 commit 08ff2f9

File tree

7 files changed

+648
-21
lines changed

7 files changed

+648
-21
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ libraryDependencies += "io.intercom" % "intercom-java" % "1.0.9"
7979
Resources this API supports:
8080

8181
- [Users](#users)
82+
- [Contacts](#contacts)
8283
- [Companies](#companies)
8384
- [Admins](#admins)
8485
- [Events](#events)
@@ -139,6 +140,41 @@ while(users.hasNext()) {
139140
}
140141
```
141142

143+
### Contacts
144+
145+
_Contacts were added in version 1.1 of the client._
146+
147+
```java
148+
// Create a Contact
149+
Contact contact = new Contact()
150+
.setEmail("[email protected]")
151+
.addCustomAttribute(newStringAttribute("role", "fence"));
152+
Contact created = Contact.create(contact);
153+
154+
// Find a single contact by server supplied user id or id
155+
contact = Contact.findByID("541a144b201ebf2ec5000002");
156+
contact = Contact.findByUserID("e1a7d875-d83a-46f7-86f4-73be98a98584);
157+
158+
// Update a contact
159+
contact.setName("Stitch Hessian");
160+
Contact updated = Contact.update(contact);
161+
162+
// Read a contact list by email
163+
Contact contacts = Contact.listByEmail("jubal@serenity.io");
164+
while(contacts.hasNext()) {
165+
System.out.println(contacts.next());
166+
}
167+
168+
// Iterate over all contacts
169+
Contact allContacts = Contact.list();
170+
while(allContacts.hasNext()) {
171+
System.out.println(allContacts.next());
172+
}
173+
174+
// Remove a contact
175+
Contact.delete(contact);
176+
```
177+
142178
### Companies
143179
144180
```java
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.intercom.api;
2+
3+
4+
import com.google.common.collect.Lists;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
class CompanyUpdateBuilder {
10+
11+
/**
12+
* Provide restrictions on the company data that can be sent via a user update
13+
*/
14+
static List<CompanyWithStringPlan> buildUserUpdateCompanies(CompanyCollection c) {
15+
final ArrayList<CompanyWithStringPlan> updatableCompanies = Lists.newArrayList();
16+
if (c != null) {
17+
final List<Company> companies = c.getPage();
18+
for (Company company : companies) {
19+
final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan();
20+
updatableCompany.setCompanyID(company.getCompanyID());
21+
updatableCompany.setName(company.getName());
22+
updatableCompany.setSessionCount(company.getSessionCount());
23+
updatableCompany.setMonthlySpend(company.getMonthlySpend());
24+
updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt());
25+
if (company.getPlan() != null) {
26+
updatableCompany.setPlan(company.getPlan().getName());
27+
}
28+
updatableCompanies.add(updatableCompany);
29+
}
30+
}
31+
return updatableCompanies;
32+
}
33+
}

0 commit comments

Comments
 (0)