Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
added in missing fields that weren't being picked up
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Dec 4, 2016
1 parent 6e7e455 commit 3fa604b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 27 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ repositories {

```
dependencies {
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.2', ext: 'jar')
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.2', ext: 'jar')
}
```

Expand All @@ -494,9 +494,9 @@ or, more simply for versions of gradle greater than 2.1

```
dependencies {
runtime 'synapticloop:backblaze-b2-java-api:2.1.1'
runtime 'synapticloop:backblaze-b2-java-api:2.1.2'
compile 'synapticloop:backblaze-b2-java-api:2.1.1'
compile 'synapticloop:backblaze-b2-java-api:2.1.2'
}
```

Expand All @@ -514,7 +514,7 @@ dependencies {
<dependency>
<groupId>synapticloop</groupId>
<artifactId>backblaze-b2-java-api</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<type>jar</type>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ group = 'synapticloop'
archivesBaseName = 'backblaze-b2-java-api'
description = """A java api for the truly excellent backblaze b2 storage service"""

version = '2.1.1'
version = '2.1.2'

sourceCompatibility = 1.7
targetCompatibility = 1.7
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/synapticloop/b2/request/BaseB2Request.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package synapticloop.b2.request;

import static org.apache.http.entity.ContentType.*;

/*
* Copyright (c) 2016 Synapticloop.
*
Expand All @@ -18,6 +16,8 @@
* this source code or binaries.
*/

import static org.apache.http.entity.ContentType.*;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -46,8 +46,6 @@
import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.response.B2AuthorizeAccountResponse;

import static org.apache.http.entity.ContentType.APPLICATION_JSON;

public abstract class BaseB2Request {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Request.class);

Expand Down Expand Up @@ -353,7 +351,7 @@ protected CloseableHttpResponse execute(final HttpUriRequest request) throws IOE
*/
private Object obfuscateData(String key, Object data) {
if(LOGGER.isDebugEnabled()) {
if("accountId".equals(key)) {
if(B2RequestProperties.KEY_ACCOUNT_ID.equals(key)) {
return("[redacted]");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class B2DownloadFileResponse {
private final String contentSha1;
private final String uploadTimestamp;

private final Map<String, String> fileInfo = new HashMap<>();
private final Map<String, String> fileInfo = new HashMap<String, String>();

/**
* Instantiate a bucket response with the JSON response as a string from
Expand Down
46 changes: 33 additions & 13 deletions src/main/java/synapticloop/b2/response/B2FileInfoResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class B2FileInfoResponse extends BaseB2Response {
private final String contentType;
private final String contentSha1;
private final Long contentLength;
private final String accountId;
private final String bucketId;

private final Map<String, String> fileInfo;
private Action action;
Expand Down Expand Up @@ -68,6 +70,8 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {

this.size = this.readLong(B2ResponseProperties.KEY_SIZE);
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);
this.accountId = this.readString(B2ResponseProperties.KEY_ACCOUNT_ID);
this.bucketId = this.readString(B2ResponseProperties.KEY_BUCKET_ID);

this.warnOnMissedKeys();
}
Expand Down Expand Up @@ -105,14 +109,14 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
* @return the sha1 has of the content
*/
public String getContentSha1() { return this.contentSha1; }

/**
* Get the file info for the downloaded file - which is a map of key value
* pairs with both the key and value being strings
*
* @return the file info map of key:value strings
*/

public Map<String, String> getFileInfo() { return this.fileInfo; }

/**
Expand All @@ -134,21 +138,37 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
*/
public Long getUploadTimestamp() { return this.uploadTimestamp; }

/**
* Return the account ID used to authorize this account
*
* @return the account ID
*/
public String getAccountId() { return this.accountId; }

/**
* Return the bucket ID that this file belongs in
*
* @return the bucket ID
*/
public String getBucketId() { return this.bucketId; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2FileInfoResponse{");
sb.append("fileId='").append(fileId).append('\'');
sb.append(", fileName='").append(fileName).append('\'');
sb.append(", contentLength=").append(contentLength);
sb.append(", contentType=").append(contentType);
sb.append(", contentSha1='").append(contentSha1).append('\'');
sb.append(", fileInfo=").append(fileInfo);
sb.append(", size=").append(size);
sb.append(", uploadTimestamp=").append(uploadTimestamp);
sb.append('}');
return sb.toString();
return "B2FileInfoResponse " +
"[fileId=" + this.fileId +
", fileName=" + this.fileName +
", contentType=" + this.contentType +
", contentSha1=" + this.contentSha1 +
", contentLength=" + this.contentLength +
", accountId=" + this.accountId +
", bucketId=" + this.bucketId +
", fileInfo=" + this.fileInfo +
", action=" + this.action +
", size=" + this.size +
", uploadTimestamp=" + this.uploadTimestamp +
"]";
}
}
42 changes: 41 additions & 1 deletion src/main/java/synapticloop/b2/response/B2HideFileResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package synapticloop.b2.response;

import java.util.Map;

/*
* Copyright (c) 2016 Synapticloop.
*
Expand Down Expand Up @@ -31,7 +33,12 @@ public class B2HideFileResponse extends BaseB2Response {
private final Integer size;
private final Long uploadTimestamp;

/**
private final Long contentLength;
private final String contentType;
private final String contentSha1;
private final Map<String, String> fileInfo;

/**
* Instantiate a hide file response with the JSON response as a string from
* the API call. This response is then parsed into the relevant fields.
*
Expand Down Expand Up @@ -60,6 +67,10 @@ public B2HideFileResponse(String json) throws B2ApiException {

this.size = this.readInt(B2ResponseProperties.KEY_SIZE);
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);
this.contentLength = this.readLong(B2ResponseProperties.KEY_CONTENT_LENGTH);
this.contentType =this.readString(B2ResponseProperties.KEY_CONTENT_TYPE);
this.contentSha1 =this.readString(B2ResponseProperties.KEY_CONTENT_SHA1);
this.fileInfo = this.readMap(B2ResponseProperties.KEY_FILE_INFO);

this.warnOnMissedKeys();
}
Expand Down Expand Up @@ -88,4 +99,33 @@ public String toString() {
return sb.toString();
}

/**
* Get the content length of the downloaded file
*
* @return the length of the content
*/
public Long getContentLength() { return this.contentLength; }

/**
* Get the content type of the downloaded file
*
* @return the content type of the downloaded file
*/
public String getContentType() { return this.contentType; }

/**
* Get the SHA1 of the returned content
*
* @return the SHA1 of the returned content
*/
public String getContentSha1() { return this.contentSha1; }

/**
* Get the file info for the file, this will be returned in the map as
* key(tag), value (super-secret-tag)
*
* @return The map of the file info
*/
public Map<String, String> getFileInfo() { return this.fileInfo; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class B2StartLargeFileResponse extends BaseB2Response {
private final String accountId;
private final String bucketId;
private final String contentType;
private final String uploadTimestamp;

private final Map<String, String> fileInfo;

public B2StartLargeFileResponse(String json) throws B2ApiException {
Expand All @@ -43,6 +45,7 @@ public B2StartLargeFileResponse(String json) throws B2ApiException {
this.bucketId = this.readString(B2ResponseProperties.KEY_BUCKET_ID);
this.contentType = this.readString(B2ResponseProperties.KEY_CONTENT_TYPE);
this.fileInfo = this.readMap(B2ResponseProperties.KEY_FILE_INFO);
this.uploadTimestamp = this.readString(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);

this.warnOnMissedKeys();
}
Expand All @@ -57,6 +60,13 @@ public B2StartLargeFileResponse(String json) throws B2ApiException {

public String getContentType() { return this.contentType; }

/**
* Get the upload timestamp of the file
*
* @return the upload timestamp of the file
*/
public String getUploadTimestamp() { return this.uploadTimestamp; }

public Map<String, String> getFileInfo() { return this.fileInfo; }

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/synapticloop/b2/response/BaseB2Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ protected void warnOnMissedKeys() {
Iterator keys = response.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, response.get(key));
if(B2ResponseProperties.KEY_ACCOUNT_ID.equals(key)) {
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, "[redacted]");
} else {
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, response.get(key));
}
}
}
}
Expand Down

0 comments on commit 3fa604b

Please sign in to comment.