Skip to content

Commit

Permalink
Switch requests to use GET method when possible.
Browse files Browse the repository at this point in the history
> This API request is now being described as a GET request and not a POST request, as was the case in previous versions of our documentation.

  We made this update because we believe that an API call that retrieves data and does not alter state is more accurately represented as a GET request.
  • Loading branch information
dkocher committed Mar 13, 2024
1 parent f4cb9cf commit 34bcb22
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class B2GetFileInfoRequest extends BaseB2Request {
public B2GetFileInfoRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String fileId) {
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_GET_FILE_INFO);

this.addProperty(B2RequestProperties.KEY_FILE_ID, fileId);
this.addParameter(B2RequestProperties.KEY_FILE_ID, fileId);
}

/**
Expand All @@ -64,6 +64,6 @@ public B2GetFileInfoRequest(CloseableHttpClient client, B2AuthorizeAccountRespon
* @throws IOException if there was an error communicating with the API service
*/
public B2FileResponse getResponse() throws B2ApiException, IOException {
return new B2FileResponse(EntityUtils.toString(executePost().getEntity()));
return new B2FileResponse(EntityUtils.toString(executeGet().getEntity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResp
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId, String startFileName, Integer maxFileCount, String prefix, String delimiter) {
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_NAMES);

this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
this.addParameter(B2RequestProperties.KEY_BUCKET_ID, bucketId);

if(null != startFileName) {
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
this.addParameter(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
}
if(null != prefix) {
this.addProperty(B2RequestProperties.KEY_PREFIX, prefix);
this.addParameter(B2RequestProperties.KEY_PREFIX, prefix);
}
if(null != delimiter) {
this.addProperty(B2RequestProperties.KEY_DELIMITER, delimiter);
this.addParameter(B2RequestProperties.KEY_DELIMITER, delimiter);
}

this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
this.addParameter(B2RequestProperties.KEY_MAX_FILE_COUNT, String.valueOf(maxFileCount));
}

/**
Expand All @@ -107,6 +107,6 @@ public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResp
* @throws IOException if there was an error communicating with the API service
*/
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
return new B2ListFilesResponse(EntityUtils.toString(executeGet().getEntity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountR
String prefix, String delimiter) {
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_VERSIONS);

this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
this.addParameter(B2RequestProperties.KEY_BUCKET_ID, bucketId);
this.addParameter(B2RequestProperties.KEY_MAX_FILE_COUNT, String.valueOf(maxFileCount));
if(null != startFileName) {
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
this.addParameter(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
}
if(null != startFileId) {
this.addProperty(B2RequestProperties.KEY_START_FILE_ID, startFileId);
this.addParameter(B2RequestProperties.KEY_START_FILE_ID, startFileId);
}
if(null != prefix) {
this.addProperty(B2RequestProperties.KEY_PREFIX, prefix);
this.addParameter(B2RequestProperties.KEY_PREFIX, prefix);
}
if(null != delimiter) {
this.addProperty(B2RequestProperties.KEY_DELIMITER, delimiter);
this.addParameter(B2RequestProperties.KEY_DELIMITER, delimiter);
}
}

Expand All @@ -116,6 +116,6 @@ public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountR
* @throws IOException if there was an error communicating with the API service
*/
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
return new B2ListFilesResponse(EntityUtils.toString(executeGet().getEntity()));
}
}
8 changes: 4 additions & 4 deletions src/main/java/synapticloop/b2/request/B2ListPartsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public B2ListPartsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse
String fileId, Integer startPartNumber, Integer maxPartCount) {
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_PARTS);

this.addProperty(B2RequestProperties.KEY_FILE_ID, fileId);
this.addParameter(B2RequestProperties.KEY_FILE_ID, fileId);
if (startPartNumber != null) {
this.addProperty(B2RequestProperties.KEY_START_PART_NUMBER, startPartNumber);
this.addParameter(B2RequestProperties.KEY_START_PART_NUMBER, String.valueOf(startPartNumber));
}
if (startPartNumber != null) {
this.addProperty(B2RequestProperties.KEY_MAX_PART_COUNT, maxPartCount);
this.addParameter(B2RequestProperties.KEY_MAX_PART_COUNT, String.valueOf(maxPartCount));
}
}

public B2ListPartsResponse getResponse() throws B2ApiException, IOException {
return new B2ListPartsResponse(EntityUtils.toString(executePost().getEntity()));
return new B2ListPartsResponse(EntityUtils.toString(executeGet().getEntity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public B2ListUnfinishedLargeFilesRequest(CloseableHttpClient client, B2Authorize
String bucketId, String startFileId, Integer maxFileCount) {
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_UNFINISHED_LARGE_FILES);

this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
this.addParameter(B2RequestProperties.KEY_BUCKET_ID, bucketId);
if (null != startFileId) {
this.addProperty(B2RequestProperties.KEY_START_FILE_ID, startFileId);
this.addParameter(B2RequestProperties.KEY_START_FILE_ID, startFileId);
}
if (maxFileCount != null) {
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
this.addParameter(B2RequestProperties.KEY_MAX_FILE_COUNT, String.valueOf(maxFileCount));
}
}

public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
return new B2ListFilesResponse(EntityUtils.toString(executeGet().getEntity()));
}
}

0 comments on commit 34bcb22

Please sign in to comment.