Skip to content

Commit

Permalink
Merge pull request #166 from yutaipu/master
Browse files Browse the repository at this point in the history
支持解绑设备与别名的绑定关系
  • Loading branch information
yutaipu committed Jul 30, 2020
2 parents c9d1b4e + 9674cd1 commit b0a064e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.4.4</version>
<version>3.4.6-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/jpush/jpush-api-java-client</url>
<name>JPush API Java Client</name>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cn/jpush/api/JPushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,11 @@ public DefaultResult deleteAlias(String alias, String platform)
return _deviceClient.deleteAlias(alias, platform);
}

public DefaultResult removeDevicesFromAlias(String alias, Set<String> toRemoveDevice)
throws APIConnectionException, APIRequestException {
return _deviceClient.removeDevicesFromAlias(alias, toRemoveDevice);
}

public Map<String, OnlineStatus> getUserOnlineStatus(String... registrationIds)
throws APIConnectionException, APIRequestException
{
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/cn/jpush/api/device/DeviceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ public DefaultResult deleteAlias(String alias, String platform) throws APIConnec
return DefaultResult.fromResponse(response);
}

public DefaultResult removeDevicesFromAlias(String alias, Set<String> toRemoveDevice) throws APIConnectionException, APIRequestException {
String url = hostName + aliasesPath + "/" + alias;

JsonObject top = new JsonObject();
JsonObject registrationIds = new JsonObject();

if (null != toRemoveDevice && toRemoveDevice.size() > 0) {
JsonArray array = new JsonArray();
for (String device : toRemoveDevice) {
array.add(new JsonPrimitive(device));
}
registrationIds.add("remove", array);
}

top.add("registration_ids", registrationIds);

ResponseWrapper response = _httpClient.sendPost(url, top.toString());

return DefaultResult.fromResponse(response);
}

// -------------- devices status

public Map<String, OnlineStatus> getUserOnlineStatus(String... registrationIds)
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void testGetDeviceTagAlias_cleard() throws Exception {
assertEquals("tags cleared", 0, result.tags.size());
}



// ------------------ tags

@Test
Expand Down Expand Up @@ -197,4 +197,13 @@ public void testBindMobile_empty() throws APIConnectionException, APIRequestExce
assertTrue(result.isResultOK());
}

@Test
@TestOrder(order = 330)
public void testRemoveDevicesFromAlias() throws APIConnectionException, APIRequestException {
Set<String> toRemoveDevice = new HashSet<>();
toRemoveDevice.add(REGISTRATION_ID1);
DefaultResult result = jpushClient.removeDevicesFromAlias("alias1", toRemoveDevice);
assertTrue(result.isResultOK());
}

}

0 comments on commit b0a064e

Please sign in to comment.