diff --git a/README.md b/README.md
index 723c854..3ed29a0 100644
--- a/README.md
+++ b/README.md
@@ -103,7 +103,7 @@ see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blo
B2ApiClient()
// authenticate the client
-authorize(String, String)
+authenticate(String, String)
// create a bucket
createBucket(String, BucketType)
@@ -480,9 +480,9 @@ repositories {
```
dependencies {
- runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.0', ext: 'jar')
+ runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
- compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.0', ext: 'jar')
+ compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
}
```
@@ -494,9 +494,9 @@ or, more simply for versions of gradle greater than 2.1
```
dependencies {
- runtime 'synapticloop:backblaze-b2-java-api:2.1.0'
+ runtime 'synapticloop:backblaze-b2-java-api:2.1.1'
- compile 'synapticloop:backblaze-b2-java-api:2.1.0'
+ compile 'synapticloop:backblaze-b2-java-api:2.1.1'
}
```
@@ -514,7 +514,7 @@ dependencies {
Lifecycle rules instruct the B2 service to automatically hide and/or delete + * old files. You can set up rules to do things like delete old versions of + * files 30 days after a newer version was uploaded.
+ * + *A bucket can have up to 100 lifecycle rules. Each rule has a fileNamePrefix + * that specifies which files in the bucket it applies to. Any file whose name + * starts with the prefix is subject to the rule. A prefix of the empty string, + * "", means that the rule applies to all files in the bucket.
+ * + *You're not allowed to create two rules that both apply to the same files. + * For example, a rule with a file name prefix of photos/ and a rule with a file + * name prefix of photos/kittens/ would both apply to a file named + * photos/kittens/fluffy.jpg, so you're not allowed to have both rules at the + * same time.
+ * + *Each lifecycle rule specifies two things:
+ * + *Either can be null, which means that part of the rule doesn't apply. Setting + * both to null is not allowed, because the rule would do nothing.
+ * + *Setting daysFromUploadingToHiding to 0 is not allowed. When set, it must be a + * positive number.
+ * + *The most commonly used setting is daysFromHidingToDeleting, which says how long + * to keep file versions that are not the current version. A file version counts + * as hidden when explicitly hidden with b2_hide_file, or when a newer file with + * the same name is uploaded. When a rule with this setting applies, the file will + * be deleted the given number of days after it is hidden.
+ * + *For example, if you are backing up your files to B2 using the B2 command-line + * tool, or another software package that uploads files when they change, B2 will + * keep old versions of the file. This is very helpful, because it means the old + * versions are there if the original file is accidentally deleted. On the other + * hand, keeping them forever can clutter things up. For an application like this, + * you might want a lifecycle rule that keeps old versions in the backup/ folder + * for 30 days, and then deletes them:
+ * + *+ { + "daysFromHidingToDeleting": 30, + "daysFromUploadingToHiding": null, + "fileNamePrefix": "backup/" + } + *+ * + *
The daysFromUploadingToHiding setting is less frequently used. It causes files to + * be hidden automatically after the given number of days. This can be useful for things + * like server log files that can be deleted after a while. This rule will keep files + * in the logs/ folder for 7 days, and then hide and immediately delete them:
+ * + *+ { + "daysFromHidingToDeleting": 0, + "daysFromUploadingToHiding": 7, + "fileNamePrefix": "logs/" + } + *+ * + *
The API calls related to lifecycle rules are:
+ * + *When you create a new bucket, you can specify the lifecycle rules. Later, + * you can change the rules on a bucket by updating it.
+ * + * @author synapticloop + * + */ +public class LifecycleRule { + private final Long daysFromHidingToDeleting; + private final Long daysFromUploadingToHiding; + private final String fileNamePrefix; + + public LifecycleRule(Long daysFromHidingToDeleting, Long daysFromUploadingToHiding, String fileNamePrefix) { + this.daysFromHidingToDeleting = daysFromHidingToDeleting; + this.daysFromUploadingToHiding = daysFromUploadingToHiding; + this.fileNamePrefix = fileNamePrefix; + } + + public LifecycleRule(JSONObject jsonObject) { + long hide = jsonObject.optLong("daysFromHidingToDeleting", Long.MIN_VALUE); + if(hide == Long.MIN_VALUE) { + daysFromHidingToDeleting = null; + } else { + daysFromHidingToDeleting = hide; + } + + long upload = jsonObject.optLong("daysFromUploadingToHiding", Long.MIN_VALUE); + if(upload == Long.MIN_VALUE) { + daysFromUploadingToHiding = null; + } else { + daysFromUploadingToHiding = upload; + } + + fileNamePrefix = jsonObject.optString("fileNamePrefix", null); + } + + /** + * The number of days from when the file was hidden to when it will be deleted + * + * @return the number of days from hiding to deleting + */ + public Long getDaysFromHidingToDeleting() { return this.daysFromHidingToDeleting; } + + /** + * The number of days from when the file was uploaded to when it will be deleted + * + * @return the number of days from uploading to deleting + */ + public Long getDaysFromUploadingToHiding() { return this.daysFromUploadingToHiding; } + + /** + * The file name prefix to which this rule applies + * + * @return the file name prefix to which this rule applies + */ + public String getFileNamePrefix() { return this.fileNamePrefix; } + +} diff --git a/src/main/java/synapticloop/b2/request/B2ListFileNamesRequest.java b/src/main/java/synapticloop/b2/request/B2ListFileNamesRequest.java index 97a934a..b8415b2 100644 --- a/src/main/java/synapticloop/b2/request/B2ListFileNamesRequest.java +++ b/src/main/java/synapticloop/b2/request/B2ListFileNamesRequest.java @@ -1,5 +1,7 @@ package synapticloop.b2.request; +import java.io.IOException; + /* * Copyright (c) 2016 Synapticloop. * @@ -19,22 +21,19 @@ 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.B2ListFilesResponse; /** *Lists the names of all files in a bucket, starting at a given name.
- *+ * *
This call returns at most 1000 file names, but it can be called repeatedly to scan through all of the file names in a bucket. Each time you call, it returns an "endFileName" that can be used as the starting point for the next call.
*There may be many file versions for the same name, but this call will return each name only once. If you want all of the versions, use b2_list_file_versions instead.
- *- *
- * This is the interaction class for the b2_list_file_names api calls, this was - * generated from the backblaze api documentation - which can be found here: - *
+ * + *
This is the interaction class for the b2_list_file_names api calls, this was + * generated from the backblaze api documentation - which can be found here:
+ * * http://www.backblaze.com/b2/docs/b2_list_file_names.html * * @author synapticloop diff --git a/src/main/java/synapticloop/b2/response/B2BucketResponse.java b/src/main/java/synapticloop/b2/response/B2BucketResponse.java index 739daca..d20c2f4 100644 --- a/src/main/java/synapticloop/b2/response/B2BucketResponse.java +++ b/src/main/java/synapticloop/b2/response/B2BucketResponse.java @@ -1,5 +1,11 @@ package synapticloop.b2.response; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; + /* * Copyright (c) 2016 Synapticloop. * @@ -21,6 +27,7 @@ import org.slf4j.LoggerFactory; import synapticloop.b2.BucketType; +import synapticloop.b2.LifecycleRule; import synapticloop.b2.exception.B2ApiException; public class B2BucketResponse extends BaseB2Response { @@ -30,6 +37,9 @@ public class B2BucketResponse extends BaseB2Response { private final String accountId; private final String bucketName; private final String bucketType; + private final Long revision; + private final Map