-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84b6b29
commit 8003193
Showing
14 changed files
with
244 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class ScheduleTemplatePushSendParam extends TemplatePushSendParam { | ||
|
||
@JsonProperty("schedule_name") | ||
private String scheduleName; | ||
|
||
@JsonProperty("trigger") | ||
private SchedulePushSendParam.Trigger trigger; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import cn.jiguang.sdk.bean.push.other.TemplateResult; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class ScheduleTemplatePushSendResult { | ||
|
||
@JsonProperty("code") | ||
private Integer code; | ||
|
||
@JsonProperty("message") | ||
private String message; | ||
|
||
@JsonProperty("data") | ||
private Data data; | ||
|
||
@lombok.Data | ||
public static class Data { | ||
|
||
@JsonProperty("schedule_list") | ||
private List<TemplateResult> results; | ||
|
||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import cn.jiguang.sdk.bean.push.other.TemplateParam; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class TemplatePushSendParam { | ||
|
||
@JsonProperty("id") | ||
private String id; | ||
|
||
@JsonProperty("params") | ||
private List<TemplateParam> params; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import cn.jiguang.sdk.bean.push.other.TemplateResult; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class TemplatePushSendResult { | ||
|
||
@JsonProperty("code") | ||
private Integer code; | ||
|
||
@JsonProperty("message") | ||
private String message; | ||
|
||
@JsonProperty("data") | ||
private Data data; | ||
|
||
@lombok.Data | ||
public static class Data { | ||
|
||
@JsonProperty("push_list") | ||
private List<TemplateResult> results; | ||
|
||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.jiguang.sdk.bean.push.other; | ||
|
||
import cn.jiguang.sdk.bean.push.audience.Audience; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
public class TemplateParam { | ||
|
||
/** | ||
* 两种格式 | ||
* 字符串:"all" | ||
* {@link Audience}对象: {"tag":[],"tag_and":[],"tag_not":[],"alias":[],"registration_id":[],"segment":[],"abtest":[],"live_activity_id":"","file":{"file_id":""}} | ||
*/ | ||
@JsonProperty("audience") | ||
private Object audience; | ||
|
||
@JsonProperty("keys") | ||
private Map<String, String> keys; | ||
|
||
@JsonProperty("trace_id") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String traceId; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cn.jiguang.sdk.bean.push.other; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class TemplateResult { | ||
|
||
@JsonProperty("code") | ||
private Integer code; | ||
|
||
@JsonProperty("message") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String message; | ||
|
||
@JsonProperty("message_id") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String messageId; | ||
|
||
@JsonProperty("schedule_id") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String scheduleId; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
jiguang-sdk/src/main/java/cn/jiguang/sdk/codec/ApiErrorDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
package cn.jiguang.sdk.codec; | ||
|
||
import cn.jiguang.sdk.bean.push.other.TemplateResult; | ||
import cn.jiguang.sdk.exception.ApiErrorException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import feign.Response; | ||
import feign.Util; | ||
import feign.codec.ErrorDecoder; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Slf4j | ||
public class ApiErrorDecoder implements ErrorDecoder { | ||
|
||
@Override | ||
public Exception decode(String methodKey, Response response) { | ||
int status = response.status(); | ||
Response.Body body = response.body(); | ||
if (methodKey.contains("templateSend") || methodKey.contains("scheduleTemplateSend")) { | ||
try { | ||
String bodyContent = Util.toString(body.asReader(StandardCharsets.UTF_8)); | ||
TemplateResult templateResult = new ObjectMapper().readValue(bodyContent, TemplateResult.class); | ||
return buildApiErrorException(status, templateResult.getCode(), templateResult.getMessage()); | ||
} catch (Exception exception) { | ||
log.error("unknown error", exception); | ||
return buildApiErrorException(status, 500, "unknown error"); | ||
} | ||
} | ||
try { | ||
Response.Body body = response.body(); | ||
String bodyContent = Util.toString(body.asReader(StandardCharsets.UTF_8)); | ||
ApiErrorException.ApiError apiError = new ObjectMapper().readValue(bodyContent, ApiErrorException.ApiError.class); | ||
return new ApiErrorException(status, apiError); | ||
} catch (Exception exception) { | ||
return new ApiErrorException(status, null); | ||
log.error("unknown error", exception); | ||
return buildApiErrorException(status, 500, "unknown error"); | ||
} | ||
} | ||
|
||
private ApiErrorException buildApiErrorException(int status, int code, String message) { | ||
ApiErrorException.ApiError.Error error = new ApiErrorException.ApiError.Error(); | ||
error.setCode(code); | ||
error.setMessage(message); | ||
ApiErrorException.ApiError apiError = new ApiErrorException.ApiError(); | ||
apiError.setError(error); | ||
return new ApiErrorException(status, apiError); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters