1313import cn .jpush .api .common .resp .DefaultResult ;
1414import cn .jpush .api .common .resp .ResponseWrapper ;
1515
16+ import com .google .common .base .Preconditions ;
1617import com .google .gson .JsonArray ;
1718import com .google .gson .JsonObject ;
1819import com .google .gson .JsonPrimitive ;
@@ -51,39 +52,53 @@ public TagAliasResult getDeviceTagAlias(String registrationId) throws APIConnect
5152 return BaseResult .fromResponse (response , TagAliasResult .class );
5253 }
5354
54- public DefaultResult updateDeviceTagAlias (String registrationId , String alias , boolean clearTag ,
55+ public DefaultResult updateDeviceTagAlias (String registrationId , boolean clearAlias , boolean clearTag ) throws APIConnectionException , APIRequestException {
56+ Preconditions .checkArgument (clearAlias || clearTag , "It is not meaningful to do nothing." );
57+
58+ String url = HOST_NAME_SSL + DEVICE_PATH + "/" + registrationId ;
59+
60+ JsonObject top = new JsonObject ();
61+ if (clearAlias ) {
62+ top .addProperty ("alias" , "" );
63+ }
64+ if (clearTag ) {
65+ top .addProperty ("tags" , "" );
66+ }
67+
68+ ResponseWrapper response = _httpClient .sendPost (url , top .toString ());
69+
70+ return DefaultResult .fromResponse (response , DefaultResult .class );
71+ }
72+
73+ public DefaultResult updateDeviceTagAlias (String registrationId , String alias ,
5574 Set <String > tagsToAdd , Set <String > tagsToRemove ) throws APIConnectionException , APIRequestException {
5675 String url = HOST_NAME_SSL + DEVICE_PATH + "/" + registrationId ;
5776
5877 JsonObject top = new JsonObject ();
5978 if (null != alias ) {
6079 top .addProperty ("alias" , alias );
6180 }
62- if (clearTag ) {
63- top .addProperty ("tag" , "" );
64- } else {
65- JsonObject tagObject = new JsonObject ();
66- JsonArray tagsAdd = ServiceHelper .fromSet (tagsToAdd );
67- if (tagsAdd .size () > 0 ) {
68- tagObject .add ("add" , tagsAdd );
69- }
70-
71- JsonArray tagsRemove = ServiceHelper .fromSet (tagsToRemove );
72- if (tagsRemove .size () > 0 ) {
73- tagObject .add ("remove" , tagsRemove );
74- }
75-
76- if (tagObject .entrySet ().size () > 0 ) {
77- top .add ("tag" , tagObject );
78- }
81+
82+ JsonObject tagObject = new JsonObject ();
83+ JsonArray tagsAdd = ServiceHelper .fromSet (tagsToAdd );
84+ if (tagsAdd .size () > 0 ) {
85+ tagObject .add ("add" , tagsAdd );
86+ }
87+
88+ JsonArray tagsRemove = ServiceHelper .fromSet (tagsToRemove );
89+ if (tagsRemove .size () > 0 ) {
90+ tagObject .add ("remove" , tagsRemove );
91+ }
92+
93+ if (tagObject .entrySet ().size () > 0 ) {
94+ top .add ("tags" , tagObject );
7995 }
8096
8197 ResponseWrapper response = _httpClient .sendPost (url , top .toString ());
8298
8399 return DefaultResult .fromResponse (response , DefaultResult .class );
84100 }
85-
86-
101+
87102 // ------------- tags
88103
89104 public TagListResult getTagList () throws APIConnectionException , APIRequestException {
@@ -132,7 +147,7 @@ public DefaultResult addRemoveDevicesFromTag(String theTag, Set<String> toAddUse
132147 public DefaultResult deleteTag (String theTag , String platform ) throws APIConnectionException , APIRequestException {
133148 String url = HOST_NAME_SSL + TAG_PATH + "/" + theTag ;
134149 if (null != platform ) {
135- url += "/ ?platform=" + platform ;
150+ url += "?platform=" + platform ;
136151 }
137152
138153 ResponseWrapper response = _httpClient .sendDelete (url );
@@ -146,7 +161,7 @@ public DefaultResult deleteTag(String theTag, String platform) throws APIConnect
146161 public AliasDeviceListResult getAliasDeviceList (String alias , String platform ) throws APIConnectionException , APIRequestException {
147162 String url = HOST_NAME_SSL + ALIAS_PATH + "/" + alias ;
148163 if (null != platform ) {
149- url += "/ ?platform=" + platform ;
164+ url += "?platform=" + platform ;
150165 }
151166
152167 ResponseWrapper response = _httpClient .sendGet (url );
@@ -157,7 +172,7 @@ public AliasDeviceListResult getAliasDeviceList(String alias, String platform) t
157172 public DefaultResult deleteAlias (String alias , String platform ) throws APIConnectionException , APIRequestException {
158173 String url = HOST_NAME_SSL + ALIAS_PATH + "/" + alias ;
159174 if (null != platform ) {
160- url += "/ ?platform=" + platform ;
175+ url += "?platform=" + platform ;
161176 }
162177
163178 ResponseWrapper response = _httpClient .sendDelete (url );
0 commit comments