Skip to content

Commit 3cc1392

Browse files
committed
Implement new calendar endpoint and fix library versioning
1 parent 788ad7c commit 3cc1392

8 files changed

Lines changed: 298 additions & 0 deletions

File tree

library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ compileJava {
127127

128128
buildConfig {
129129
packageName = 'me.proxer.library'
130+
version = project.version
130131
}
131132

132133
javadoc {

library/src/main/java/me/proxer/library/api/ProxerApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.proxer.library.api.info.InfoApi;
1111
import me.proxer.library.api.list.ListApi;
1212
import me.proxer.library.api.manga.MangaApi;
13+
import me.proxer.library.api.media.MediaApi;
1314
import me.proxer.library.api.messenger.MessengerApi;
1415
import me.proxer.library.api.notifications.NotificationsApi;
1516
import me.proxer.library.api.ucp.UcpApi;
@@ -96,6 +97,11 @@ public final class ProxerApi {
9697
*/
9798
private final ForumApi forum;
9899

100+
/**
101+
* Returns the respective API.
102+
*/
103+
private final MediaApi media;
104+
99105
private ProxerApi(final Moshi moshi, final OkHttpClient client, final Retrofit retrofit) {
100106
this.moshi = moshi;
101107
this.client = client;
@@ -110,6 +116,7 @@ private ProxerApi(final Moshi moshi, final OkHttpClient client, final Retrofit r
110116
anime = new AnimeApi(retrofit);
111117
manga = new MangaApi(retrofit);
112118
forum = new ForumApi(retrofit);
119+
media = new MediaApi(retrofit);
113120
}
114121

115122
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package me.proxer.library.api.media;
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.media.CalendarEntry;
7+
8+
import java.util.List;
9+
10+
/**
11+
* @author Ruben Gees
12+
*/
13+
@Accessors(fluent = true)
14+
public final class CalendarEndpoint implements Endpoint<List<CalendarEntry>> {
15+
16+
private final InternalApi internalApi;
17+
18+
CalendarEndpoint(final InternalApi internalApi) {
19+
this.internalApi = internalApi;
20+
}
21+
22+
@Override
23+
public ProxerCall<List<CalendarEntry>> build() {
24+
return internalApi.calendar();
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package me.proxer.library.api.media;
2+
3+
import me.proxer.library.api.ProxerCall;
4+
import me.proxer.library.entity.media.CalendarEntry;
5+
import retrofit2.http.GET;
6+
7+
import javax.annotation.ParametersAreNullableByDefault;
8+
import java.util.List;
9+
10+
/**
11+
* @author Ruben Gees
12+
*/
13+
@ParametersAreNullableByDefault
14+
public interface InternalApi {
15+
16+
@GET("media/calendar")
17+
ProxerCall<List<CalendarEntry>> calendar();
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.proxer.library.api.media;
2+
3+
import retrofit2.Retrofit;
4+
5+
/**
6+
* Api for the Media class.
7+
*
8+
* @author Ruben Gees
9+
*/
10+
public final class MediaApi {
11+
12+
private final InternalApi internalApi;
13+
14+
/**
15+
* Only for internal use.
16+
*/
17+
public MediaApi(final Retrofit retrofit) {
18+
this.internalApi = retrofit.create(InternalApi.class);
19+
}
20+
21+
/**
22+
* Returns the respective endpoint.
23+
*/
24+
public CalendarEndpoint calendar() {
25+
return new CalendarEndpoint(internalApi);
26+
}
27+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package me.proxer.library.entity.media;
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.ProxerDateItem;
8+
import me.proxer.library.entity.ProxerIdItem;
9+
import me.proxer.library.enums.Genre;
10+
11+
import javax.annotation.Nullable;
12+
import java.util.Date;
13+
import java.util.Set;
14+
15+
/**
16+
* Entity holding the data of a single calendar entry.
17+
*
18+
* @author Ruben Gees
19+
*/
20+
@Value
21+
@EqualsAndHashCode(onParam = @__({@Nullable}))
22+
public class CalendarEntry implements ProxerIdItem, ProxerDateItem {
23+
24+
/**
25+
* {@inheritDoc}
26+
*/
27+
@Getter(onMethod = @__({@Override}))
28+
@Json(name = "id")
29+
private String id;
30+
31+
/**
32+
* Returns the id of the associated {@link me.proxer.library.entity.info.Entry}.
33+
*/
34+
@Json(name = "eid")
35+
private String entryId;
36+
37+
/**
38+
* Returns the name.
39+
*/
40+
@Json(name = "entryname")
41+
private String name;
42+
43+
/**
44+
* Returns the next episode to be aired.
45+
*/
46+
@Json(name = "episode")
47+
private int episode;
48+
49+
/**
50+
* Returns the title of the next episode to be aired. May be empty.
51+
*/
52+
@Json(name = "episodeTitle")
53+
private String episodeTitle;
54+
55+
/**
56+
* {@inheritDoc}
57+
*/
58+
@Getter(onMethod = @__({@Override}))
59+
@Json(name = "time")
60+
private Date date;
61+
62+
/**
63+
* Returns the timezone of the country, the episode is aired in.
64+
*/
65+
@Json(name = "timezone")
66+
private String timezone;
67+
68+
/**
69+
* Returns the id of the television channel, transmitting the episode. "0" if not set.
70+
*/
71+
@Json(name = "iid")
72+
private String industryId;
73+
74+
/**
75+
* Returns the name of the television channel, transmitting the episode. May be null.
76+
*/
77+
@Nullable
78+
@Json(name = "industryname")
79+
private String industryName;
80+
81+
/**
82+
* Returns the day of the week, the episode is aired.
83+
*/
84+
@Json(name = "weekday")
85+
private String weekDay;
86+
87+
/**
88+
* Returns the date (and time), the episode will be uploaded.
89+
* This is just an estimated value and can be imprecise.
90+
*/
91+
@Json(name = "uptime")
92+
private Date uploadDate;
93+
94+
/**
95+
* Returns the genres.
96+
*/
97+
@Json(name = "genre")
98+
private Set<Genre> genres;
99+
100+
/**
101+
* Returns the sum of all ratings.
102+
*/
103+
@Json(name = "rate_sum")
104+
private int ratingSum;
105+
106+
/**
107+
* Returns the amount of ratings.
108+
*/
109+
@Json(name = "rate_count")
110+
private int ratingAmount;
111+
112+
/**
113+
* Returns the average of all ratings.
114+
*/
115+
public final float getRating() {
116+
if (ratingAmount <= 0) {
117+
return 0;
118+
} else {
119+
return ratingSum / (float) ratingAmount;
120+
}
121+
}
122+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package me.proxer.library.api.media;
2+
3+
import me.proxer.library.ProxerTest;
4+
import me.proxer.library.api.ProxerException;
5+
import me.proxer.library.entity.media.CalendarEntry;
6+
import me.proxer.library.enums.Genre;
7+
import okhttp3.mockwebserver.MockResponse;
8+
import org.junit.Test;
9+
10+
import java.io.IOException;
11+
import java.util.Date;
12+
import java.util.EnumSet;
13+
import java.util.List;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
/**
18+
* @author Ruben Gees
19+
*/
20+
public class CalendarEndpointTest extends ProxerTest {
21+
22+
@Test
23+
public void testDefault() throws IOException, ProxerException {
24+
server.enqueue(new MockResponse().setBody(fromResource("calendar.json")));
25+
26+
final List<CalendarEntry> result = api.media()
27+
.calendar()
28+
.build()
29+
.execute();
30+
31+
assertThat(result).first().isEqualTo(buildFirstTestCalendarEntry());
32+
assertThat(result).last().isEqualTo(buildLastTestCalendarEntry());
33+
}
34+
35+
@Test
36+
public void testPath() throws ProxerException, IOException, InterruptedException {
37+
server.enqueue(new MockResponse().setBody(fromResource("calendar.json")));
38+
39+
api.media().calendar()
40+
.build()
41+
.execute();
42+
43+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/media/calendar");
44+
}
45+
46+
private CalendarEntry buildFirstTestCalendarEntry() {
47+
return new CalendarEntry("8843", "21638", "Time Bokan: Gyakushuu no San Akunin", 18,
48+
"", new Date(1518251400L * 1000), "+09:00", "0", null,
49+
"sat", new Date(1518266091L * 1000), EnumSet.of(Genre.ADVENTURE, Genre.COMEDY, Genre.MECHA),
50+
7, 2);
51+
}
52+
53+
private CalendarEntry buildLastTestCalendarEntry() {
54+
return new CalendarEntry("8830", "19092", "ClassicaLoid 2nd Season", 17,
55+
"", new Date(1518251700L * 1000), "+09:00", "308", "NHK",
56+
"sat", new Date(1518620676L * 1000), EnumSet.of(Genre.COMEDY, Genre.MUSIC),
57+
42, 7);
58+
}
59+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"error": 0,
3+
"message": "Abfrage erfolgreich",
4+
"data": [
5+
{
6+
"id": "8843",
7+
"eid": "21638",
8+
"episode": "18",
9+
"episodeTitle": "",
10+
"time": "1518251400",
11+
"timezone": "+09:00",
12+
"iid": "0",
13+
"weekday": "sat",
14+
"uptime": "1518266091",
15+
"entryname": "Time Bokan: Gyakushuu no San Akunin",
16+
"genre": "Abenteuer Comedy Mecha",
17+
"rate_sum": "7",
18+
"rate_count": "2",
19+
"industryname": null
20+
},
21+
{
22+
"id": "8830",
23+
"eid": "19092",
24+
"episode": "17",
25+
"episodeTitle": "",
26+
"time": "1518251700",
27+
"timezone": "+09:00",
28+
"iid": "308",
29+
"weekday": "sat",
30+
"uptime": "1518620676",
31+
"entryname": "ClassicaLoid 2nd Season",
32+
"genre": "Comedy Musik",
33+
"rate_sum": "42",
34+
"rate_count": "7",
35+
"industryname": "NHK"
36+
}
37+
]
38+
}

0 commit comments

Comments
 (0)