Skip to content

Commit 0553891

Browse files
committed
Incorporate the latest API changes
1 parent 08dfd92 commit 0553891

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.proxer.library.entitiy.notifications.NewsArticle;
55
import me.proxer.library.entitiy.notifications.Notification;
66
import me.proxer.library.entitiy.notifications.NotificationInfo;
7+
import me.proxer.library.enums.NotificationFilter;
78
import retrofit2.http.*;
89

910
import java.util.List;
@@ -14,11 +15,13 @@
1415
interface InternalApi {
1516

1617
@GET("notifications/news")
17-
ProxerCall<List<NewsArticle>> news(@Query("p") Integer page, @Query("limit") Integer limit);
18+
ProxerCall<List<NewsArticle>> news(@Query("p") Integer page, @Query("limit") Integer limit,
19+
@Query("set_read") Boolean markAsRead);
1820

1921
@GET("notifications/notifications")
2022
ProxerCall<List<Notification>> notifications(@Query("p") Integer page, @Query("limit") Integer limit,
21-
@Query("set_read") Boolean markAsRead);
23+
@Query("set_read") Boolean markAsRead,
24+
@Query("filter") NotificationFilter filter);
2225

2326
@GET("notifications/count")
2427
ProxerCall<NotificationInfo> notificationInfo();

library/src/main/java/me/proxer/library/api/notifications/NewsEndpoint.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public final class NewsEndpoint implements PagingLimitEndpoint<List<NewsArticle>
3434
@Setter(onMethod = @__({@Override, @Nonnull}))
3535
private Integer limit;
3636

37+
/**
38+
* Sets if the news should be marked as read. Defaults to false.
39+
*/
40+
@Nullable
41+
@Setter(onMethod = @__({@Nonnull}))
42+
private Boolean markAsRead;
43+
3744
NewsEndpoint(@Nonnull final InternalApi internalApi) {
3845
this.internalApi = internalApi;
3946
}
@@ -44,6 +51,6 @@ public final class NewsEndpoint implements PagingLimitEndpoint<List<NewsArticle>
4451
@Override
4552
@Nonnull
4653
public ProxerCall<List<NewsArticle>> build() {
47-
return internalApi.news(page, limit);
54+
return internalApi.news(page, limit, markAsRead);
4855
}
4956
}

library/src/main/java/me/proxer/library/api/notifications/NotificationsEndpoint.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.proxer.library.api.PagingLimitEndpoint;
66
import me.proxer.library.api.ProxerCall;
77
import me.proxer.library.entitiy.notifications.Notification;
8+
import me.proxer.library.enums.NotificationFilter;
89

910
import javax.annotation.Nonnull;
1011
import javax.annotation.Nullable;
@@ -41,6 +42,13 @@ public final class NotificationsEndpoint implements PagingLimitEndpoint<List<Not
4142
@Setter(onMethod = @__({@Nonnull}))
4243
private Boolean markAsRead;
4344

45+
/**
46+
* {@inheritDoc}
47+
*/
48+
@Nullable
49+
@Setter(onMethod = @__({@Nonnull}))
50+
private NotificationFilter filter;
51+
4452
NotificationsEndpoint(@Nonnull final InternalApi internalApi) {
4553
this.internalApi = internalApi;
4654
}
@@ -51,6 +59,6 @@ public final class NotificationsEndpoint implements PagingLimitEndpoint<List<Not
5159
@Override
5260
@Nonnull
5361
public ProxerCall<List<Notification>> build() {
54-
return internalApi.notifications(page, limit, markAsRead);
62+
return internalApi.notifications(page, limit, markAsRead, filter);
5563
}
5664
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package me.proxer.library.enums;
2+
3+
import com.squareup.moshi.Json;
4+
5+
public enum NotificationFilter {
6+
@Json(name = "0") ALL,
7+
@Json(name = "1") UNREAD,
8+
@Json(name = "2") READ
9+
}

library/src/test/java/me/proxer/library/api/notifications/NewsEndpointTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public void testPath() throws ProxerException, IOException, InterruptedException
3636
api.notifications().news()
3737
.page(0)
3838
.limit(10)
39+
.markAsRead(false)
3940
.build()
4041
.execute();
4142

42-
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/notifications/news?p=0&limit=10");
43+
assertThat(server.takeRequest().getPath()).isEqualTo("/api/v1/notifications/news?p=0&limit=10&set_read=false");
4344
}
4445

4546
private NewsArticle buildTestArticle() {

library/src/test/java/me/proxer/library/api/notifications/NotificationEndpointTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.proxer.library.ProxerTest;
44
import me.proxer.library.api.ProxerException;
55
import me.proxer.library.entitiy.notifications.Notification;
6+
import me.proxer.library.enums.NotificationFilter;
67
import me.proxer.library.enums.NotificationType;
78
import okhttp3.HttpUrl;
89
import okhttp3.mockwebserver.MockResponse;
@@ -39,11 +40,12 @@ public void testPath() throws ProxerException, IOException, InterruptedException
3940
.page(0)
4041
.limit(10)
4142
.markAsRead(true)
43+
.filter(NotificationFilter.UNREAD)
4244
.build()
4345
.execute();
4446

4547
assertThat(server.takeRequest().getPath())
46-
.isEqualTo("/api/v1/notifications/notifications?p=0&limit=10&set_read=true");
48+
.isEqualTo("/api/v1/notifications/notifications?p=0&limit=10&set_read=true&filter=1");
4749
}
4850

4951
private Notification buildTestNotification() {

0 commit comments

Comments
 (0)