Exemplo n.º 1
0
 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);
   }
 }
  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
    }
  }
Exemplo n.º 3
0
    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);
      }
    }