Skip to content

Commit 6b8ac12

Browse files
thewheatchoran
authored andcommitted
Add permanent deletion support (#195)
1 parent 1250586 commit 6b8ac12

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,39 @@ 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+
* @deprecated Replaced by {@link #archive(Map)}. Renamed for consistency with API language
82+
*/
83+
@Deprecated
84+
public static User delete(Map<String, String> params)
85+
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
86+
return archive(params);
87+
}
88+
89+
public static User archive(Map<String, String> params)
90+
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
6591
return DataResource.delete(params, "users", User.class);
6692
}
6793

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 UserPermanentDeleteRequest {
11+
12+
@JsonProperty("intercom_user_id")
13+
private String intercomUserId;
14+
15+
public UserPermanentDeleteRequest() {
16+
}
17+
18+
public UserPermanentDeleteRequest(String intercomUserId) {
19+
this.setIntercomUserId(intercomUserId);
20+
}
21+
22+
public String getIntercomUserId() {
23+
return intercomUserId;
24+
}
25+
26+
public UserPermanentDeleteRequest setIntercomUserId(String intercomUserId) {
27+
this.intercomUserId = intercomUserId;
28+
return this;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "UserPermanentlyDeleteResponse{" +
34+
"intercomUserId='" + intercomUserId + '\'' +
35+
"} " + super.toString();
36+
}
37+
}
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+
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+
12+
@JsonProperty("id")
13+
private String id;
14+
15+
public UserPermanentDeleteResponse() {
16+
}
17+
18+
public String getId() {
19+
return id;
20+
}
21+
22+
public UserPermanentDeleteResponse setId(String id) {
23+
this.id = id;
24+
return this;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return "UserPermanentDeleteResponse{" +
30+
"id='" + id + '\'' +
31+
"} " + super.toString();
32+
}
33+
}

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)