Skip to content

Commit f64c012

Browse files
authored
Merge pull request #103 from jpush/dev
Dev
2 parents ca0e8e5 + 640e2b9 commit f64c012

File tree

9 files changed

+178
-12
lines changed

9 files changed

+178
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>cn.jpush.api</groupId>
4444
<artifactId>jiguang-common</artifactId>
45-
<version>1.0.8</version>
45+
<version>1.0.9</version>
4646
</dependency>
4747
<dependency>
4848
<groupId>org.apache.httpcomponents</groupId>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.jpush.api;
2+
3+
import cn.jiguang.common.ClientConfig;
4+
5+
public class JPushConfig {
6+
7+
private static ClientConfig clientConfig = ClientConfig.getInstance();
8+
9+
private static JPushConfig instance = new JPushConfig();
10+
11+
public static final String ADMIN_HOST_NAME = "api.admin.host.name";
12+
public static final String V1_APP_PATH = "jpush.v1.app.path";
13+
14+
private JPushConfig() {
15+
clientConfig.put(ADMIN_HOST_NAME, "https://admin.jpush.cn");
16+
clientConfig.put(V1_APP_PATH, "/v1/app");
17+
}
18+
19+
public static JPushConfig getInstance() {
20+
return instance;
21+
}
22+
23+
public ClientConfig getClientConfig() {
24+
return clientConfig;
25+
}
26+
27+
public JPushConfig setAdminHostName(String hostName) {
28+
clientConfig.put(ADMIN_HOST_NAME, hostName);
29+
return this;
30+
}
31+
32+
public void put(String key, Object value) {
33+
clientConfig.put(key, value);
34+
}
35+
36+
public Object get(String key) {
37+
return clientConfig.get(key);
38+
}
39+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package cn.jpush.api.admin;
2+
3+
import cn.jiguang.common.ServiceHelper;
4+
import cn.jiguang.common.connection.HttpProxy;
5+
import cn.jiguang.common.connection.IHttpClient;
6+
import cn.jiguang.common.connection.NativeHttpClient;
7+
import cn.jiguang.common.resp.APIConnectionException;
8+
import cn.jiguang.common.resp.APIRequestException;
9+
import cn.jiguang.common.resp.DefaultResult;
10+
import cn.jiguang.common.resp.ResponseWrapper;
11+
import cn.jiguang.common.utils.Preconditions;
12+
import cn.jpush.api.JPushConfig;
13+
import com.google.gson.Gson;
14+
import com.google.gson.JsonObject;
15+
16+
/**
17+
* Admin APIs
18+
* https://docs.jiguang.cn/jpush/server/push/rest_api_admin_api_v1/
19+
*/
20+
public class AdminClient {
21+
22+
private IHttpClient mHttpClient;
23+
private String mBasePath;
24+
private String mV1AppPath;
25+
private Gson mGson = new Gson();
26+
27+
/**
28+
* Create a Push Client.
29+
*
30+
* @param appKey The KEY of one application on JPush.
31+
* @param masterSecret API access secret of the appKey.
32+
*/
33+
public AdminClient(String appKey, String masterSecret) {
34+
this(appKey, masterSecret, null, JPushConfig.getInstance());
35+
}
36+
37+
public AdminClient(String appKey, String masterSecret, HttpProxy proxy) {
38+
this(appKey, masterSecret, proxy, JPushConfig.getInstance());
39+
}
40+
41+
42+
public AdminClient(String appKey, String masterSecret, HttpProxy proxy, JPushConfig conf) {
43+
ServiceHelper.checkBasic(appKey, masterSecret);
44+
mBasePath = (String) conf.get(JPushConfig.ADMIN_HOST_NAME);
45+
mV1AppPath = (String) conf.get(JPushConfig.V1_APP_PATH);
46+
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
47+
this.mHttpClient = new NativeHttpClient(authCode, proxy, conf.getClientConfig());
48+
}
49+
50+
public void setHttpClient(IHttpClient client) {
51+
this.mHttpClient = client;
52+
}
53+
54+
/**
55+
* Create an app under developer account
56+
* @param appName app name
57+
* @param packageName android package name
58+
* @param groupName developer app group name
59+
* @return {@link CreateAppResult}
60+
* @throws APIConnectionException connect exception
61+
* @throws APIRequestException request exception
62+
*/
63+
public CreateAppResult createApp(String appName, String packageName, String groupName)
64+
throws APIConnectionException, APIRequestException {
65+
Preconditions.checkArgument(null != appName, "app name should not be null");
66+
Preconditions.checkArgument(null != packageName, "package name should not be null");
67+
JsonObject jsonObject = new JsonObject();
68+
jsonObject.addProperty("app_name", appName);
69+
jsonObject.addProperty("android_package", packageName);
70+
if (null != groupName) {
71+
jsonObject.addProperty("group_name", groupName);
72+
}
73+
ResponseWrapper responseWrapper = mHttpClient.sendPost(mBasePath + mV1AppPath, mGson.toJson(jsonObject));
74+
return CreateAppResult.fromResponse(responseWrapper, CreateAppResult.class);
75+
}
76+
77+
/**
78+
* Delete app by app key
79+
* @param appKey app key
80+
* @return {@link AppResult}
81+
* @throws APIConnectionException connect exception
82+
* @throws APIRequestException request exception
83+
*/
84+
public AppResult deleteApp(String appKey) throws APIConnectionException, APIRequestException {
85+
ResponseWrapper responseWrapper = mHttpClient.sendDelete(mBasePath + mV1AppPath + "/" + appKey + "/delete");
86+
return DefaultResult.fromResponse(responseWrapper, AppResult.class);
87+
}
88+
89+
// public AppResult uploadCertificate(String appKey) throws APIConnectionException, APIRequestException {
90+
//
91+
// }
92+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.jpush.api.admin;
2+
3+
import cn.jiguang.common.resp.BaseResult;
4+
import com.google.gson.annotations.Expose;
5+
6+
public class AppResult extends BaseResult {
7+
8+
@Expose private String success;
9+
10+
public String getSuccess() {
11+
return success;
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.jpush.api.admin;
2+
3+
import cn.jiguang.common.resp.BaseResult;
4+
import com.google.gson.annotations.Expose;
5+
6+
public class CreateAppResult extends BaseResult {
7+
@Expose private String app_key;
8+
@Expose private boolean is_new_created;
9+
@Expose private String android_package;
10+
11+
public String getApp_key() {
12+
return app_key;
13+
}
14+
15+
public boolean is_new_created() {
16+
return is_new_created;
17+
}
18+
19+
public String getAndroid_package() {
20+
return android_package;
21+
}
22+
}

src/main/java/cn/jpush/api/report/MessagesResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MessagesResult extends BaseResult {
1919

2020
public static class Message {
2121
@Expose
22-
public long msg_id;
22+
public String msg_id;
2323
@Expose
2424
public Android android;
2525
@Expose
@@ -47,13 +47,13 @@ public static class Ios {
4747
@Expose
4848
public int apns_target;
4949
@Expose
50+
public int apns_received;
51+
@Expose
5052
public int click;
5153
@Expose
5254
public int target;
5355
@Expose
5456
public int received;
55-
@Expose
56-
public int msg_click;
5757
}
5858

5959
public static class Winphone {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static class Received {
2626
@Expose
2727
public int ios_apns_sent;
2828
@Expose
29+
public int ios_apns_received;
30+
@Expose
2931
public int ios_msg_received;
3032
@Expose
3133
public int wp_mpns_sent;

src/test/java/cn/jpush/api/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public abstract class BaseTest {
66

77
protected static final String APP_KEY = "d4ee2375846bc30fa51334f5";
8-
protected static final String MASTER_SECRET = "cfb11ca45888cdd6388483f5";
8+
protected static final String MASTER_SECRET = "3f045fd404d09a8a1f38d791";
99
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
1010
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
1111

src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ public void testUpdateDeviceTagAlias_add_remove_tags() throws APIConnectionExcep
3131
tagsToAdd.add("tag1");
3232
tagsToAdd.add("tag2");
3333
Set<String> tagsToRemove = new HashSet<String>();
34-
tagsToRemove.add("tag3");
35-
tagsToRemove.add("tag4");
36-
DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, "alias1", tagsToAdd, tagsToRemove);
34+
tagsToRemove.add("tag1");
35+
tagsToRemove.add("tag2");
36+
DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, "alias1", tagsToAdd, tagsToRemove);
3737
assertTrue(result.isResultOK());
3838
}
3939

4040
@Test
4141
@TestOrder(order = 110)
4242
public void testGetDeviceTagAlias_1() throws Exception {
43-
TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
43+
TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID3);
4444

4545
assertTrue(result.isResultOK());
4646
assertEquals("alias not equals", "alias1", result.alias);
@@ -92,10 +92,8 @@ public void testAddRemoveDevicesFromTag() throws APIConnectionException, APIRequ
9292
@Test
9393
@TestOrder(order = 210)
9494
public void testIsDeviceInTag() throws APIConnectionException, APIRequestException {
95-
BooleanResult result = jpushClient.isDeviceInTag("tag3", REGISTRATION_ID1);
95+
BooleanResult result = jpushClient.isDeviceInTag("tag2", REGISTRATION_ID3);
9696
assertTrue("", result.result);
97-
result = jpushClient.isDeviceInTag("tag3", REGISTRATION_ID2);
98-
assertFalse("", result.result);
9997
}
10098

10199
@Test

0 commit comments

Comments
 (0)