Skip to content

Commit dc902b9

Browse files
committed
Implement forum discussion api
1 parent cd0c240 commit dc902b9

6 files changed

Lines changed: 223 additions & 14 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.proxer.library.api.info;
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.info.ForumDiscussion;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Endpoint for retrieving the list of forum discussions associated with an {@link me.proxer.library.entity.info.Entry}.
12+
*
13+
* @author Ruben Gees
14+
*/
15+
@Accessors(fluent = true)
16+
public class ForumDiscussionsEndpoint implements Endpoint<List<ForumDiscussion>> {
17+
18+
private final InternalApi internalApi;
19+
20+
private final String id;
21+
22+
ForumDiscussionsEndpoint(final InternalApi internalApi, final String id) {
23+
this.internalApi = internalApi;
24+
this.id = id;
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
@Override
31+
public ProxerCall<List<ForumDiscussion>> build() {
32+
return internalApi.forumDiscussions(id);
33+
}
34+
}

library/src/main/java/me/proxer/library/api/info/InfoApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,11 @@ public RecommendationsEndpoint recommendations(final String entryId) {
101101
public MediaUserInfoEndpoint userInfo(final String entryId) {
102102
return new MediaUserInfoEndpoint(internalApi, entryId);
103103
}
104+
105+
/**
106+
* Returns the respective endpoint.
107+
*/
108+
public ForumDiscussionsEndpoint forumDiscussions(final String entryId) {
109+
return new ForumDiscussionsEndpoint(internalApi, entryId);
110+
}
104111
}

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
package me.proxer.library.api.info;
22

33
import me.proxer.library.api.ProxerCall;
4-
import me.proxer.library.entity.info.Comment;
5-
import me.proxer.library.entity.info.Entry;
6-
import me.proxer.library.entity.info.EntryCore;
7-
import me.proxer.library.entity.info.EpisodeInfo;
8-
import me.proxer.library.entity.info.Industry;
9-
import me.proxer.library.entity.info.MediaUserInfo;
10-
import me.proxer.library.entity.info.Recommendation;
11-
import me.proxer.library.entity.info.Relation;
12-
import me.proxer.library.entity.info.TranslatorGroup;
4+
import me.proxer.library.entity.info.*;
135
import me.proxer.library.enums.CommentSortCriteria;
14-
import retrofit2.http.Field;
15-
import retrofit2.http.FormUrlEncoded;
16-
import retrofit2.http.GET;
17-
import retrofit2.http.POST;
18-
import retrofit2.http.Query;
6+
import retrofit2.http.*;
197

208
import javax.annotation.ParametersAreNullableByDefault;
219
import java.util.List;
@@ -63,4 +51,7 @@ ProxerCall<Void> modifyUserInfo(@Field("id") String id,
6351

6452
@GET("info/userinfo")
6553
ProxerCall<MediaUserInfo> userInfo(@Query("id") String id);
54+
55+
@GET("info/forum")
56+
ProxerCall<List<ForumDiscussion>> forumDiscussions(@Query("id") String id);
6657
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package me.proxer.library.entity.info;
2+
3+
import com.squareup.moshi.Json;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.Getter;
6+
import lombok.Value;
7+
import me.proxer.library.entity.ProxerIdItem;
8+
9+
import javax.annotation.Nullable;
10+
import java.util.Date;
11+
12+
/**
13+
* Entity containing meta information about a single forum discussion.
14+
*
15+
* @author Ruben Gees
16+
*/
17+
@Value
18+
@EqualsAndHashCode(onParam = @__({@Nullable}))
19+
public class ForumDiscussion implements ProxerIdItem {
20+
21+
/**
22+
* Returns the id.
23+
*/
24+
@Getter(onMethod = @__({@Override}))
25+
@Json(name = "id")
26+
private String id;
27+
28+
/**
29+
* Returns the id of the category.
30+
*/
31+
@Json(name = "category_id")
32+
private String categoryId;
33+
34+
/**
35+
* Returns the subject.
36+
*/
37+
@Json(name = "subject")
38+
private String subject;
39+
40+
/**
41+
* Returns the amount of posts.
42+
*/
43+
@Json(name = "posts")
44+
private int posts;
45+
46+
/**
47+
* Returns the amount of hits.
48+
*/
49+
@Json(name = "hits")
50+
private int hits;
51+
52+
/**
53+
* Returns the date of the first post.
54+
*/
55+
@Json(name = "first_post_time")
56+
private Date firstPostDate;
57+
58+
/**
59+
* Returns the user id of the author of the first post.
60+
*/
61+
@Json(name = "first_post_userid")
62+
private String firstPostUserId;
63+
64+
/**
65+
* Returns the username of the author of the first post.
66+
*/
67+
@Json(name = "first_post_guest_name")
68+
private String firstPostUsername;
69+
70+
/**
71+
* Returns the date of the last post.
72+
*/
73+
@Json(name = "last_post_time")
74+
private Date lastPostDate;
75+
76+
/**
77+
* Returns the user id of the author of the last post.
78+
*/
79+
@Json(name = "last_post_userid")
80+
private String lastPostUserId;
81+
82+
/**
83+
* Returns the username of the author of the last post.
84+
*/
85+
@Json(name = "last_post_guest_name")
86+
private String lastPostUsername;
87+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package me.proxer.library.api.info;
2+
3+
import me.proxer.library.ProxerTest;
4+
import me.proxer.library.api.ProxerException;
5+
import me.proxer.library.entity.info.ForumDiscussion;
6+
import okhttp3.mockwebserver.MockResponse;
7+
import org.junit.Test;
8+
9+
import java.io.IOException;
10+
import java.util.Date;
11+
import java.util.List;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
/**
16+
* @author Ruben Gees
17+
*/
18+
public class ForumDiscussionsEndpointTest extends ProxerTest {
19+
20+
@Test
21+
public void testDefault() throws IOException, ProxerException {
22+
server.enqueue(new MockResponse().setBody(fromResource("info_forum.json")));
23+
24+
final List<ForumDiscussion> result = api.info()
25+
.forumDiscussions("1")
26+
.build()
27+
.execute();
28+
29+
assertThat(result).first().isEqualTo(buildFirstTestForumDiscussion());
30+
assertThat(result).last().isEqualTo(buildLastTestForumDiscussion());
31+
}
32+
33+
@Test
34+
public void testPath() throws ProxerException, IOException, InterruptedException {
35+
server.enqueue(new MockResponse().setBody(fromResource("info_forum.json")));
36+
37+
api.info().forumDiscussions("3")
38+
.build()
39+
.execute();
40+
41+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/info/forum?id=3");
42+
}
43+
44+
private ForumDiscussion buildFirstTestForumDiscussion() {
45+
return new ForumDiscussion("384098", "281", "Overlord II - Diskussionsthread",
46+
15, 749, new Date(1514199320 * 1000L), "351626", "Asuka..",
47+
new Date(1517246199 * 1000L), "506979", "5devilz");
48+
}
49+
50+
private ForumDiscussion buildLastTestForumDiscussion() {
51+
return new ForumDiscussion("381421", "56",
52+
"Overlord II – neues Visual, weitere Charaktere und Synchronsprecher enthüllt",
53+
35, 32334, new Date(1489228544 * 1000L), "19328", "Moeface",
54+
new Date(1514078674 * 1000L), "470614", "..Rhyanon.");
55+
}
56+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"error": 0,
3+
"message": "Abfrage erfolgreich",
4+
"data": [
5+
{
6+
"id": "384098",
7+
"category_id": "281",
8+
"subject": "Overlord II - Diskussionsthread",
9+
"posts": "15",
10+
"hits": "749",
11+
"first_post_time": "1514199320",
12+
"first_post_userid": "351626",
13+
"first_post_guest_name": "Asuka..",
14+
"last_post_time": "1517246199",
15+
"last_post_userid": "506979",
16+
"last_post_guest_name": "5devilz",
17+
"category_name": "Airing-Anime"
18+
},
19+
{
20+
"id": "381421",
21+
"category_id": "56",
22+
"subject": "Overlord II – neues Visual, weitere Charaktere und Synchronsprecher enthüllt",
23+
"posts": "35",
24+
"hits": "32334",
25+
"first_post_time": "1489228544",
26+
"first_post_userid": "19328",
27+
"first_post_guest_name": "Moeface",
28+
"last_post_time": "1514078674",
29+
"last_post_userid": "470614",
30+
"last_post_guest_name": "..Rhyanon.",
31+
"category_name": "Anime- und Manga-News"
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)