Skip to content

Commit 93af30a

Browse files
author
Javen
committed
Bug fix: handle new API response.
1 parent fa8e47c commit 93af30a

File tree

5 files changed

+39
-68
lines changed

5 files changed

+39
-68
lines changed

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cn.jpush.api.common;
22

3+
import cn.jpush.api.common.ResponseResult.ErrorObject;
4+
35
import com.google.gson.Gson;
46
import com.google.gson.GsonBuilder;
57

@@ -13,12 +15,34 @@ public abstract class BaseResult {
1315

1416
public ResponseResult responseResult;
1517

16-
public abstract boolean isResultOK();
18+
protected ErrorObject getErrorObject() {
19+
if (null != responseResult) {
20+
return responseResult.error;
21+
}
22+
return null;
23+
}
1724

18-
public abstract int getErrorCode();
25+
public int getErrorCode() {
26+
ErrorObject eo = getErrorObject();
27+
if (null != eo) {
28+
return eo.code;
29+
}
30+
return ERROR_CODE_OK;
31+
}
1932

20-
public abstract String getErrorMessage();
33+
public String getErrorMessage() {
34+
ErrorObject eo = getErrorObject();
35+
if (null != eo) {
36+
return eo.message;
37+
}
38+
return ERROR_MESSAGE_NONE;
39+
}
2140

41+
public boolean isResultOK() {
42+
if (responseResult.responseCode == RESPONSE_OK) return true;
43+
return false;
44+
}
45+
2246
public int getRateLimitQuota() {
2347
if (null != responseResult) {
2448
return responseResult.rateLimitQuota;
@@ -40,4 +64,10 @@ public int getRateLimitReset() {
4064
return 0;
4165
}
4266

67+
@Override
68+
public String toString() {
69+
return _gson.toJson(this);
70+
}
71+
72+
4373
}

src/cn/jpush/api/examples/JPushClientExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private static void testSendNotification() {
3232
LOG.info("Paylaod JSON - " + payload.toString());
3333

3434
PushResult result = jpushClient.sendPush(payload);
35+
LOG.debug(result.responseResult.responseContent);
3536
LOG.debug(result.toString());
3637
}
3738

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

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,11 @@
55
import com.google.gson.annotations.Expose;
66

77
public class PushResult extends BaseResult {
8-
@Expose public Long msg_id;
9-
@Expose public int sendno;
10-
@Expose public int errcode = ERROR_CODE_NONE;
11-
@Expose public String errmsg;
12-
13-
public PushResult() {
14-
}
15-
16-
public long getMessageId() {
17-
return this.msg_id;
18-
}
19-
20-
public int getSendNo() {
21-
return this.sendno;
22-
}
23-
24-
public int getErrorCode() {
25-
return this.errcode;
26-
}
27-
28-
public String getErrorMessage() {
29-
return this.errmsg;
30-
}
31-
32-
public boolean isResultOK() {
33-
if (responseResult.responseCode == RESPONSE_OK && this.errcode == ERROR_CODE_OK) return true;
34-
return false;
8+
9+
public static class Push {
10+
@Expose public long msg_id;
11+
@Expose public int sendno;
3512
}
3613

37-
@Override
38-
public String toString() {
39-
return _gson.toJson(this);
40-
}
41-
4214
}
4315

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55

66
import cn.jpush.api.common.BaseResult;
7-
import cn.jpush.api.common.ResponseResult.ErrorObject;
87

98
import com.google.gson.annotations.Expose;
109

@@ -21,36 +20,5 @@ public List<Received> getReceivedList() {
2120
return this.receivedList;
2221
}
2322

24-
protected ErrorObject getErrorObject() {
25-
if (null != responseResult) {
26-
return responseResult.error;
27-
}
28-
return null;
29-
}
30-
31-
public int getErrorCode() {
32-
ErrorObject eo = getErrorObject();
33-
if (null != eo) {
34-
return eo.code;
35-
}
36-
return ERROR_CODE_OK;
37-
}
38-
39-
public String getErrorMessage() {
40-
ErrorObject eo = getErrorObject();
41-
if (null != eo) {
42-
return eo.message;
43-
}
44-
return ERROR_MESSAGE_NONE;
45-
}
4623

47-
public boolean isResultOK() {
48-
if (responseResult.responseCode == RESPONSE_OK) return true;
49-
return false;
50-
}
51-
52-
@Override
53-
public String toString() {
54-
return _gson.toJson(this);
55-
}
5624
}

test/cn/jpush/api/PushSpecialCharacterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public int sendMessage(String content) {
3434
.setMessage(message)
3535
.build();
3636
PushResult result = jpush.sendPush(payload);
37-
return result.errcode;
37+
return result.getErrorCode();
3838
}
3939

4040
@Test

0 commit comments

Comments
 (0)