|
6 | 6 | import com.fasterxml.jackson.annotation.JsonInclude; |
7 | 7 | import com.fasterxml.jackson.annotation.JsonProperty; |
8 | 8 | import com.google.common.annotations.VisibleForTesting; |
| 9 | +import com.google.common.base.Strings; |
9 | 10 | import com.google.common.collect.Maps; |
10 | 11 |
|
11 | 12 | import java.net.URI; |
@@ -66,7 +67,27 @@ public static Contact update(Contact c) |
66 | 67 |
|
67 | 68 | public static Contact delete(Contact c) |
68 | 69 | throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException { |
69 | | - return DataResource.delete(c.getID(), "contacts", Contact.class); |
| 70 | + if(!Strings.isNullOrEmpty(c.getID())) { |
| 71 | + return delete(c.getID()); |
| 72 | + } |
| 73 | + else if(!Strings.isNullOrEmpty(c.getUserID())) { |
| 74 | + return deleteByUserID(c.getUserID()); |
| 75 | + } |
| 76 | + else { |
| 77 | + throw new InvalidException("to delete a contact you must provide a id or user_id value"); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public static Contact delete(String id) |
| 82 | + throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException { |
| 83 | + return DataResource.delete(id, "contacts", Contact.class); |
| 84 | + } |
| 85 | + |
| 86 | + public static Contact deleteByUserID(String user_id) |
| 87 | + throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException { |
| 88 | + Map<String, String> params = new HashMap<String,String>(); |
| 89 | + params.put("user_id", user_id); |
| 90 | + return DataResource.delete(params, "contacts", Contact.class); |
70 | 91 | } |
71 | 92 |
|
72 | 93 | public static User convert(Contact c, User u) |
@@ -416,8 +437,7 @@ public String getID() { |
416 | 437 | return id; |
417 | 438 | } |
418 | 439 |
|
419 | | - @VisibleForTesting |
420 | | - Contact setID(String id) { |
| 440 | + public Contact setID(String id) { |
421 | 441 | this.id = id; |
422 | 442 | return this; |
423 | 443 | } |
@@ -457,6 +477,11 @@ public String getUserID() { |
457 | 477 | return userID; |
458 | 478 | } |
459 | 479 |
|
| 480 | + public Contact setUserID(String userID) { |
| 481 | + this.userID = userID; |
| 482 | + return this; |
| 483 | + } |
| 484 | + |
460 | 485 | public Avatar getAvatar() { |
461 | 486 | return avatar; |
462 | 487 | } |
|
0 commit comments