@Override
 protected PocketAuthInfo buildInfo(final Response r) throws AccessTokenException {
   if (r.getStatus() >= 400) {
     throw new AccessTokenException(r.asJson().asText());
   } else {
     final List<NameValuePair> list = URLEncodedUtils.parse(r.getBody(), Charset.forName("UTF-8"));
     final Map<String, String> map = new HashMap<String, String>(list.size());
     for (final NameValuePair nameValuePair : list) {
       map.put(nameValuePair.getName(), nameValuePair.getValue());
     }
     return new PocketAuthInfo(map);
   }
 }
  private String getRequestToken(final Request request) throws AuthException {
    final Configuration c = getConfiguration();
    final List<NameValuePair> params = getRequestTokenParams(request, c);
    final Response r =
        WS.url(c.getString(SettingKeys.REQUEST_TOKEN_URL))
            .setHeader("Content-Type", "application/json")
            .setHeader("X-Accept", "application/json")
            .post(encodeParamsAsJson(params))
            .get(getTimeout());

    if (r.getStatus() >= 400) {
      throw new AuthException(r.asJson().asText());
    } else {
      return r.asJson().get(PocketConstants.CODE).asText();
    }
  }
예제 #3
0
 protected BaseApiJsonResponse(
     HttpMethodType method,
     String urlDomain,
     String urlPath,
     Map<String, String> params,
     Response resp) {
   super(method, urlDomain, urlPath, params, resp);
   this.json = resp.asJson();
 }