Skip to content

Commit 95a6417

Browse files
committed
Implement error log api and fix minor issues
1 parent e0b3e2f commit 95a6417

7 files changed

Lines changed: 151 additions & 6 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.experimental.Accessors;
77
import me.proxer.library.BuildConfig;
88
import me.proxer.library.api.anime.AnimeApi;
9+
import me.proxer.library.api.apps.AppsApi;
910
import me.proxer.library.api.forum.ForumApi;
1011
import me.proxer.library.api.info.InfoApi;
1112
import me.proxer.library.api.list.ListApi;
@@ -102,6 +103,11 @@ public final class ProxerApi {
102103
*/
103104
private final MediaApi media;
104105

106+
/**
107+
* Returns the respective API.
108+
*/
109+
private final AppsApi apps;
110+
105111
private ProxerApi(final Moshi moshi, final OkHttpClient client, final Retrofit retrofit) {
106112
this.moshi = moshi;
107113
this.client = client;
@@ -117,6 +123,7 @@ private ProxerApi(final Moshi moshi, final OkHttpClient client, final Retrofit r
117123
manga = new MangaApi(retrofit);
118124
forum = new ForumApi(retrofit);
119125
media = new MediaApi(retrofit);
126+
apps = new AppsApi(retrofit);
120127
}
121128

122129
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.proxer.library.api.apps;
2+
3+
import retrofit2.Retrofit;
4+
5+
/**
6+
* Api for the Media class.
7+
*
8+
* @author Ruben Gees
9+
*/
10+
public final class AppsApi {
11+
12+
private final InternalApi internalApi;
13+
14+
/**
15+
* Only for internal use.
16+
*/
17+
public AppsApi(final Retrofit retrofit) {
18+
this.internalApi = retrofit.create(InternalApi.class);
19+
}
20+
21+
/**
22+
* Returns the respective endpoint.
23+
*/
24+
public ErrorLogEndpoint errorLog(final String id, final String message) {
25+
return new ErrorLogEndpoint(internalApi, id, message);
26+
}
27+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package me.proxer.library.api.apps;
2+
3+
import lombok.Setter;
4+
import lombok.experimental.Accessors;
5+
import me.proxer.library.api.Endpoint;
6+
import me.proxer.library.api.ProxerCall;
7+
8+
import javax.annotation.Nullable;
9+
10+
/**
11+
* Endpoint for sending error logs.
12+
*
13+
* @author Ruben Gees
14+
*/
15+
@Accessors(fluent = true)
16+
public final class ErrorLogEndpoint implements Endpoint<Void> {
17+
18+
private final InternalApi internalApi;
19+
20+
private final String id;
21+
private final String message;
22+
23+
/**
24+
* Sets if the error log should be sent anonymously. If not set, this behaves as true.
25+
*/
26+
@Nullable
27+
@Setter
28+
private Boolean anonym;
29+
30+
ErrorLogEndpoint(final InternalApi internalApi, final String id, final String message) {
31+
this.internalApi = internalApi;
32+
this.id = id;
33+
this.message = message;
34+
}
35+
36+
@Override
37+
public ProxerCall<Void> build() {
38+
return internalApi.errorLog(id, message, anonym);
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.proxer.library.api.apps;
2+
3+
import me.proxer.library.api.ProxerCall;
4+
import retrofit2.http.Field;
5+
import retrofit2.http.FormUrlEncoded;
6+
import retrofit2.http.POST;
7+
8+
import javax.annotation.ParametersAreNullableByDefault;
9+
10+
/**
11+
* @author Ruben Gees
12+
*/
13+
@ParametersAreNullableByDefault
14+
public interface InternalApi {
15+
16+
@FormUrlEncoded
17+
@POST("apps/errorlog")
18+
ProxerCall<Void> errorLog(@Field("id") String id,
19+
@Field("message") String message,
20+
@Field("anonym") Boolean anonym);
21+
}

library/src/main/java/me/proxer/library/api/media/CalendarEndpoint.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.util.List;
99

1010
/**
11+
* Endpoint for retrieving the anime calendar/schedule.
12+
*
1113
* @author Ruben Gees
1214
*/
1315
@Accessors(fluent = true)

library/src/main/java/me/proxer/library/api/ucp/BookmarksEndpoint.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ public final class BookmarksEndpoint implements PagingLimitEndpoint<List<Bookmar
2424
* {@inheritDoc}
2525
*/
2626
@Nullable
27-
@Setter
28-
private Category category;
27+
@Setter(onMethod = @__({@Override}))
28+
private Integer page;
2929

3030
/**
3131
* {@inheritDoc}
3232
*/
3333
@Nullable
3434
@Setter(onMethod = @__({@Override}))
35-
private Integer page;
35+
private Integer limit;
3636

3737
/**
38-
* {@inheritDoc}
38+
* Sets the type of category to return.
3939
*/
4040
@Nullable
41-
@Setter(onMethod = @__({@Override}))
42-
private Integer limit;
41+
@Setter
42+
private Category category;
4343

4444
/**
4545
* Sets if only available or only not available bookmarks should be returned.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package me.proxer.library.api.apps;
2+
3+
import me.proxer.library.ProxerTest;
4+
import me.proxer.library.api.ProxerException;
5+
import okhttp3.mockwebserver.MockResponse;
6+
import org.junit.Test;
7+
8+
import java.io.IOException;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
public class ErrorLogEndpointTest extends ProxerTest {
13+
14+
@Test
15+
public void testDefault() throws ProxerException, IOException {
16+
server.enqueue(new MockResponse().setBody(fromResource("empty.json")));
17+
18+
final Void result = api.apps()
19+
.errorLog("3", "test message")
20+
.build()
21+
.execute();
22+
23+
assertThat(result).isNull();
24+
}
25+
26+
@Test
27+
public void testPath() throws ProxerException, IOException, InterruptedException {
28+
server.enqueue(new MockResponse().setBody(fromResource("empty.json")));
29+
30+
api.apps().errorLog("3", "test message")
31+
.build()
32+
.execute();
33+
34+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/apps/errorlog");
35+
}
36+
37+
@Test
38+
public void testParameters() throws IOException, ProxerException, InterruptedException {
39+
server.enqueue(new MockResponse().setBody(fromResource("empty.json")));
40+
41+
api.apps().errorLog("3", "test message")
42+
.anonym(false)
43+
.build()
44+
.execute();
45+
46+
assertThat(server.takeRequest().getBody().readUtf8()).isEqualTo("id=3&message=test%20message&anonym=false");
47+
}
48+
}

0 commit comments

Comments
 (0)