Skip to content

Commit 168dfff

Browse files
author
Timothy Lim
committed
Add permanent deletion support
1 parent 70f3612 commit 168dfff

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,40 @@ public static User update(User user) throws InvalidException, AuthorizationExcep
5555
return DataResource.update(UserUpdate.buildFrom(user), "users", User.class);
5656
}
5757

58-
public static User delete(String id)
58+
/**
59+
* @deprecated Replaced by {@link #archive(String)}. Renamed for consistency with API language
60+
*/
61+
public static User delete(String id){
62+
return archive(id);
63+
}
64+
65+
public static User archive(String id)
5966
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
6067
return DataResource.delete(id, "users", User.class);
6168
}
6269

63-
public static User delete(Map<String, String> params)
70+
public static UserPermanentDeleteResponse permanentDelete(String id)
6471
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
72+
73+
final URI uri = UriBuilder.newBuilder()
74+
.path("user_delete_requests")
75+
.build();
76+
return new HttpClient(uri)
77+
.post(UserPermanentDeleteResponse.class, new UserPermanentDeleteRequest(id));
78+
79+
}
80+
81+
/**
82+
* @deprecated Replaced by {@link #archive(Map)}. Renamed for consistency with API language
83+
*/
84+
@Deprecated
85+
public static User delete(Map<String, String> params)
86+
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
87+
return archive(params);
88+
}
89+
90+
public static User archive(Map<String, String> params)
91+
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
6592
return DataResource.delete(params, "users", User.class);
6693
}
6794

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.intercom.api;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
@SuppressWarnings("UnusedDeclaration")
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
11+
public class UserPermanentDeleteRequest {
12+
@JsonProperty("intercom_user_id")
13+
private String intercomUserId;
14+
public UserPermanentDeleteRequest() {
15+
}
16+
public UserPermanentDeleteRequest(String intercomUserId) {
17+
this.setIntercomUserId(intercomUserId);
18+
}
19+
public String getIntercomUserId() {
20+
return intercomUserId;
21+
}
22+
23+
public UserPermanentDeleteRequest setIntercomUserId(String intercomUserId) {
24+
this.intercomUserId = intercomUserId;
25+
return this;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "UserPermanentlyDeleteResponse{" +
31+
"intercomUserId='" + intercomUserId + '\'' +
32+
"} " + super.toString();
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.intercom.api;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@SuppressWarnings("UnusedDeclaration")
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
10+
public class UserPermanentDeleteResponse {
11+
@JsonProperty("id")
12+
private String id;
13+
public UserPermanentDeleteResponse() {
14+
}
15+
public String getId() {
16+
return id;
17+
}
18+
19+
public UserPermanentDeleteResponse setId(String id) {
20+
this.id = id;
21+
return this;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return "UserPermanentDeleteResponse{" +
27+
"id='" + id + '\'' +
28+
"} " + super.toString();
29+
}
30+
31+
}

intercom-java/src/test/java/io/intercom/api/UserTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,11 @@ public void testBulkValidation() {
266266
assertTrue(e.getFirstError() != null);
267267
}
268268
}
269+
270+
@Test
271+
public void TestPermanentDelete() throws Exception{
272+
String json = load("permanent_delete_response.json");
273+
final UserPermanentDeleteResponse userPermanentDeleteResponse= mapper.readValue(json, UserPermanentDeleteResponse.class);
274+
assertEquals("123456", userPermanentDeleteResponse.getId());
275+
}
269276
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"id": 123456
3+
}

0 commit comments

Comments
 (0)