This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'iterate-ch-feature/b2_get_download_authorization'
- Loading branch information
Showing
5 changed files
with
145 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/synapticloop/b2/request/B2GetDownloadAuthorizationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package synapticloop.b2.request; | ||
|
||
/* | ||
* Copyright (c) 2017 iterate GmbH. | ||
* | ||
* All rights reserved. | ||
* | ||
* This code may contain contributions from other parties which, where | ||
* applicable, will be listed in the default build file for the project | ||
* ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project. | ||
* | ||
* This source code and any derived binaries are covered by the terms and | ||
* conditions of the Licence agreement ("the Licence"). You may not use this | ||
* source code or any derived binaries except in compliance with the Licence. | ||
* A copy of the Licence is available in the file named LICENSE.txt shipped with | ||
* this source code or binaries. | ||
*/ | ||
|
||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
|
||
import synapticloop.b2.exception.B2ApiException; | ||
import synapticloop.b2.response.B2AuthorizeAccountResponse; | ||
import synapticloop.b2.response.B2GetDownloadAuthorizationResponse; | ||
|
||
public class B2GetDownloadAuthorizationRequest extends BaseB2Request { | ||
private static final String B2_GET_DOWNLOAD_AUTHORIZATION = BASE_API_VERSION + "b2_get_download_authorization"; | ||
|
||
/** | ||
* @param client The http client to use | ||
* @param b2AuthorizeAccountResponse the authorize account response | ||
* @param bucketId The identifier for the bucket. | ||
* @param fileNamePrefix The file name prefix of files the download authorization token will allow b2_download_file_by_name to access. | ||
* @param validDurationInSeconds The number of seconds before the authorization token will expire. | ||
* The maximum value is 604800 which is one week in seconds. | ||
*/ | ||
public B2GetDownloadAuthorizationRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, | ||
String bucketId, String fileNamePrefix, Integer validDurationInSeconds) { | ||
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_GET_DOWNLOAD_AUTHORIZATION); | ||
|
||
this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId); | ||
this.addProperty(B2RequestProperties.KEY_FILE_NAME_PREFIX, fileNamePrefix); | ||
this.addProperty(B2RequestProperties.KEY_VALID_DURATION_INSECONDS, validDurationInSeconds); | ||
} | ||
|
||
public B2GetDownloadAuthorizationResponse getResponse() throws B2ApiException, IOException { | ||
return new B2GetDownloadAuthorizationResponse(EntityUtils.toString(executePost().getEntity())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/synapticloop/b2/response/B2GetDownloadAuthorizationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package synapticloop.b2.response; | ||
|
||
/* | ||
* Copyright (c) 2017 iterate GmbH. | ||
* | ||
* All rights reserved. | ||
* | ||
* This code may contain contributions from other parties which, where | ||
* applicable, will be listed in the default build file for the project | ||
* ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project. | ||
* | ||
* This source code and any derived binaries are covered by the terms and | ||
* conditions of the Licence agreement ("the Licence"). You may not use this | ||
* source code or any derived binaries except in compliance with the Licence. | ||
* A copy of the Licence is available in the file named LICENSE.txt shipped with | ||
* this source code or binaries. | ||
*/ | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import synapticloop.b2.exception.B2ApiException; | ||
|
||
public class B2GetDownloadAuthorizationResponse extends BaseB2Response { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(B2AuthorizeAccountResponse.class); | ||
|
||
private final String bucketId; | ||
private final String fileNamePrefix; | ||
private final String authorizationToken; | ||
|
||
public B2GetDownloadAuthorizationResponse(String json) throws B2ApiException { | ||
super(json); | ||
|
||
this.bucketId = this.readString(B2ResponseProperties.KEY_BUCKET_ID); | ||
this.fileNamePrefix = this.readString(B2ResponseProperties.KEY_FILE_NAME); | ||
this.authorizationToken = this.readString(B2ResponseProperties.KEY_AUTHORIZATION_TOKEN); | ||
|
||
this.warnOnMissedKeys(); | ||
} | ||
|
||
/** | ||
* @return The identifier for the bucket. | ||
*/ | ||
public String getBucketId() { return bucketId; } | ||
|
||
/** | ||
* @return The prefix for files the authorization token will allow b2_download_file_by_name to access. | ||
*/ | ||
public String getFileNamePrefix() { return fileNamePrefix; } | ||
|
||
/** | ||
* @return The authorization token that can be passed in the Authorization header or as an Authorization | ||
* parameter to b2_download_file_by_name to access files beginning with the file name prefix. | ||
*/ | ||
public String getAuthorizationToken() { return authorizationToken; } | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOGGER; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("B2GetDownloadAuthorizationResponse{"); | ||
sb.append("bucketId='").append(bucketId).append('\''); | ||
sb.append(", fileNamePrefix='").append(fileNamePrefix).append('\''); | ||
sb.append(", authorizationToken='").append(authorizationToken).append('\''); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters