Skip to content

Commit 2201512

Browse files
author
Javen
committed
Add feature - baseResult to return rate limiting params.
1 parent 18e1be4 commit 2201512

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cn.jpush.api.common;
2+
3+
import cn.jpush.api.common.ResponseResult.ErrorObject;
4+
5+
import com.google.gson.Gson;
6+
import com.google.gson.GsonBuilder;
7+
8+
public class BaseResult {
9+
10+
protected static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
11+
12+
public ResponseResult responseResult;
13+
14+
public ErrorObject getErrorObject() {
15+
if (null != responseResult) {
16+
return responseResult.error;
17+
}
18+
return null;
19+
}
20+
21+
public int getRateLimitQuota() {
22+
if (null != responseResult) {
23+
return responseResult.rateLimitQuota;
24+
}
25+
return 0;
26+
}
27+
28+
public int getRateLimitRemaining() {
29+
if (null != responseResult) {
30+
return responseResult.rateLimitRemaining;
31+
}
32+
return 0;
33+
}
34+
35+
public int getRateLimitReset() {
36+
if (null != responseResult) {
37+
return responseResult.rateLimitReset;
38+
}
39+
return 0;
40+
}
41+
42+
}

src/cn/jpush/api/common/ResponseResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ResponseResult {
1212
public int responseCode;
1313
public String responseContent;
1414

15-
public Error error; // error for non-200 response, used by new API
15+
public ErrorObject error; // error for non-200 response, used by new API
1616

1717
public int rateLimitQuota;
1818
public int rateLimitRemaining;
@@ -34,15 +34,15 @@ public void setRateLimit(String quota, String remaining, String reset) {
3434
}
3535

3636
public void setErrorObject() {
37-
error = _gson.fromJson(responseContent, Error.class);
37+
error = _gson.fromJson(responseContent, ErrorObject.class);
3838
}
3939

4040
@Override
4141
public String toString() {
4242
return _gson.toJson(this);
4343
}
4444

45-
public class Error {
45+
public class ErrorObject {
4646
public int code;
4747
public String message;
4848
}

src/cn/jpush/api/push/MessageResult.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package cn.jpush.api.push;
22

3-
import cn.jpush.api.common.ResponseResult;
3+
import cn.jpush.api.common.BaseResult;
44

5-
import com.google.gson.Gson;
6-
import com.google.gson.GsonBuilder;
75
import com.google.gson.annotations.Expose;
86

9-
public class MessageResult {
10-
protected static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
11-
12-
public ResponseResult responseResult;
13-
7+
public class MessageResult extends BaseResult {
148
@Expose public Long msg_id;
159
@Expose public int sendno;
1610
@Expose public int errcode = -1;

src/cn/jpush/api/report/ReceivedsResult.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import cn.jpush.api.common.ResponseResult;
6+
import cn.jpush.api.common.BaseResult;
77

8-
import com.google.gson.Gson;
9-
import com.google.gson.GsonBuilder;
108
import com.google.gson.annotations.Expose;
119

12-
public class ReceivedsResult {
13-
protected static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
14-
15-
public ResponseResult responseResult;
10+
public class ReceivedsResult extends BaseResult {
1611
@Expose public List<Received> receivedList = new ArrayList<Received>();
1712

1813
public static class Received {

0 commit comments

Comments
 (0)