public static <T> DbxWrappedException fromResponse(StoneSerializer<T> errSerializer, HttpRequestor.Response response, String userId) throws IOException, JsonParseException { String requestId = DbxRequestUtil.getRequestId(response); ApiErrorResponse<T> apiResponse = new ApiErrorResponse.Serializer<T>(errSerializer) .deserialize(response.getBody()); T routeError = apiResponse.getError(); DbxGlobalCallbackFactory factory = DbxRequestUtil.sharedCallbackFactory; DbxWrappedException.executeBlockForObject(factory, userId, routeError); DbxWrappedException.executeOtherBlocks(factory, userId, routeError); return new DbxWrappedException(routeError, requestId, apiResponse.getUserMessage()); }
protected DbxApiException newException(DbxWrappedException error) { return new DbxApiException(error.getRequestId(), error.getUserMessage(), "Unexpected error response for \"upload_session/start\":" + error.getErrorValue()); } }
public static String buildUrlWithParams(/*@Nullable*/String userLocale, String host, String path, /*@Nullable*/String/*@Nullable*/[] params) { return buildUri(host, path) + "?" + encodeUrlParams(userLocale, params); }
/** * Builds an instance of {@link DbxRequestConfig} with this builder's configured parameters * or defaults. * * @return new {@code DbxRequestConfig} instance. */ public DbxRequestConfig build() { return new DbxRequestConfig(clientIdentifier, userLocale, httpRequestor, maxRetries); } }
private String buildOAuth1Header(DbxOAuth1AccessToken token) { StringBuilder buf = new StringBuilder(); buf.append("OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\""); buf.append(", oauth_consumer_key=\"").append(encode(this.appInfo.getKey())).append("\""); buf.append(", oauth_token=\"").append(encode(token.getKey())).append("\""); buf.append(", oauth_signature=\"").append(encode(this.appInfo.getSecret())).append("&").append(encode(token.getSecret())).append("\""); return buf.toString(); }
@Override protected void addAuthHeaders(List<HttpRequestor.Header> headers) { DbxRequestUtil.addAuthHeader(headers, accessToken); if (memberId != null) { DbxRequestUtil.addSelectUserHeader(headers, memberId); } if (adminId != null) { DbxRequestUtil.addSelectAdminHeader(headers, adminId); } }
/** * @param key Dropbox app key (see {@link #getKey}) * @param secret Dropbox app secret (see {@link #getSecret}) */ public DbxAppInfo(String key, String secret) { checkKeyArg(key); checkSecretArg(secret); this.key = key; this.secret = secret; this.host = DbxHost.DEFAULT; }
@Override public T run() throws DbxException { HttpRequestor.Response response = startPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers); return finishResponse(response, handler); } });
public <T> T doPost(String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/ArrayList<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException { return DbxRequestUtil.doPost(requestConfig, accessToken, USER_AGENT_ID, host, path, params, headers, handler); }
/** * Call this after the user has visited the authorizaton URL and copy/pasted the authorization * code that Dropbox gave them. * * @param code The authorization code shown to the user when they clicked "Allow" on the * authorization, page on the Dropbox website, never {@code null}. * * @throws DbxException if an error occurs communicating with Dropbox. */ public DbxAuthFinish finishFromCode(String code) throws DbxException { return finish(code); }
private <T> T doGet(String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/ArrayList<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException { return DbxRequestUtil.doGet(requestConfig, accessToken, USER_AGENT_ID, host, path, params, headers, handler); }
/** * Call this after the user has visited the authorizaton URL and copy/pasted the authorization * code that Dropbox gave them. * * @param code * The authorization code shown to the user when they clicked "Allow" on the authorization * page on the Dropbox website. */ public DbxAuthFinish finish(String code) throws DbxException { return auth.finishFromCode(code); } }
/** * Returns a new request builder with default values (e.g. no redirect). * * @return new request builder with default values */ public static Builder newBuilder() { return new Builder(); }
/** * Returns a builder for building a copy of this configuration. Useful for modifying an existing * configuration. * * @return builder configured to build a copy of this instance */ public Builder copy() { return new Builder(clientIdentifier, userLocale, httpRequestor, maxRetries); }
/** * @param appInfo * Your application's Dropbox API information (the app key and secret). */ public DbxWebAuthNoRedirect(DbxRequestConfig requestConfig, DbxAppInfo appInfo) { this.auth = new DbxWebAuth(requestConfig, appInfo); }
@Override public void write(NoThrowOutputStream out) { out.write(this.data, this.offset, this.length); } }
@Override public void read(NoThrowInputStream in) { in.read(this.data, this.offset, this.length); } }
@Override public IOException getCause() { // guaranteed to be an IOException return (IOException) super.getCause(); } }
/** * Returns a new request builder with default values (e.g. no redirect). * * @return new request builder with default values */ public static Request.Builder newRequestBuilder() { return Request.newBuilder(); }
/** * @param key Dropbox app key (see {@link #getKey}) * @param secret Dropbox app secret (see {@link #getSecret}) * @param host Dropbox host configuration (see {@link #getHost}) */ public DbxAppInfo(String key, String secret, DbxHost host) { checkKeyArg(key); checkSecretArg(secret); this.key = key; this.secret = secret; this.host = host; }