1919import java .util .Arrays ;
2020import java .util .List ;
2121import java .util .function .Function ;
22+ import java .util .stream .Collectors ;
2223
2324public class DevRant {
2425 static final String APP_ID = "3" ;
@@ -167,7 +168,8 @@ private <T> List<T> getFeed(String url, Function<JsonObject, T> converter, Sort
167168 return getFeed (url , converter ,
168169 new BasicNameValuePair ("sort" , sort .toString ()),
169170 new BasicNameValuePair ("limit" , String .valueOf (limit )),
170- new BasicNameValuePair ("skip" , String .valueOf (skip ))
171+ new BasicNameValuePair ("skip" , String .valueOf (skip )),
172+ sort .getParameter ()
171173 );
172174 }
173175
@@ -255,7 +257,7 @@ public boolean vote(Rant rant, Vote vote) {
255257 public boolean voteRant (int id , Vote vote ) {
256258 // Rants url, id, vote url.
257259 String url = String .format ("%1$s/%2$d%3$s" , API_RANTS , id , API_VOTE );
258- return Util .jsonSuccess (post (url , new BasicNameValuePair ("vote" , String . valueOf ( vote .getValue ()))));
260+ return Util .jsonSuccess (post (url , new BasicNameValuePair ("vote" , vote .toString ()), vote . getParameter ( )));
259261 }
260262
261263 /**
@@ -279,7 +281,7 @@ public boolean vote(Comment comment, Vote vote) {
279281 public boolean voteComment (int id , Vote vote ) {
280282 // API url, comments url, id, vote url.
281283 String url = String .format ("%1$s%2$s/%3$d%4$s" , API , API_COMMENT , id , API_VOTE );
282- return Util .jsonSuccess (post (url , new BasicNameValuePair ("vote" , String .valueOf (vote .getValue ()))));
284+ return Util .jsonSuccess (post (url , new BasicNameValuePair ("vote" , String .valueOf (vote .toString ())), vote . getParameter ( )));
283285 }
284286
285287 /**
@@ -356,13 +358,14 @@ JsonObject get(String url, NameValuePair... params) {
356358
357359 /**
358360 * Get a list with all the parameters, including default and auth parameters.
361+ * This also filters out any parameters that are {@code null}.
359362 *
360363 * @param params The parameters to use.
361364 * @return A list containing the given parameters, the default parameters, and the auth parameters.
362365 */
363366 private List <NameValuePair > getParameters (NameValuePair ... params ) {
364- List <NameValuePair > paramList = new ArrayList <>(params .length + 5 );
365- paramList .addAll (Arrays .asList (params ));
367+ List <NameValuePair > paramList = new ArrayList <>(params .length + 6 );
368+ paramList .addAll (Arrays .stream (params ). filter ( p -> p != null ). collect ( Collectors . toList () ));
366369
367370 // Add the parameters which always need to be present.
368371 paramList .add (new BasicNameValuePair ("app" , APP_ID ));
0 commit comments