Skip to content

Commit

Permalink
Merge pull request #49 from jpush/dev
Browse files Browse the repository at this point in the history
merge version 3.2.8
  • Loading branch information
Liuchy1 committed Dec 21, 2015
2 parents 81a93ba + 9884cfc commit 70e3b8a
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 122 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,31 @@
LOG.info("Error Message: " + e.getErrorMessage());
}
```

### Custom Client 样例

> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample
```Java
public static void testCustomClient() {
ClientConfig config = ClientConfig.getInstance();
config.setMaxRetryTimes(5);
config.setConnectionTimeout(10 * 1000); // 10 seconds
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
}

public static void testCustomPushClient() {
ClientConfig config = ClientConfig.getInstance();
config.setApnsProduction(false); // development env
config.setTimeToLive(60 * 60 * 24); // one day

// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client

// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only

}
```
51 changes: 51 additions & 0 deletions example/main/java/cn/jpush/api/examples/ClientExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cn.jpush.api.examples;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.ClientConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientExample {
protected static final Logger LOG = LoggerFactory.getLogger(ClientExample.class);

private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {
// testDefaultClient();
// testCustomClient();
// testCustomPushClient();
}

public static void testDefaultClient() {
JPushClient client = new JPushClient(masterSecret, appKey);

// JPushClient client1 = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
}

public static void testCustomClient() {
ClientConfig config = ClientConfig.getInstance();
config.setMaxRetryTimes(5);
config.setConnectionTimeout(10 * 1000); // 10 seconds
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
}

public static void testCustomPushClient() {
ClientConfig config = ClientConfig.getInstance();

config.setApnsProduction(false); // development env
config.setTimeToLive(60 * 60 * 24); // one day

// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day

JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client

// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only

}

}


Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package cn.jpush.api.examples;

import cn.jpush.api.common.resp.DefaultResult;
import cn.jpush.api.device.OnlineStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.common.resp.DefaultResult;
import cn.jpush.api.device.OnlineStatus;
import cn.jpush.api.device.TagAliasResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class DevcieExample {
protected static final Logger LOG = LoggerFactory.getLogger(DevcieExample.class);
public class DeviceExample {
protected static final Logger LOG = LoggerFactory.getLogger(DeviceExample.class);

private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
private static final String TAG1 = "tag1";
private static final String ALIAS1 = "alias1";
private static final String ALIAS2 = "alias2";
Expand All @@ -27,7 +26,7 @@ public class DevcieExample {

public static void main(String[] args) {
// testGetDeviceTagAlias();
testGetUserOnlineStatus();
// testGetUserOnlineStatus();
}

public static void testGetDeviceTagAlias() {
Expand Down
4 changes: 2 additions & 2 deletions example/main/java/cn/jpush/api/examples/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class PushExample {
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);

// demo App defined in resources/jpush-api.conf
private static final String appKey ="e5c0d34f58732cf09b2d4d74";
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static final String TITLE = "Test from API example";
public static final String ALERT = "Test from API Example - alert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ReportsExample {

// demo App defined in resources/jpush-api.conf
private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {
testGetReport();
Expand Down
4 changes: 2 additions & 2 deletions example/main/java/cn/jpush/api/examples/ScheduleExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ScheduleExample {

protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);

private static final String appKey ="e5c0d34f58732cf09b2d4d74";
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";

public static void main(String[] args) {

Expand Down
62 changes: 49 additions & 13 deletions src/main/java/cn/jpush/api/JPushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,39 @@ public JPushClient(String masterSecret, String appKey) {
_deviceClient = new DeviceClient(masterSecret, appKey);
_scheduleClient = new ScheduleClient(masterSecret, appKey);
}


/**
* Create a JPush Client by custom Client configuration.
*
* @param masterSecret API access secret of the appKey.
* @param appKey The KEY of one application on JPush.
* @param proxy The proxy, if there is no proxy, should be null.
* @param conf The client configuration. Can use ClientConfig.getInstance() as default.
*/
public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
}

/**
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
*
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, int maxRetryTimes) {
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes);
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes);
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes);
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes);
}


/**
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
*
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy) {
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy);
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy);
Expand All @@ -73,25 +98,33 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
* Create a JPush Client by custom Client configuration.
*
* If you are using JPush privacy cloud, maybe this constructor is what you needed.
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
*
* @param masterSecret API access secret of the appKey.
* @param appKey The KEY of one application on JPush.
* @param maxRetryTimes Client request retry times.
* @param proxy The proxy, if there is no proxy, should be null.
* @param conf The client configuration. Can use ClientConfig.getInstance() as default.
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf) {
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
conf.setMaxRetryTimes(maxRetryTimes);

_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);

}



/**
* Create a JPush Client by custom Client configuration with global settings.
*
* If you are using JPush privacy cloud, and you want different settings from default globally,
* maybe this constructor is what you needed.
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
*
* @param masterSecret API access secret of the appKey.
* @param appKey The KEY of one application on JPush.
Expand All @@ -101,33 +134,36 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
* @param apnsProduction Global APNs environment setting. It will override PushPayload Options.
* @param timeToLive Global time_to_live setting. It will override PushPayload Options.
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf,
boolean apnsProduction, long timeToLive) {
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
conf.setMaxRetryTimes(maxRetryTimes);
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
_pushClient.setDefaults(apnsProduction, timeToLive);

}

/**
* Create a JPush Client with global settings.
*
* If you want different settings from default globally, this constructor is what you needed.
*
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
*
* @param masterSecret API access secret of the appKey.
* @param appKey The KEY of one application on JPush.
* @param apnsProduction Global APNs environment setting. It will override PushPayload Options.
* @param timeToLive Global time_to_live setting. It will override PushPayload Options.
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) {
_pushClient = new PushClient(masterSecret, appKey, apnsProduction, timeToLive);
_reportClient = new ReportClient(masterSecret, appKey);
_deviceClient = new DeviceClient(masterSecret, appKey);
_scheduleClient = new ScheduleClient(masterSecret, appKey);
}


// ----------------------------- Push API

/**
Expand Down
Loading

0 comments on commit 70e3b8a

Please sign in to comment.