Skip to content

Commit c602782

Browse files
committed
Merge branch 'master' into savicprvoslav-master
2 parents 81d8d64 + 12f251e commit c602782

File tree

16 files changed

+180
-47
lines changed

16 files changed

+180
-47
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Please use the following template to submit your issue. Following this template will allow us to quickly investigate and help you with your issue. Please be aware that issues which do not conform to this template may be closed.
2+
3+
For feature requests please contact us at [email protected]
4+
5+
6+
## Version info
7+
- intercom-java version:
8+
- Java version:
9+
10+
## Expected behavior
11+
12+
## Actual behavior
13+
14+
## Steps to reproduce
15+
1.
16+
2.
17+
3.
18+
19+
## Logs

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: java

CHANGES.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
### Changes
22

3+
#### 2.2.0
4+
5+
- Include company custom attributes when updating a user with an embedded company object
6+
- Include support for Personal Access Token API access
7+
8+
#### 2.1.0
9+
10+
- Dynamically retrieve the parts for a conversation if not present
11+
12+
#### 2.0.0
13+
14+
- Fixes subscription metadata deserialization
15+
316
#### 1.3.1
417

518
- Fixes company removal
619

720
#### 1.3.0
821

922
- Is a rollup of the 1.3.0 beta releases.
10-
23+
1124
#### 1.3.0-b3
1225

1326
- Configure Jackson ObjectMapper once [76](https://github.com/intercom/intercom-java/issues/76)
1427

1528
#### 1.3.0-b2
1629

17-
- Allow users to be removed from companies.
30+
- Allow users to be removed from companies.
1831

1932
#### 1.3.0-b1
2033

21-
- Support bulk user and event submission. Save your request rate limit for
34+
- Support bulk user and event submission. Save your request rate limit for
2235
a rainy day! You can post and delete users, and post events.
2336

24-
- Add a currentTimestamp() helper to Intercom. This divides currentTimeMillis
37+
- Add a currentTimestamp() helper to Intercom. This divides currentTimeMillis
2538
by 1000 to produce a second level value.
2639

2740
#### 1.2.1
@@ -30,13 +43,13 @@ by 1000 to produce a second level value.
3043

3144
#### 1.2.0
3245

33-
- Allow conversations to be assigned to others on your team. Conversations
34-
are the most beautiful things, and now you can share them with others through
46+
- Allow conversations to be assigned to others on your team. Conversations
47+
are the most beautiful things, and now you can share them with others through
3548
the API.
3649

3750
- Support closing and opening conversations, either directly or with a reply.
38-
39-
51+
52+
4053
#### 1.1.2
4154

4255
- make setUserAgentData public. Previously this was a protected method.
@@ -47,17 +60,17 @@ the API.
4760

4861
#### 1.1.0
4962

50-
- add support for [Contacts](https://github.com/intercom/intercom-java#contacts)
63+
- add support for [Contacts](https://github.com/intercom/intercom-java#contacts)
5164

5265
#### 1.0.9
5366

54-
- remove secondary getters on user that stop older jackson versions working [48](https://github.com/intercom/intercom-java/issues/45) (caused in [40](https://github.com/intercom/intercom-java/issues/48)). Doing a bang up job on regression bugs atm.
67+
- remove secondary getters on user that stop older jackson versions working [48](https://github.com/intercom/intercom-java/issues/45) (caused in [40](https://github.com/intercom/intercom-java/issues/48)). Doing a bang up job on regression bugs atm.
5568

5669
#### 1.0.8
5770

5871
- fix user update regression [45](https://github.com/intercom/intercom-java/issues/45) (caused in [40](https://github.com/intercom/intercom-java/issues/40))
59-
60-
- don't send values for `unsubscribed_from_emails`, `update_last_request_at` or `new_session` unless set
72+
73+
- don't send values for `unsubscribed_from_emails`, `update_last_request_at` or `new_session` unless set
6174

6275
#### 1.0.7
6376

@@ -73,7 +86,7 @@ allow the signed_up_at user field to be submitted
7386

7487
#### 1.0.4
7588

76-
allow the intercom user id field to be submitted
89+
allow the intercom user id field to be submitted
7790

7891
#### 1.0.3
7992

@@ -86,21 +99,21 @@ encode social profile urls for user objects
8699
#### 1.0.1
87100

88101
- send custom company attributes on update
89-
102+
90103
- fix NPE when company has no plan on update
91-
92-
- invalidate setSessionCount on Company [27](https://github.com/intercom/intercom-java/issues/27)
104+
105+
- invalidate setSessionCount on Company [27](https://github.com/intercom/intercom-java/issues/27)
93106

94107
#### 1.0.0
95108

96109
- removed tag methods requiring collections
97-
110+
98111
- handle non-json error entities from server
99112

100113
#### 0.1.0
101114

102115
- support untag of users and companies
103-
116+
104117
- renamed of current page and page methods on collections (breaking)
105118

106119
#### 0.0.5

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Java bindings for the [Intercom API](https://api.intercom.io/docs)
66

7-
- [Installation](#installation)
7+
- [Installation](#add-a-dependency)
88
- [Resources](#resources)
99
- [Authorization](#authorization)
1010
- [Usage](#usage)
@@ -38,7 +38,7 @@ and add the project declaration to your `pom.xml`:
3838
<dependency>
3939
<groupId>io.intercom</groupId>
4040
<artifactId>intercom-java</artifactId>
41-
<version>1.3.1</version>
41+
<version>2.2.0</version>
4242
</dependency>
4343
```
4444

@@ -56,7 +56,7 @@ and add the project to the `dependencies` block in your `build.gradle`:
5656

5757
```groovy
5858
dependencies {
59-
compile 'io.intercom:intercom-java:1.3.1'
59+
compile 'io.intercom:intercom-java:2.2.0'
6060
}
6161
```
6262

@@ -71,7 +71,7 @@ resolvers += "jcenter" at "http://jcenter.bintray.com"
7171
and add the project to your `libraryDependencies` in your `build.sbt`:
7272

7373
```scala
74-
libraryDependencies += "io.intercom" % "intercom-java" % "1.3.1"
74+
libraryDependencies += "io.intercom" % "intercom-java" % "2.2.0"
7575
```
7676

7777
## Resources
@@ -95,14 +95,22 @@ Resources this API supports:
9595

9696
## Authorization
9797

98-
You can set the app's id and api key via the `Intercom` object -
98+
99+
If you're using a Personal Access Token (PAT) you can just use the following helper method, which will automatically set up the authentication scheme for you -
100+
101+
```java
102+
Intercom.setToken("da39a3ee5e6b4b0d3255bfef95601890afd80709");
103+
```
104+
105+
If you're still using API Keys (now deprecated), you can set up your App ID and API Key using the following methods -
99106

100107
```java
101108
Intercom.setAppID("pi3243fa");
102109
Intercom.setApiKey("da39a3ee5e6b4b0d3255bfef95601890afd80709");
103110
```
104111

105112

113+
106114
## Usage
107115

108116
### Users
@@ -155,6 +163,10 @@ User.submit(moreItems, job);
155163

156164
//View a bulk job error feed
157165
User.listJobErrorFeed(jobId)
166+
167+
// Delete a user
168+
User user = User.find("541a144b201ebf2ec5000001");
169+
User.delete(user.getId());
158170
```
159171

160172
### Contacts
@@ -272,8 +284,8 @@ System.out.println(job.getID());
272284

273285
// Bulk submit, add to an existing job
274286
final List<JobItem<Event>> moreItems = Lists.newArrayList();
275-
items.add(new JobItem<Event>("post", event4));
276-
items.add(new JobItem<Event>("delete", event5));
287+
moreItems.add(new JobItem<Event>("post", event4));
288+
moreItems.add(new JobItem<Event>("delete", event5));
277289
Event.submit(moreItems, job);
278290

279291
//View a bulk job error feed
@@ -414,7 +426,7 @@ while (userConversations.hasNext()) {
414426
final Conversation conversation = Conversation.find("66");
415427
ConversationMessage conversationMessage = conversation.getConversationMessage();
416428
ConversationPartCollection parts = conversation.getConversationPartCollection();
417-
List<ConversationPart> partList = parts.getPageItems();
429+
List<ConversationPart> partList = parts.getPage();
418430
for (ConversationPart part : partList) {
419431
String partType = part.getPartType();
420432
Author author = part.getAuthor();
@@ -435,6 +447,7 @@ ConversationCollection openForAdmin = Conversation.list(params);
435447
Admin admin = new Admin().setId("1");
436448
AdminReply adminReply = new AdminReply(admin);
437449
adminReply.setBody("These apples are healthsome");
450+
adminReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); // optional - list of attachments
438451
Conversation.reply("66", adminReply);
439452

440453
// admin close
@@ -447,6 +460,7 @@ Conversation.reply("66", adminReply);
447460
User user1 = new User().setId("5310d8e8598c9a0b24000005");
448461
UserReply userReply = new UserReply(user1);
449462
userReply.setBody("Mighty fine shindig");
463+
userReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); // optional - list of attachments
450464
System.out.println(MapperSupport.objectMapper().writeValueAsString(userReply));
451465
Conversation.reply("66", userReply);
452466
```
@@ -575,7 +589,7 @@ Some API classes have static `list()` methods that correspond to paginated API r
575589
These return a Collection object (eg `UserCollection`) which can be iterated in two
576590
ways
577591

578-
- The collection's `getPageItems()`, `hasNextPage()` and `nextPage()` methods - these are useful when you want to fetch one or just a few pages directly.
592+
- The collection's `getPage()`, `hasNextPage()` and `nextPage()` methods - these are useful when you want to fetch one or just a few pages directly.
579593

580594
- Java's inbuilt iterator methods `next()` and `hasNext()` - these are useful when you want to fetch data without manually handling pagination.
581595

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.3.1
1+
version: 2.2.0
22

33
groupId: io.intercom
44

intercom-java/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ publishing {
4444
bintray {
4545
// gradle apslodes if the bintray* props aren't found and we never run this task in circle
4646
if (System.getenv('release') != null) {
47-
user = bintrayUser
48-
key = bintrayKey
47+
user = System.getenv('BINTRAY_USER')
48+
key = System.getenv('BINTRAY_KEY')
4949
}
5050
publications = ['mavenJava']
5151
dryRun = false

intercom-java/src/main/java/io/intercom/api/AdminReply.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public String getAdminID() {
4646
public String getAssigneeID() {
4747
return reply.getAssigneeID();
4848
}
49+
50+
@JsonProperty("attachment_urls")
51+
private String[] getAttachmentUrls() {
52+
return reply.getAttachmentUrls();
53+
}
4954
}
5055

5156
@JsonProperty("assignee_id")

intercom-java/src/main/java/io/intercom/api/CompanyUpdateBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ private static CompanyWithStringPlan prepareUpdatableCompany(Company company) {
5858
updatableCompany.setSessionCount(company.getSessionCount());
5959
updatableCompany.setMonthlySpend(company.getMonthlySpend());
6060
updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt());
61+
if(company.getCustomAttributes() != null) {
62+
updatableCompany.getCustomAttributes().putAll(company.getCustomAttributes());
63+
}
6164
if (company.getPlan() != null) {
6265
updatableCompany.setPlan(company.getPlan().getName());
6366
}

intercom-java/src/main/java/io/intercom/api/Conversation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ public long getUpdatedAt() {
265265
}
266266

267267
public ConversationPartCollection getConversationPartCollection() {
268+
if (conversationPartCollection == null || conversationPartCollection.getPage().isEmpty()) {
269+
this.conversationPartCollection = find(this.getId()).getConversationPartCollection();
270+
}
271+
268272
return conversationPartCollection;
269273
}
270274

intercom-java/src/main/java/io/intercom/api/HttpClient.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ private static String clientAgentDetails() {
5959

6060
private final Map<String, String> headers;
6161

62-
private final String apiKey = Intercom.getApiKey();
63-
6462
private final HttpConnectorSupplier connection = Intercom.getHttpConnectorSupplier();
6563

6664
public HttpClient(URI uri) {
@@ -229,15 +227,21 @@ private HttpURLConnection prepareConnection(HttpURLConnection conn) {
229227
}
230228

231229
private Map<String, String> createAuthorizationHeaders() {
232-
if (Intercom.getAuthScheme().equals(Intercom.AUTH_BEARER)) {
233-
headers.put("Authorization", "Bearer " + apiKey);
234-
} else if (Intercom.getAuthScheme().equals(Intercom.AUTH_BASIC)) {
235-
final String authString = Intercom.getAppID() + ":" + Intercom.getApiKey();
236-
headers.put("Authorization", "Basic " + Base64.encodeBase64String(authString.getBytes()));
230+
switch (Intercom.getAuthKeyType()) {
231+
case API_KEY:
232+
headers.put("Authorization", "Basic " + generateAuthString(Intercom.getAppID(),Intercom.getApiKey()));
233+
break;
234+
case TOKEN:
235+
headers.put("Authorization", "Basic " + generateAuthString(Intercom.getToken(),""));
236+
break;
237237
}
238238
return headers;
239239
}
240240

241+
private String generateAuthString(String username, String password) {
242+
return Base64.encodeBase64String((username + ":" + password).getBytes());
243+
}
244+
241245
private Map<String, String> createHeaders() {
242246
headers.put("User-Agent", USER_AGENT);
243247
headers.put("X-Client-Platform-Details", CLIENT_AGENT_DETAILS);

0 commit comments

Comments
 (0)