summaryrefslogtreecommitdiff
path: root/src/io/BearerRequester.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/BearerRequester.java')
-rw-r--r--src/io/BearerRequester.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/io/BearerRequester.java b/src/io/BearerRequester.java
index 442f62a..11776fc 100644
--- a/src/io/BearerRequester.java
+++ b/src/io/BearerRequester.java
@@ -1,5 +1,7 @@
package io;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -57,18 +59,16 @@ public class BearerRequester extends AbstractRequester {
conn.setDoOutput(true);
conn.getOutputStream().write(postData.getBytes(Charsets.UTF_8));
- try {
- JSONObject resp = getResponseAsJson(conn);
- // TODO: parse resp.errors
- if (!resp.getString("token_type").equals("bearer")) {
- throw new IOException("Expected bearer token type");
- }
- access_token = resp.getString("access_token");
- } catch (JSONException ex) {
- // treat JSON errors as if an I/O error occurred
- throw new IOException(ex);
+ JsonObject resp = getResponseAsJson(conn).getAsJsonObject();
+ if (!resp.getAsJsonObject().getAsJsonPrimitive("token_type").getAsString().equals("bearer")) {
+ throw new IOException("Expected bearer token type");
}
- } finally {
+ access_token = resp.getAsJsonPrimitive("access_token").getAsString();
+ }
+ catch (ClassCastException ex) {
+ throw new IOException("Response was not a JsonObject");
+ }
+ finally {
conn.disconnect();
}
}
@@ -90,7 +90,7 @@ public class BearerRequester extends AbstractRequester {
public boolean isValid() throws IOException {
// NOTE: this actually contributes to the ratelimit (12/minute)
// TODO: find alternative that does not hit the ratelimit
- JSONObject obj = getJSONRelax("application/rate_limit_status");
- return !obj.has("errors");
+ Response obj = getJSON("application/rate_limit_status");
+ return !obj.getResp().getAsJsonObject().has("errors");
}
}