Skip to content

Commit 7afc854

Browse files
author
Javen
committed
Merge branch 'v30' into dev
2 parents cf49ddb + 838e6bd commit 7afc854

File tree

11 files changed

+80
-53
lines changed

11 files changed

+80
-53
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public enum DeviceType {
44

55
Android("android"),
66
IOS("ios"),
7-
MPNs("mpns");
7+
WinPhone("winphone");
88

99
private final String value;
1010

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public PushClient(String masterSecret, String appKey, boolean apnsProduction, lo
5555

5656
public PushResult sendPush(PushPayload pushPayload) {
5757
if (_overallSettingEnabled) {
58-
pushPayload.resetOptionalTimeToLive(_timeToLive);
59-
pushPayload.resetOptionalApnsProduction(_apnsProduction);
58+
pushPayload.resetOptionsTimeToLive(_timeToLive);
59+
pushPayload.resetOptionsApnsProduction(_apnsProduction);
6060
}
6161

6262
ResponseResult response = sendPost(PUSH_URL, pushPayload.toJSON().getAsString(), _authCode);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.google.gson.JsonObject;
66
import com.google.gson.JsonPrimitive;
77

8-
public class Optional implements PushModel {
8+
public class Options implements PushModel {
99
public static final String OPTIONAL = "optional";
1010

1111
public static final String SENDNO = "sendno";
@@ -18,7 +18,7 @@ public class Optional implements PushModel {
1818
private long timeToLive;
1919
private boolean apnsProduction;
2020

21-
private Optional(int sendno, int overrideMsgId, long timeToLive, boolean apnsProduction) {
21+
private Options(int sendno, int overrideMsgId, long timeToLive, boolean apnsProduction) {
2222
this.sendno = sendno;
2323
this.overrideMsgId = overrideMsgId;
2424
this.timeToLive = timeToLive;
@@ -81,11 +81,11 @@ public Builder setApnsProduction(boolean apnsProduction) {
8181
return this;
8282
}
8383

84-
public Optional build() {
84+
public Options build() {
8585
Preconditions.checkArgument(sendno >= 0, "sendno should be greater than 0.");
8686
Preconditions.checkArgument(overrideMsgId >= 0, "override_msg_id should be greater than 0.");
8787
Preconditions.checkArgument(timeToLive >= 0, "time_to_live should be greater than 0.");
88-
return new Optional(sendno, overrideMsgId, timeToLive, apnsProduction);
88+
return new Options(sendno, overrideMsgId, timeToLive, apnsProduction);
8989
}
9090
}
9191

src/cn/jpush/api/push/model/Platform.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public static Platform all() {
2929
return newBuilder().setAll(true).build();
3030
}
3131

32+
public static Platform android() {
33+
return newBuilder().addDeviceType(DeviceType.Android).build();
34+
}
35+
36+
public static Platform ios() {
37+
return newBuilder().addDeviceType(DeviceType.IOS).build();
38+
}
39+
40+
public static Platform winphone() {
41+
return newBuilder().addDeviceType(DeviceType.WinPhone).build();
42+
}
43+
3244
public boolean isAll() {
3345
return all;
3446
}

src/cn/jpush/api/push/model/PushPayload.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class PushPayload implements PushModel {
1212
private final Audience audience;
1313
private final Notification notification;
1414
private final Message message;
15-
private Optional optional;
15+
private Options options;
1616

1717
private PushPayload(Platform platform, Audience audience,
18-
Notification notification, Message message, Optional optional) {
18+
Notification notification, Message message, Options options) {
1919
this.platform = platform;
2020
this.audience = audience;
2121
this.notification = notification;
2222
this.message = message;
23-
this.optional = optional;
23+
this.options = options;
2424
}
2525

2626
public static Builder newBuilder() {
@@ -39,19 +39,19 @@ public static PushPayload simpleMessageAll(String content) {
3939
.setMessage(Message.content(content)).build();
4040
}
4141

42-
public void resetOptionalApnsProduction(boolean apnsProduction) {
43-
if (null == optional) {
44-
optional = Optional.newBuilder().setApnsProduction(apnsProduction).build();
42+
public void resetOptionsApnsProduction(boolean apnsProduction) {
43+
if (null == options) {
44+
options = Options.newBuilder().setApnsProduction(apnsProduction).build();
4545
} else {
46-
optional.setApnsProduction(apnsProduction);
46+
options.setApnsProduction(apnsProduction);
4747
}
4848
}
4949

50-
public void resetOptionalTimeToLive(long timeToLive) {
51-
if (null == optional) {
52-
optional = Optional.newBuilder().setTimeToLive(timeToLive).build();
50+
public void resetOptionsTimeToLive(long timeToLive) {
51+
if (null == options) {
52+
options = Options.newBuilder().setTimeToLive(timeToLive).build();
5353
} else {
54-
optional.setTimeToLive(timeToLive);
54+
options.setTimeToLive(timeToLive);
5555
}
5656
}
5757

@@ -67,17 +67,17 @@ public JsonElement toJSON() {
6767
json.add(Message.MESSAGE, message.toJSON());
6868
}
6969
if (null != message) {
70-
json.add(Optional.OPTIONAL, optional.toJSON());
70+
json.add(Options.OPTIONAL, options.toJSON());
7171
}
7272
return json;
7373
}
7474

7575
public static class Builder {
76-
private Platform platform = Platform.all();
76+
private Platform platform = null;
7777
private Audience audience = null;
7878
private Notification notification = null;
7979
private Message message = null;
80-
private Optional optional = null;
80+
private Options options = null;
8181

8282
public Builder setPlatform(Platform platform) {
8383
this.platform = platform;
@@ -99,15 +99,15 @@ public Builder setMessage(Message message) {
9999
return this;
100100
}
101101

102-
public Builder setOptional(Optional optional) {
103-
this.optional = optional;
102+
public Builder setOptions(Options options) {
103+
this.options = options;
104104
return this;
105105
}
106106

107107
public PushPayload build() {
108-
Preconditions.checkArgument(null != audience, "Audience should be set.");
108+
Preconditions.checkArgument(! (null == audience || null == platform), "Audience should be set.");
109109
Preconditions.checkArgument(! (null == notification && null == message), "notification or message should be set at least one.");
110-
return new PushPayload(platform, audience, notification, message, optional);
110+
return new PushPayload(platform, audience, notification, message, options);
111111
}
112112
}
113113
}

src/cn/jpush/api/push/model/audience/Audience.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ public static Audience tag(Collection<String> tagValues) {
5050
return newBuilder().addAudienceTarget(target).build();
5151
}
5252

53+
public static Audience tagAnd(String... tagValue) {
54+
AudienceTarget target = AudienceTarget.newBuilder()
55+
.setAudienceType(AudienceType.TAG_AND)
56+
.addAudienceTargetValues(tagValue).build();
57+
return newBuilder().addAudienceTarget(target).build();
58+
}
59+
60+
public static Audience tagAnd(Collection<String> tagValues) {
61+
AudienceTarget target = AudienceTarget.newBuilder()
62+
.setAudienceType(AudienceType.TAG_AND)
63+
.addAudienceTargetValues(tagValues).build();
64+
return newBuilder().addAudienceTarget(target).build();
65+
}
66+
5367
public static Audience alias(String... alias) {
5468
AudienceTarget target = AudienceTarget.newBuilder()
5569
.setAudienceType(AudienceType.ALIAS)

src/cn/jpush/api/push/model/audience/AudienceType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public enum AudienceType {
44
TAG("tag"),
5-
TAGAND("tag_and"),
5+
TAG_AND("tag_and"),
66
ALIAS("alias"),
77
SEGMENT("segment"),
88
REGISTRATION_ID("registration_id");

src/cn/jpush/api/push/model/notification/MpnsNotification.java renamed to src/cn/jpush/api/push/model/notification/WinPhoneNotification.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.google.gson.JsonObject;
99
import com.google.gson.JsonPrimitive;
1010

11-
public class MpnsNotification extends PlatformNotification {
12-
public static final String NOTIFICATION_MPNS = "mpns";
11+
public class WinPhoneNotification extends PlatformNotification {
12+
public static final String NOTIFICATION_WINPHONE = "winphone";
1313

1414
public static final String TITLE = "title";
1515
public static final String EXTRAS = "extras";
@@ -19,7 +19,7 @@ public class MpnsNotification extends PlatformNotification {
1919
private final String openPage;
2020
private final ImmutableMap<String, String> extras;
2121

22-
private MpnsNotification(String alert, String title, String openPage,
22+
private WinPhoneNotification(String alert, String title, String openPage,
2323
ImmutableMap<String, String> extras) {
2424
super(alert);
2525
this.title = title;
@@ -31,14 +31,14 @@ public static Builder newBuilder() {
3131
return new Builder();
3232
}
3333

34-
public static MpnsNotification alert(String alert) {
34+
public static WinPhoneNotification alert(String alert) {
3535
return newBuilder().setAlert(alert).build();
3636
}
3737

3838

3939
@Override
4040
public String getPlatform() {
41-
return NOTIFICATION_MPNS;
41+
return NOTIFICATION_WINPHONE;
4242
}
4343

4444
@Override
@@ -106,8 +106,8 @@ public Builder addExtra(String key, String value) {
106106
return this;
107107
}
108108

109-
public MpnsNotification build() {
110-
return new MpnsNotification(alert, title, openPage,
109+
public WinPhoneNotification build() {
110+
return new WinPhoneNotification(alert, title, openPage,
111111
(null == extrasBuilder) ? null : extrasBuilder.build());
112112
}
113113
}

test/cn/jpush/api/push/model/OptionalTests.java renamed to test/cn/jpush/api/push/model/OptionsTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
import org.junit.Assert;
55
import org.junit.Test;
66

7-
import cn.jpush.api.push.model.Optional;
7+
import cn.jpush.api.push.model.Options;
88

99
import com.google.gson.JsonObject;
1010
import com.google.gson.JsonPrimitive;
1111

12-
public class OptionalTests {
12+
public class OptionsTests {
1313

1414
@Test(expected = IllegalArgumentException.class)
1515
public void testIllegalSendno() {
16-
Optional.newBuilder().setSendno(-1).build();
16+
Options.newBuilder().setSendno(-1).build();
1717
}
1818

1919
@Test(expected = IllegalArgumentException.class)
2020
public void testIllegalOverrideMsgId() {
21-
Optional.newBuilder().setOverrideMsgId(-1).build();
21+
Options.newBuilder().setOverrideMsgId(-1).build();
2222
}
2323

2424
@Test(expected = IllegalArgumentException.class)
2525
public void testIllegalTimeToLive() {
26-
Optional.newBuilder().setTimeToLive(-1).build();
26+
Options.newBuilder().setTimeToLive(-1).build();
2727
}
2828

2929
@Test
3030
public void testSendno() {
3131
JsonObject json = new JsonObject();
3232
json.add("sendno", new JsonPrimitive(111));
33-
Optional optional = Optional.newBuilder().setSendno(111).build();
33+
Options optional = Options.newBuilder().setSendno(111).build();
3434
Assert.assertEquals("", json, optional.toJSON());
3535
}
3636

3737
@Test
3838
public void testApnsProduction() {
3939
JsonObject json = new JsonObject();
4040
json.add("apns_production", new JsonPrimitive(false));
41-
Optional optional = Optional.newBuilder().setApnsProduction(false).build();
41+
Options optional = Options.newBuilder().setApnsProduction(false).build();
4242
Assert.assertEquals("", json, optional.toJSON());
4343
}
4444

test/cn/jpush/api/push/model/PushPayloadTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55

6-
import cn.jpush.api.push.model.Platform;
7-
import cn.jpush.api.push.model.PushPayload;
86
import cn.jpush.api.push.model.audience.Audience;
97
import cn.jpush.api.push.model.notification.Notification;
108

@@ -39,17 +37,20 @@ public void testIllegal_NoAudience() {
3937
PushPayload.newBuilder().setPlatform(platform).setNotification(notifcation).build();
4038
}
4139

42-
@Test
40+
@Test(expected = IllegalArgumentException.class)
4341
public void testIllegal_NoPlatform() {
4442
Audience audience = Audience.all();
4543
Notification notifcation = Notification.alert("alert");
46-
PushPayload push = PushPayload.newBuilder().setAudience(audience).setNotification(notifcation).build();
44+
PushPayload.newBuilder().setAudience(audience).setNotification(notifcation).build();
45+
}
46+
47+
public void testNormal() {
48+
Platform platform = Platform.all();
49+
Audience audience = Audience.all();
50+
Notification notifcation = Notification.alert("alert");
51+
PushPayload payload = PushPayload.newBuilder().setAudience(audience).setNotification(notifcation).build();
4752

48-
JsonObject json = new JsonObject();
49-
json.add("audience", new JsonPrimitive("all"));
50-
json.add("platform", new JsonPrimitive("all"));
51-
json.add("notification", getNotificationAlert("alert"));
52-
Assert.assertEquals("", json, push.toJSON());
53+
Assert.assertEquals("", getNotificationAlert("alert"), payload.toJSON());
5354
}
5455

5556
public JsonObject getNotificationAlert(String alert) {

0 commit comments

Comments
 (0)