Skip to content

Commit e7f2eeb

Browse files
committed
Implement the user rooms api for the chat
1 parent 7183588 commit e7f2eeb

6 files changed

Lines changed: 96 additions & 2 deletions

File tree

library/src/main/java/me/proxer/library/api/chat/ChatApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public PublicChatRoomsEndpoint publicRooms() {
2525
return new PublicChatRoomsEndpoint(internalApi);
2626
}
2727

28+
/**
29+
* Returns the respective endpoint.
30+
*/
31+
public UserChatRoomsEndpoint userRooms() {
32+
return new UserChatRoomsEndpoint(internalApi);
33+
}
34+
2835
/**
2936
* Returns the respective endpoint.
3037
*/

library/src/main/java/me/proxer/library/api/chat/InternalApi.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public interface InternalApi {
2121
@GET("chat/publicrooms")
2222
ProxerCall<List<ChatRoom>> publicRooms();
2323

24+
@GET("chat/myrooms")
25+
ProxerCall<List<ChatRoom>> userRooms();
26+
2427
@GET("chat/messages")
2528
ProxerCall<List<ChatMessage>> messages(@Query("room_id") String roomId,
2629
@Query("message_id") String messageId);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.proxer.library.api.chat;
2+
3+
import lombok.experimental.Accessors;
4+
import me.proxer.library.api.Endpoint;
5+
import me.proxer.library.api.ProxerCall;
6+
import me.proxer.library.entity.chat.ChatRoom;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Endpoint for retrieving the used chat rooms of a user.
12+
* Requires a user to be logged in.
13+
*
14+
* @author Ruben Gees
15+
*/
16+
@Accessors(fluent = true)
17+
public final class UserChatRoomsEndpoint implements Endpoint<List<ChatRoom>> {
18+
19+
private final InternalApi internalApi;
20+
21+
UserChatRoomsEndpoint(final InternalApi internalApi) {
22+
this.internalApi = internalApi;
23+
}
24+
25+
/**
26+
* {@inheritDoc}
27+
*/
28+
@Override
29+
public ProxerCall<List<ChatRoom>> build() {
30+
return internalApi.userRooms();
31+
}
32+
}

library/src/test/java/me/proxer/library/api/chat/PublicChatRoomsEndpointTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PublicChatRoomsEndpointTest extends ProxerTest {
1818

1919
@Test
2020
public void testDefault() throws IOException, ProxerException {
21-
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms_public.json")));
21+
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms.json")));
2222

2323
final List<ChatRoom> result = api.chat()
2424
.publicRooms()
@@ -31,7 +31,7 @@ public void testDefault() throws IOException, ProxerException {
3131

3232
@Test
3333
public void testPath() throws ProxerException, IOException, InterruptedException {
34-
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms_public.json")));
34+
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms.json")));
3535

3636
api.chat().publicRooms()
3737
.build()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package me.proxer.library.api.chat;
2+
3+
import me.proxer.library.ProxerTest;
4+
import me.proxer.library.api.ProxerException;
5+
import me.proxer.library.entity.chat.ChatRoom;
6+
import okhttp3.mockwebserver.MockResponse;
7+
import org.junit.Test;
8+
9+
import java.io.IOException;
10+
import java.util.List;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
/**
15+
* @author Ruben Gees
16+
*/
17+
public class UserChatRoomsEndpointTest extends ProxerTest {
18+
19+
@Test
20+
public void testDefault() throws IOException, ProxerException {
21+
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms.json")));
22+
23+
final List<ChatRoom> result = api.chat()
24+
.userRooms()
25+
.build()
26+
.execute();
27+
28+
assertThat(result).first().isEqualTo(buildFirstTestRoom());
29+
assertThat(result).last().isEqualTo(buildLastTestRoom());
30+
}
31+
32+
@Test
33+
public void testPath() throws ProxerException, IOException, InterruptedException {
34+
server.enqueue(new MockResponse().setBody(fromResource("chat_rooms.json")));
35+
36+
api.chat().userRooms()
37+
.build()
38+
.execute();
39+
40+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/chat/myrooms");
41+
}
42+
43+
private ChatRoom buildFirstTestRoom() {
44+
return new ChatRoom("1", "Proxer.Me Hauptchat", "Willkommen im Proxer-Chat!",
45+
false, false);
46+
}
47+
48+
private ChatRoom buildLastTestRoom() {
49+
return new ChatRoom("6", "Chat-Ankündigungen (21.03.18)", "",
50+
true, false);
51+
}
52+
}
File renamed without changes.

0 commit comments

Comments
 (0)