Skip to content

Commit 51bb951

Browse files
committed
Implement media user info api
1 parent 52231ac commit 51bb951

6 files changed

Lines changed: 140 additions & 0 deletions

File tree

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
@@ -94,4 +94,11 @@ public ModifyUserInfoEndpoint markAsFinished(final String entryId) {
9494
public RecommendationsEndpoint recommendations(final String entryId) {
9595
return new RecommendationsEndpoint(internalApi, entryId);
9696
}
97+
98+
/**
99+
* Returns the respective endpoint.
100+
*/
101+
public MediaUserInfoEndpoint userInfo(final String entryId) {
102+
return new MediaUserInfoEndpoint(internalApi, entryId);
103+
}
97104
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import me.proxer.library.entity.info.EntryCore;
77
import me.proxer.library.entity.info.EpisodeInfo;
88
import me.proxer.library.entity.info.Industry;
9+
import me.proxer.library.entity.info.MediaUserInfo;
910
import me.proxer.library.entity.info.Recommendation;
1011
import me.proxer.library.entity.info.Relation;
1112
import me.proxer.library.entity.info.TranslatorGroup;
@@ -59,4 +60,7 @@ ProxerCall<Void> modifyUserInfo(@Field("id") String id,
5960

6061
@GET("info/recommendations")
6162
ProxerCall<List<Recommendation>> recommendations(@Query("id") String id);
63+
64+
@GET("info/userinfo")
65+
ProxerCall<MediaUserInfo> userInfo(@Query("id") String id);
6266
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.MediaUserInfo;
7+
import me.proxer.library.entity.info.TranslatorGroup;
8+
9+
/**
10+
* Endpoint for retrieving all information of an {@link TranslatorGroup}.
11+
*
12+
* @author Ruben Gees
13+
*/
14+
@Accessors(fluent = true)
15+
public final class MediaUserInfoEndpoint implements Endpoint<MediaUserInfo> {
16+
17+
private final InternalApi internalApi;
18+
19+
private final String id;
20+
21+
MediaUserInfoEndpoint(final InternalApi internalApi, final String id) {
22+
this.internalApi = internalApi;
23+
this.id = id;
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
@Override
30+
public ProxerCall<MediaUserInfo> build() {
31+
return internalApi.userInfo(id);
32+
}
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.proxer.library.entity.info;
2+
3+
import com.squareup.moshi.Json;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.Value;
6+
7+
import javax.annotation.Nullable;
8+
9+
/**
10+
* Entity which holds info of the connection between an {@link Entry} and an {@link me.proxer.library.entity.user.User}.
11+
*
12+
* @author Ruben Gees
13+
*/
14+
@Value
15+
@EqualsAndHashCode(onParam = @__({@Nullable}))
16+
public class MediaUserInfo {
17+
18+
/**
19+
* Returns true, if this media has been noted by the user.
20+
*/
21+
@Json(name = "noted")
22+
private boolean noted;
23+
24+
/**
25+
* Returns true, if this media has been finished by the user.
26+
*/
27+
@Json(name = "finished")
28+
private boolean finished;
29+
30+
/**
31+
* Returns true, if this media has been canceled by the user.
32+
*/
33+
@Json(name = "canceled")
34+
private boolean canceled;
35+
36+
/**
37+
* Returns true, if this media is on the top ten list of the user.
38+
*/
39+
@Json(name = "topten")
40+
private boolean topTen;
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.MediaUserInfo;
6+
import okhttp3.mockwebserver.MockResponse;
7+
import org.junit.Test;
8+
9+
import java.io.IOException;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
/**
14+
* @author Ruben Gees
15+
*/
16+
public class MediaUserInfoEndpointTest extends ProxerTest {
17+
18+
@Test
19+
public void testDefault() throws IOException, ProxerException {
20+
server.enqueue(new MockResponse().setBody(fromResource("media_user_info.json")));
21+
22+
final MediaUserInfo result = api.info()
23+
.userInfo("123")
24+
.build()
25+
.execute();
26+
27+
assertThat(result).isEqualTo(buildTestUserInfo());
28+
}
29+
30+
@Test
31+
public void testPath() throws ProxerException, IOException, InterruptedException {
32+
server.enqueue(new MockResponse().setBody(fromResource("media_user_info.json")));
33+
34+
api.info().userInfo("321")
35+
.build()
36+
.execute();
37+
38+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/info/userinfo?id=321");
39+
}
40+
41+
private MediaUserInfo buildTestUserInfo() {
42+
return new MediaUserInfo(false, true, false, true);
43+
}
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"error": 0,
3+
"message": "Abfrage erfolgreich",
4+
"data": {
5+
"marked": true,
6+
"noted": false,
7+
"finished": true,
8+
"canceled": false,
9+
"topten": true
10+
}
11+
}

0 commit comments

Comments
 (0)