@@ -97,9 +97,11 @@ public boolean isLoggedIn() {
9797 * @return An array of rants.
9898 */
9999 public List <Rant > rants (Sort sort , int limit , int skip ) {
100- // Rants url, app id, sort, skip, limit.
101- String url = String .format ("%1$s?app=%2$s&sort=%3$s&skip=%4$d&limit=%5$d" , API_RANTS , APP_ID , sort .toString (), skip , limit );
102- JsonObject json = get (url );
100+ JsonObject json = get (API_RANTS ,
101+ new BasicNameValuePair ("sort" , sort .toString ()),
102+ new BasicNameValuePair ("limit" , String .valueOf (limit )),
103+ new BasicNameValuePair ("skip" , String .valueOf (skip ))
104+ );
103105
104106 // Check for success.
105107 if (!Util .jsonSuccess (json ))
@@ -115,9 +117,7 @@ public List<Rant> rants(Sort sort, int limit, int skip) {
115117 * @return An array of rants matching the search term.
116118 */
117119 public List <Rant > search (String term ) {
118- // Search url, app id, term.
119- String url = String .format ("%1$s?app=%2$s&term=%3$s" , API_SEARCH , APP_ID , term );
120- JsonObject json = get (url );
120+ JsonObject json = get (API_SEARCH , new BasicNameValuePair ("term" , term ));
121121
122122 // Check for success.
123123 if (!Util .jsonSuccess (json ))
@@ -132,9 +132,7 @@ public List<Rant> search(String term) {
132132 * @return A random rant.
133133 */
134134 public Rant surprise () {
135- // Surprise url, app id.
136- String url = String .format ("%1$s?app=%2$s" , API_SURPRISE , APP_ID );
137- JsonObject json = get (url );
135+ JsonObject json = get (API_SURPRISE );
138136
139137 // Check for success.
140138 if (!Util .jsonSuccess (json ))
@@ -149,9 +147,7 @@ public Rant surprise() {
149147 * @return The weekly rants.
150148 */
151149 public List <Rant > weekly () {
152- // Weekly url, app id.
153- String url = String .format ("%1$s?app=%2$s" , API_WEEKLY , APP_ID );
154- JsonObject json = get (url );
150+ JsonObject json = get (API_WEEKLY );
155151
156152 // Check for success.
157153 if (!Util .jsonSuccess (json ))
@@ -166,9 +162,7 @@ public List<Rant> weekly() {
166162 * @return The collab rants.
167163 */
168164 public List <Collab > collabs () {
169- // Collab url, app id.
170- String url = String .format ("%1$s?app=%2$s&" , API_COLLABS , APP_ID );
171- JsonObject json = get (url );
165+ JsonObject json = get (API_COLLABS );
172166
173167 // Check for success.
174168 if (!Util .jsonSuccess (json ))
@@ -184,9 +178,7 @@ public List<Collab> collabs() {
184178 * @return The rant.
185179 */
186180 public Rant getRant (int id ) {
187- // Rants url, rant id, app id.
188- String url = String .format ("%1$s/%2$d?app=%3$s" , DevRant .API_RANTS , id , DevRant .APP_ID );
189- JsonObject json = get (url );
181+ JsonObject json = get (API_RANTS + '/' + id );
190182
191183 // Check if the rant exists.
192184 if (!Util .jsonSuccess (json ))
@@ -202,9 +194,7 @@ public Rant getRant(int id) {
202194 * @return The collab.
203195 */
204196 public Collab getCollab (int id ) {
205- // Collabs url, collab id, app id.
206- String url = String .format ("%1$s/%2$d?app=%3$s" , DevRant .API_RANTS , id , DevRant .APP_ID );
207- JsonObject json = get (url );
197+ JsonObject json = get (API_RANTS + '/' + id );
208198
209199 // Check if the collab exists.
210200 if (!Util .jsonSuccess (json ))
@@ -220,9 +210,7 @@ public Collab getCollab(int id) {
220210 * @return The user.
221211 */
222212 public User getUser (String username ) {
223- // Users url, user id, app id.
224- String url = String .format ("%1$s?app=%2$s&username=%3$s" , DevRant .API_USER_ID , DevRant .APP_ID , username );
225- JsonObject json = get (url );
213+ JsonObject json = get (API_USER_ID , new BasicNameValuePair ("username" , username ));
226214
227215 // Check if the user exists.
228216 if (!Util .jsonSuccess (json ))
@@ -358,8 +346,18 @@ JsonObject post(String url, NameValuePair... params) {
358346 * @param url The url to make the request to.
359347 * @return A {@link JsonObject} containing the response.
360348 */
361- JsonObject get (String url ) {
362- return executeRequest (Request .Get (BASE_URL + url ));
349+ JsonObject get (String url , NameValuePair ... params ) {
350+ StringBuilder finalUrl = new StringBuilder (url ).append ("?app=" ).append (APP_ID ).append ("&plat=" ).append (PLAT_ID );
351+
352+ // Add all parameters.
353+ for (NameValuePair param : params )
354+ finalUrl .append ('&' ).append (param .getName ()).append ('=' ).append (param .getValue ());
355+
356+ // Add the auth information.
357+ if (isLoggedIn ())
358+ finalUrl .append ("&token_id=" ).append (auth .getId ()).append ("&token_key=" ).append (auth .getKey ()).append ("&user_id=" ).append (auth .getUserId ());
359+
360+ return executeRequest (Request .Get (BASE_URL + finalUrl .toString ()));
363361 }
364362
365363 /**
0 commit comments