Package play.libs.WS

Examples of play.libs.WS.WSRequest


        this.secret = Preconditions.checkNotNull(secret, "Secret can't be null");
    }

    @Override
    public DbxAccount getAccount() {
        WSRequest ws = new WSRequestFactory(DropboxURLs.ACCOUNT, token, secret).create();
        return new Gson().fromJson(ws.get().getJson(), DbxAccount.class);
    }
View Full Code Here


    @Override
    public DbxMetadata getMetadata(String path) throws InvalidTokenException {
        Preconditions.checkNotNull(path, "Path missing.");
        path = path.startsWith("/") ? path : "/" + path;

        WSRequest ws = new WSRequestFactory(DropboxURLs.METADATA, token, secret)
            .addPath(path)
            .addPair("include_deleted", "false")
            .create();

        try {
View Full Code Here

    @Override
    public boolean mkdir(String path) {
        Preconditions.checkNotNull(path, "Path missing.");
        Preconditions.checkArgument(path.charAt(0) == '/', "Path should start with /.");

        WSRequest ws = new WSRequestFactory(DropboxURLs.CREATE_FOLDER, token, secret)
            .addPair("root", "dropbox")
            .addPair("path", path)
            .create();

        try {
          HttpResponse resp = ws.get();
          if (resp.success()) {
              return true;
          }

          Logger.error("Failed creating folder at '%s'. %s", path, getError(resp));
View Full Code Here

        Preconditions.checkArgument((from.charAt(0) == '/') && (to.charAt(0) == '/'),
                "To and from paths should start with /");
        Preconditions.checkArgument(Dropbox.isValidFilename(to),
                "To path contains bad characters: '" + to + "' Bad chars: \\ : ? * < > \"");
       
        WSRequest ws = new WSRequestFactory(DropboxURLs.MOVE, token, secret)
            .addPair("root", "dropbox")
            .addPair("from_path", from)
            .addPair("to_path", to)
            .create();
       
View Full Code Here

    @Override
    public HttpResponse debug(HTTPMethod method, String url) throws InvalidTokenException {
        Preconditions.checkArgument(url.startsWith("/"), "url must start with /");

        WSRequest req = WS.url(Dropbox.API_URL + url)
                          .oauth(Dropbox.OAUTH,
                                 this.token,
                                 this.secret);
        switch (method) {
        case GET:
View Full Code Here

                String.format("/authorize?response_type=code&client_id=%s&redirect_uri=%s",
                              CLIENT_ID, WS.encode(Router.getFullUrl("Login.boxAuthCallback")));
    }

    public static BoxCredentials getCred(String code) {
        WSRequest ws = WS.url(URLs.BASE_V2_OAUTH + "/token")
                         .setParameter("grant_type", "authorization_code")
                         .setParameter("code", code)
                         .setParameter("client_id", CLIENT_ID)
                         .setParameter("client_secret", CLIENT_SECRET);

        HttpResponse resp = ws.post();
        if (resp.success()) {
            return new Gson().fromJson(resp.getJson(), BoxCredentials.class);
        }

        throw new IllegalStateException("Failed fetching box account credentials. Status: " + resp.getStatus() +
View Full Code Here

    @Override
    @Nonnull
    public HttpResponse debug(HTTPMethod method, String url) throws InvalidTokenException {
        Preconditions.checkArgument(url.startsWith("/"), "url must start with /");
       
        WSRequest req = req(url);
        switch (method) {
        case GET:
            return req.get();
        case POST:
            return req.post();
        default:
            throw new IllegalArgumentException("Unhandled HTTP method");
        }
    }
View Full Code Here

        return null;
    }

    @Override
    public BoxAccount getAccount() {
        WSRequest req = req("/users/me");
       
        HttpResponse resp = req.get();
        if (resp.success()) {
            return new Gson().fromJson(resp.getJson(), BoxAccount.class);
        }
       
        throw new IllegalStateException("Failed fetching box account info. Status: " + resp.getStatus() +
View Full Code Here

    private @CheckForNull BoxItem getMetadata(@Nonnull String id, String type) throws InvalidTokenException {
        if (id == null) {
            throw new NullPointerException("Parent id cannot be null");
        }

        WSRequest request;
        if (BoxItem.FOLDER.equals(type)) {
            request = req("/folders/" + OAuth.percentEncode(id))
                          .setParameter("limit", 1000);
        } else {
            request = req("/files/" + OAuth.percentEncode(id));
        }

        Logger.info("getMetadata: id: %s type: %s", id, type);
        HttpResponse resp = request.get();
        if (resp.success()) {
            return new Gson().fromJson(resp.getJson(), BoxItem.class);
        }

        String err = getError(resp);
View Full Code Here

  public static JsonObject query(String query, boolean retry) {
    OAuthSession oauth = ForceDotComOAuth2.getOAuthSession();
    if (oauth == null) {
      Application.index();
    }
    WSRequest req = WS.url(oauth.instance_url
        + "/services/data/v28.0/query/?q=%s", query);
    req.headers.put("Authorization", "OAuth " + oauth.access_token);
    HttpResponse response = req.get();

    int res = response.getStatus();
    if (res == 200) {
      return response.getJson().getAsJsonObject().getAsJsonObject();
    } else if (res == 400) {
View Full Code Here

TOP

Related Classes of play.libs.WS.WSRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.