Skip to content

Commit

Permalink
Add support for un ban API.
Browse files Browse the repository at this point in the history
  • Loading branch information
amatkivskiy committed Dec 25, 2016
1 parent 27b9926 commit b7b7f08
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ void updateMessage(@Path("roomId") String roomId,
@POST("/rooms/{roomId}/bans")
void banUser(@Path("roomId") String roomId, @Field("username") String username,
Callback<BanResponse> callback);

@DELETE("/rooms/{roomId}/bans/{username}")
void unBanUser(@Path("roomId") String roomId, @Path("username") String username,
Callback<BooleanResponse> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void getGroupRooms(String groupId, Callback<List<RoomResponse>> callback)
}

// Ban API
void getBannedUsers(String roomId, Callback<List<BanResponse>> callback) {
public void getBannedUsers(String roomId, Callback<List<BanResponse>> callback) {
api.getBannedUsers(roomId, callback);
}

Expand All @@ -211,10 +211,14 @@ void getBannedUsers(String roomId, Callback<List<BanResponse>> callback) {
* @param username name of the user.
* @param callback callback for the request.
*/
void banUser(String roomId, String username, Callback<BanResponse> callback) {
public void banUser(String roomId, String username, Callback<BanResponse> callback) {
api.banUser(roomId, username, callback);
}

public void unBanUser(String roomId, String username, Callback<BooleanResponse> callback) {
api.unBanUser(roomId, username, callback);
}

public static class Builder extends GitterApiBuilder<Builder, AsyncGitterApiClient> {

protected String getFullEndpointUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ Observable<MessageResponse> updateMessage(@Path("roomId") String roomId,
@FormUrlEncoded
@POST("/rooms/{roomId}/bans")
Observable<BanResponse> banUser(@Path("roomId") String roomId, @Field("username") String username);

@DELETE("/rooms/{roomId}/bans/{username}")
Observable<BooleanResponse> unBanUser(@Path("roomId") String roomId, @Path("username") String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public Observable<BanResponse> banUser(String roomId, String username) {
return api.banUser(roomId, username);
}

public Observable<BooleanResponse> unBanUser(String roomId, String username) {
return api.unBanUser(roomId, username);
}

public static class Builder extends GitterApiBuilder<Builder, RxGitterApiClient> {

protected String getFullEndpointUrl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.amatkivskiy.gitter.sdk.rx.ban;

import com.amatkivskiy.gitter.sdk.model.response.BooleanResponse;
import com.amatkivskiy.gitter.sdk.model.response.ban.BanResponse;
import com.amatkivskiy.gitter.sdk.rx.TestBuilder;
import com.amatkivskiy.gitter.sdk.rx.client.RxGitterApiClient;
Expand Down Expand Up @@ -118,4 +119,33 @@ public void testBanPrivateRoomUserFails() throws Exception {
assertThat(response.bannedBy, is(nullValue()));
assertThat(response.dateBanned, is(nullValue()));
}

@Test
public void testUnBanRoomUserCorrect() throws Exception {
// ARRANGE
String roomId = "test_room_id";
String userName = "amatkivskiy";
this.mockWebServer.enqueue(createStringMockedResponse("{\"success\":true}"));
TestSubscriber<BooleanResponse> testSubscriber = TestSubscriber.create();

// ACT
this.gitterApiClient.unBanUser(roomId, userName).subscribe(testSubscriber);

// ASSERT
// Assert RxGitterApiClient pass correct params in the request URL
HttpUrl url = getRequestUrl(this.mockWebServer);
// check number of path segments in url
assertThat(url.pathSegments().size(), is(6));
// get room id path segment
assertThat(url.pathSegments().get(3), is(roomId));
assertThat(url.pathSegments().get(4), is("bans"));
assertThat(url.pathSegments().get(5), is(userName));

// check received result
assertSuccessfulResult(testSubscriber);
BooleanResponse response = getOnNextEvent(testSubscriber);

assertThat(response, is(notNullValue()));
assertThat(response.success, is(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ MessageResponse updateMessage(@Path("roomId") String roomId,
@FormUrlEncoded
@POST("/rooms/{roomId}/bans")
BanResponse banUser(@Path("roomId") String roomId, @Field("username") String username);

@DELETE("/rooms/{roomId}/bans/{username}")
BooleanResponse unBanUser(@Path("roomId") String roomId, @Path("username") String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public BanResponse banUser(String roomId, String username) {
return api.banUser(roomId, username);
}

public BooleanResponse unBanUser(String roomId, String username) {
return api.unBanUser(roomId, username);
}

public static class Builder extends GitterApiBuilder<Builder, SyncGitterApiClient> {

protected String getFullEndpointUrl() {
Expand Down

0 comments on commit b7b7f08

Please sign in to comment.