public Map<String, MessageStatus> getMessagesStatus(CheckMessagePayload payload) throws APIConnectionException, APIRequestException { String url = _hostName + (_statusPath.endsWith("/message")?_statusPath:(_statusPath+"/message")); ResponseWrapper result = _httpClient.sendPost(url, payload.toString()); Type type = new TypeToken<Map<String, MessageStatus>>(){}.getType(); return new Gson().fromJson(result.responseContent, type); }
public Map<String, MessageStatus> getMessagesStatus(CheckMessagePayload payload) throws APIConnectionException, APIRequestException { String url = _hostName + (_statusPath.endsWith("/message")?_statusPath:(_statusPath+"/message")); ResponseWrapper result = _httpClient.sendPost(url, payload.toString()); Type type = new TypeToken<Map<String, MessageStatus>>(){}.getType(); return new Gson().fromJson(result.responseContent, type); }
public DefaultResult updateDeviceTagAlias(String registrationId, boolean clearAlias, boolean clearTag) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(clearAlias || clearTag, "It is not meaningful to do nothing."); String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); if (clearAlias) { top.addProperty("alias", ""); } if (clearTag) { top.addProperty("tags", ""); } ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public DefaultResult bindMobile(String registrationId, String mobile) throws APIConnectionException, APIRequestException { if ( StringUtils.isEmpty(mobile) ) { // delete bind while mobile is empty. mobile = ""; } else { // Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile); } String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); top.addProperty("mobile", mobile); ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public DefaultResult updateDeviceTagAlias(String registrationId, boolean clearAlias, boolean clearTag) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(clearAlias || clearTag, "It is not meaningful to do nothing."); String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); if (clearAlias) { top.addProperty("alias", ""); } if (clearTag) { top.addProperty("tags", ""); } ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public DefaultResult bindMobile(String registrationId, String mobile) throws APIConnectionException, APIRequestException { if ( StringUtils.isEmpty(mobile) ) { // delete bind while mobile is empty. mobile = ""; } else { // Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile); } String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); top.addProperty("mobile", mobile); ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public DefaultResult addRemoveDevicesFromTag(String theTag, Set<String> toAddUsers, Set<String> toRemoveUsers) throws APIConnectionException, APIRequestException { String url = hostName + tagsPath + "/" + theTag; JsonObject top = new JsonObject(); JsonObject registrationIds = new JsonObject(); if (null != toAddUsers && toAddUsers.size() > 0) { JsonArray array = new JsonArray(); for (String user : toAddUsers) { array.add(new JsonPrimitive(user)); } registrationIds.add("add", array); } if (null != toRemoveUsers && toRemoveUsers.size() > 0) { JsonArray array = new JsonArray(); for (String user : toRemoveUsers) { array.add(new JsonPrimitive(user)); } registrationIds.add("remove", array); } top.add("registration_ids", registrationIds); ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public DefaultResult addRemoveDevicesFromTag(String theTag, Set<String> toAddUsers, Set<String> toRemoveUsers) throws APIConnectionException, APIRequestException { String url = hostName + tagsPath + "/" + theTag; JsonObject top = new JsonObject(); JsonObject registrationIds = new JsonObject(); if (null != toAddUsers && toAddUsers.size() > 0) { JsonArray array = new JsonArray(); for (String user : toAddUsers) { array.add(new JsonPrimitive(user)); } registrationIds.add("add", array); } if (null != toRemoveUsers && toRemoveUsers.size() > 0) { JsonArray array = new JsonArray(); for (String user : toRemoveUsers) { array.add(new JsonPrimitive(user)); } registrationIds.add("remove", array); } top.add("registration_ids", registrationIds); ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public Map<String, OnlineStatus> getUserOnlineStatus(String... registrationIds) throws APIConnectionException, APIRequestException { Preconditions.checkArgument((null != registrationIds ), "The registration id list should not be null."); Preconditions.checkArgument(registrationIds.length > 0 && registrationIds.length <= 1000, "The length of registration id list should between 1 and 1000."); String url = hostName + devicesPath + "/status"; JsonObject json = new JsonObject(); JsonArray array = new JsonArray(); for(int i = 0; i < registrationIds.length; i++) { array.add(new JsonPrimitive(registrationIds[i])); } json.add("registration_ids", array); Type type = new TypeToken<Map<String, OnlineStatus>>(){}.getType(); ResponseWrapper response = _httpClient.sendPost(url, json.toString()); Map<String, OnlineStatus> map = new Gson().fromJson(response.responseContent, type); return map; }
public DefaultResult updateDeviceTagAlias(String registrationId, String alias, Set<String> tagsToAdd, Set<String> tagsToRemove) throws APIConnectionException, APIRequestException { String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); if (null != alias) { top.addProperty("alias", alias); } JsonObject tagObject = new JsonObject(); JsonArray tagsAdd = ServiceHelper.fromSet(tagsToAdd); if (tagsAdd.size() > 0) { tagObject.add("add", tagsAdd); } JsonArray tagsRemove = ServiceHelper.fromSet(tagsToRemove); if (tagsRemove.size() > 0) { tagObject.add("remove", tagsRemove); } if (tagObject.entrySet().size() > 0) { top.add("tags", tagObject); } ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public Map<String, OnlineStatus> getUserOnlineStatus(String... registrationIds) throws APIConnectionException, APIRequestException { Preconditions.checkArgument((null != registrationIds ), "The registration id list should not be null."); Preconditions.checkArgument(registrationIds.length > 0 && registrationIds.length <= 1000, "The length of registration id list should between 1 and 1000."); String url = hostName + devicesPath + "/status"; JsonObject json = new JsonObject(); JsonArray array = new JsonArray(); for(int i = 0; i < registrationIds.length; i++) { array.add(new JsonPrimitive(registrationIds[i])); } json.add("registration_ids", array); Type type = new TypeToken<Map<String, OnlineStatus>>(){}.getType(); ResponseWrapper response = _httpClient.sendPost(url, json.toString()); Map<String, OnlineStatus> map = new Gson().fromJson(response.responseContent, type); return map; }
public DefaultResult updateDeviceTagAlias(String registrationId, String alias, Set<String> tagsToAdd, Set<String> tagsToRemove) throws APIConnectionException, APIRequestException { String url = hostName + devicesPath + "/" + registrationId; JsonObject top = new JsonObject(); if (null != alias) { top.addProperty("alias", alias); } JsonObject tagObject = new JsonObject(); JsonArray tagsAdd = ServiceHelper.fromSet(tagsToAdd); if (tagsAdd.size() > 0) { tagObject.add("add", tagsAdd); } JsonArray tagsRemove = ServiceHelper.fromSet(tagsToRemove); if (tagsRemove.size() > 0) { tagObject.add("remove", tagsRemove); } if (tagObject.entrySet().size() > 0) { top.add("tags", tagObject); } ResponseWrapper response = _httpClient.sendPost(url, top.toString()); return DefaultResult.fromResponse(response); }
public ScheduleResult createSchedule(SchedulePayload payload) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(null != payload, "payload should not be null"); if (apnsProduction > 0) { payload.resetPushApnsProduction(true); } else if(apnsProduction == 0) { payload.resetPushApnsProduction(false); } if (timeToLive >= 0) { payload.resetPushTimeToLive(timeToLive); } ResponseWrapper response = _httpClient.sendPost(hostName + schedulePath, payload.toString()); return ScheduleResult.fromResponse(response, ScheduleResult.class); }
public ScheduleResult createSchedule(SchedulePayload payload) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(null != payload, "payload should not be null"); if (apnsProduction > 0) { payload.resetPushApnsProduction(true); } else if(apnsProduction == 0) { payload.resetPushApnsProduction(false); } if (timeToLive >= 0) { payload.resetPushTimeToLive(timeToLive); } ResponseWrapper response = _httpClient.sendPost(hostName + schedulePath, payload.toString()); return ScheduleResult.fromResponse(response, ScheduleResult.class); }