Skip to content

Commit 5a409f6

Browse files
committed
Method to getReports and add ReportStatus enum
1 parent 2e7fced commit 5a409f6

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.memerator.api.entity;
2+
3+
public enum ReportStatus {
4+
/**
5+
* An open report, unhandled.
6+
*/
7+
OPEN(0),
8+
9+
/**
10+
* Sets the max age to 2. Allows family friendly and teen.
11+
*/
12+
ASSIGNED(1),
13+
14+
/**
15+
* Sets the max age to 4. Allows all memes on Memerator.
16+
*/
17+
RESOLVED(2);
18+
19+
private final int status;
20+
21+
ReportStatus(int status) {
22+
this.status = status;
23+
}
24+
25+
public int getAsInt() {
26+
return status;
27+
}
28+
29+
public static ReportStatus fromInt(int status) {
30+
switch (status) {
31+
case 0:
32+
return OPEN;
33+
case 1:
34+
return ASSIGNED;
35+
case 2:
36+
return RESOLVED;
37+
}
38+
return null;
39+
}
40+
41+
public String toString() {
42+
switch(status) {
43+
case (0):
44+
return "Open";
45+
case (1):
46+
return "Resolved";
47+
case (2):
48+
return "Closed";
49+
default:
50+
return "Unknown";
51+
}
52+
}
53+
}

src/main/java/me/memerator/api/object/Profile.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ public void setBio(String bio) {
7676

7777
/**
7878
* @return your notifications
79-
* @throws Unauthorized if your api key cannot access the endpoint
80-
* @throws RateLimited if you hit the rate limit
81-
* @throws InvalidToken if your token is invalid
82-
* @throws NotFound if the notification endpoint somehow disappears
83-
* @throws InternalServerError if a server side error occurs
8479
*/
8580
public List<Notification> getNotifications() {
8681
JSONArray notificationsraw = new JSONArray(MemeratorAPI.api.get("/notifications"));
@@ -91,6 +86,27 @@ public List<Notification> getNotifications() {
9186
return notifications;
9287
}
9388

89+
/**
90+
* @return your reports
91+
*/
92+
public List<Report> getReports() {
93+
JSONArray reportResponse = new JSONArray(MemeratorAPI.api.get("/reports"));
94+
ArrayList<Report> reports = new ArrayList<>();
95+
for(int i = 0; i < reportResponse.length(); i++) {
96+
reports.add(new Report((JSONObject) reportResponse.get(i)));
97+
}
98+
return reports;
99+
}
100+
101+
/**
102+
* Gets a specific report by ID
103+
* @param id the report id
104+
* @return the report
105+
*/
106+
public Report getReport(int id) {
107+
return new Report(new JSONObject(MemeratorAPI.api.get("/report/" + id)));
108+
}
109+
94110
/**
95111
* @return your amount of notifications
96112
*/

src/main/java/me/memerator/api/object/Report.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.memerator.api.object;
22

3+
import me.memerator.api.entity.ReportStatus;
34
import org.json.JSONObject;
45

56
/**
@@ -25,11 +26,21 @@ public int getReportId() {
2526
* Status 1 means it's claimed, but not settled.
2627
* Status 2 means it's resolved.
2728
* @return the status.
29+
* @deprecated
30+
* @see Report#getStatus()
2831
*/
2932
public int getStatusCode() {
3033
return values.getInt("status");
3134
}
3235

36+
/**
37+
* The status of the report.
38+
* @return the status
39+
*/
40+
public ReportStatus getStatus() {
41+
return ReportStatus.fromInt(values.getInt("status"));
42+
}
43+
3344
/**
3445
* @return the ID of the meme being reported.
3546
*/
@@ -71,20 +82,26 @@ public String getStaffComment() {
7182

7283
/**
7384
* @return if the report is open
85+
* @deprecated
86+
* @see Report#getStatus()
7487
*/
7588
public boolean isOpen() {
7689
return getStatusCode() == 0;
7790
}
7891

7992
/**
8093
* @return if the report is assigned to someone
94+
* @deprecated
95+
* @see Report#getStatus()
8196
*/
8297
public boolean isAssigned() {
8398
return getStatusCode() == 0;
8499
}
85100

86101
/**
87102
* @return if the report is closed
103+
* @deprecated
104+
* @see Report#getStatus()
88105
*/
89106
public boolean isClosed() {
90107
return getStatusCode() == 2;

0 commit comments

Comments
 (0)