Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Add destroy feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vergnesOL committed Feb 17, 2012
1 parent 00990e7 commit a977570
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface FriendOperations {

WeiboProfile createFriend(long uid);

WeiboProfile deleteFriend(long uid);

List<WeiboProfile> getActiveFollowers(long uid);

List<WeiboProfile> getActiveFollowers(long uid, int pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ protected FriendTemplate(ObjectMapper objectMapper,
super(objectMapper, restTemplate, isAuthorized);
}

@Override
public WeiboProfile createFriend(long uid) {
requireAuthorization();
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
1);
request.add("uid", String.valueOf(uid));
return restTemplate.postForObject(buildUri("friendships/create.json"),
request, WeiboProfile.class);
}

@Override
public WeiboProfile deleteFriend(long uid) {
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
1);
request.add("uid", String.valueOf(uid));
return restTemplate.postForObject(buildUri("friendships/destroy.json"),
request, WeiboProfile.class);
}

private CursoredList<WeiboProfile> fetchUsersList(String url, long uid,
int pageSize, int pageNumber) {
requireAuthorization();
Expand Down Expand Up @@ -139,14 +158,4 @@ public CursoredList<WeiboProfile> getFriends(long uid, int pageSize,
return fetchUsersList("friendships/friends.json", uid, pageSize,
pageNumber);
}

@Override
public WeiboProfile createFriend(long uid) {
requireAuthorization();
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
1);
request.add("uid", String.valueOf(uid));
return restTemplate.postForObject(buildUri("friendships/create.json"),
request, WeiboProfile.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,18 @@ public void testGetFriendsPagination() {
assertEquals(1, friends.getNextCursor());
}

@Test
public void testDeleteFriend() {
mockServer
.expect(requestTo("https://api.weibo.com/2/friendships/destroy.json"))
.andExpect(method(POST))
.andExpect(body("uid=1"))
.andExpect(header("Authorization", "OAuth2 accessToken"))
.andRespond(
withResponse(jsonResource("profile"), responseHeaders));

WeiboProfile user = friendTemplate.deleteFriend(1L);
verifyWeiboProfile(user);
}

}

0 comments on commit a977570

Please sign in to comment.