コード例 #1
0
ファイル: WeiBoOAuth2.java プロジェクト: norain2050/sp2p
 static Error oauth2(WS.HttpResponse response) {
   if (response.getQueryString().containsKey("error")) {
     Map<String, String> qs = response.getQueryString();
     return new Error(Type.OAUTH, qs.get("error"), qs.get("error_description"));
   } else if (response
       .getContentType()
       .startsWith("text/javascript")) { // Stupid Facebook returns JSON with the wrong encoding
     JsonObject jsonResponse = response.getJson().getAsJsonObject().getAsJsonObject("error");
     return new Error(
         Type.OAUTH,
         jsonResponse.getAsJsonPrimitive("type").getAsString(),
         jsonResponse.getAsJsonPrimitive("message").getAsString());
   } else {
     return new Error(Type.UNKNOWN, null, null);
   }
 }
コード例 #2
0
  public void unsubscribe(String user, String repository, String type) {
    WSRequest request = WS.url("https://api.github.com/hub");
    request.authenticate(username, password);

    request.setParameter("hub.mode", "unsubscribe");
    request.setParameter(
        "hub.topic", String.format("https://github.com/%s/%s/events/%s", user, repository, type));

    play.libs.WS.HttpResponse response = request.post();

    Logger.info("Response status : " + response.getStatus());
    Logger.info("Response body : " + response.getString());

    if (response.getStatus() == 204) {

    } else {
      // TODO
    }
  }
コード例 #3
0
ファイル: WeiBoOAuth2.java プロジェクト: norain2050/sp2p
    public Response(WS.HttpResponse response) {
      this.httpResponse = response;

      JSONObject queryJson = JSONObject.fromObject(response.getString());
      if (queryJson != null) {
        this.accessToken = queryJson.get("access_token").toString();
        this.uid = queryJson.get("uid").toString();
        this.error = null;
      } else {
        this.accessToken = null;
        this.uid = null;
        this.error = Error.oauth2(response);
      }
    }