From 65d8c72b7fe76033d8e194bf8715dfb0ebb138d8 Mon Sep 17 00:00:00 2001 From: synapticloop Date: Sun, 4 Dec 2016 21:41:34 +0000 Subject: [PATCH] updated documentation --- README.md | 292 ++++++++++++++---- build.gradle | 33 +- documentr.json | 13 +- src/docs/usage-001.md | 5 + src/docs/{usage.md => usage-002.md} | 30 +- .../b2/response/BaseB2Response.java | 2 +- .../synapticloop/b2/QuickExampleMain.java | 32 ++ .../b2/request/B2DownloadFileRequestTest.java | 5 +- 8 files changed, 307 insertions(+), 105 deletions(-) create mode 100644 src/docs/usage-001.md rename src/docs/{usage.md => usage-002.md} (73%) create mode 100644 src/test/java/synapticloop/b2/QuickExampleMain.java diff --git a/README.md b/README.md index 4326cdc..723c854 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,108 @@ -[![Build Status](https://travis-ci.org/synapticloop/backblaze-b2-java-api.svg?branch=master)](https://travis-ci.org/synapticloop/backblaze-b2-java-api) [![Download](https://api.bintray.com/packages/synapticloop/maven/backblaze-b2-java-api/images/download.svg)](https://bintray.com/synapticloop/maven/backblaze-b2-java-api/_latestVersion) [![GitHub Release](https://img.shields.io/github/release/synapticloop/backblaze-b2-java-api.svg)](https://github.com/synapticloop/backblaze-b2-java-api/releases) + [![Build Status](https://travis-ci.org/synapticloop/backblaze-b2-java-api.svg?branch=master)](https://travis-ci.org/synapticloop/backblaze-b2-java-api) [![Download](https://api.bintray.com/packages/synapticloop/maven/backblaze-b2-java-api/images/download.svg)](https://bintray.com/synapticloop/maven/backblaze-b2-java-api/_latestVersion) [![GitHub Release](https://img.shields.io/github/release/synapticloop/backblaze-b2-java-api.svg)](https://github.com/synapticloop/backblaze-b2-java-api/releases) -# backblaze-b2-java-api + + + + +# backblaze-b2-java-api [top](#documentr_top) > A java api for the truly excellent backblaze b2 storage service + + + + + + +# Table of Contents [top](#documentr_top) + + + + - [backblaze-b2-java-api](#documentr_heading_0) + - [Table of Contents](#documentr_heading_1) + - [Usage](#documentr_heading_2) + - [Large File Support](#documentr_heading_3) + - [Building the Package](#documentr_heading_4) + - [*NIX/Mac OS X](#documentr_heading_5) + - [Windows](#documentr_heading_6) + - [Running the Tests](#documentr_heading_7) + - [*NIX/Mac OS X](#documentr_heading_8) + - [Windows](#documentr_heading_9) + - [Logging - slf4j](#documentr_heading_10) + - [Log4j](#documentr_heading_11) + - [Artefact Publishing - Github](#documentr_heading_16) + - [Artefact Publishing - Bintray](#documentr_heading_17) + - [maven setup](#documentr_heading_18) + - [gradle setup](#documentr_heading_19) + - [Dependencies - Gradle](#documentr_heading_20) + - [Dependencies - Maven](#documentr_heading_21) + - [Dependencies - Downloads](#documentr_heading_22) + - [License](#documentr_heading_28) + + # Just looking for a GUI? We thoroughly recommend either [cyberduck](https://cyberduck.io/) or [mountainduck](https://mountainduck.io/) which includes this code for the awesome BackBlaze storage service. -# Usage + + + + +# Usage [top](#documentr_top) + + ``` -// required imports -import synapticloop.b2.B2ApiClient; + + +package synapticloop.b2; + +import java.io.File; +import java.io.IOException; + import synapticloop.b2.exception.B2ApiException; -import synapticloop.b2.request.*; -import synapticloop.b2.response.*; +import synapticloop.b2.response.B2BucketResponse; +public class QuickExampleMain { -String b2AccountId = ""; // your b2 account ID -String b2ApplicationKey = ""; // your b2 application Key + public static void main(String[] args) throws B2ApiException, IOException { + String b2AccountId = ""; // your b2 account ID + String b2ApplicationKey = ""; // your b2 application Key -B2ApiClient b2ApiClient = new B2ApiClient(); -b2ApiClient.authorize(b2AccountId, b2ApplicationKey); + try { + B2ApiClient b2ApiClient = new B2ApiClient(); + b2ApiClient.authenticate(b2AccountId, b2ApplicationKey); -// now create a private bucket -B2BucketResponse createPrivateBucket = b2ApiClient.createBucket("super-secret-bucket" , BucketType.ALL_PRIVATE); + // now create a private bucket + B2BucketResponse createPrivateBucket = b2ApiClient.createBucket("super-secret-bucket" , BucketType.allPrivate); -// or a public one -B2BucketResponse createPublicBucket = b2ApiClient.createBucket("everyone-has-access" , BucketType.ALL_PUBLIC); + // or a public one + B2BucketResponse createPublicBucket = b2ApiClient.createBucket("everyone-has-access" , BucketType.allPublic); + + // upload a file + b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File("/tmp/temporary-file.txt")); + } catch(B2ApiException | IOException ex) { + ex.printStackTrace(); + } + } + +} -// upload a file -b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File("/tmp/temporary-file.txt")); ``` + + see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blob/master/src/main/java/synapticloop/b2/B2ApiClient.java) for a complete list of relatively self-explanatory methods. + + ``` // create a new B2ApiClient B2ApiClient() -// authorize the client +// authenticate the client authorize(String, String) // create a bucket @@ -51,9 +111,6 @@ createBucket(String, BucketType) // delete bucket deleteBucket(String) -// delete bucket and all containing files -deleteBucketFully(String) - // delete a version of a file deleteFileVersion(String, String) @@ -108,12 +165,20 @@ uploadFile(String, String, File, String, Map) ``` -## Large File Support + + + + + + +## Large File Support [top](#documentr_top) Large files can range in size from 100MB to 10TB. Each large file must consist of at least 2 parts, and all of the parts except the last one must be at least 100MB in size. The last part must contain at least one byte. + + ``` startLargeFileUpload(String bucketId, String fileName, String mimeType, Map fileInfo) getUploadPartUrl(String fileId) @@ -126,16 +191,30 @@ listUnfinishedLargeFiles(String bucketId, String startFileId, Integer maxFileCou -# Building the Package -## *NIX/Mac OS X + + + + + +# Building the Package [top](#documentr_top) + + + + + +## *NIX/Mac OS X [top](#documentr_top) From the root of the project, simply run `./gradlew build` -## Windows + + + + +## Windows [top](#documentr_top) `./gradlew.bat build` @@ -144,9 +223,17 @@ This will compile and assemble the artefacts into the `build/libs/` directory. Note that this may also run tests (if applicable see the Testing notes) -# Running the Tests -## *NIX/Mac OS X + + + +# Running the Tests [top](#documentr_top) + + + + + +## *NIX/Mac OS X [top](#documentr_top) From the root of the project, simply run @@ -156,7 +243,11 @@ if you do not have gradle installed, try: `gradlew --info test` -## Windows + + + + +## Windows [top](#documentr_top) From the root of the project, simply run @@ -177,22 +268,36 @@ The `--info` switch will also output logging for the tests You **MUST** have the following environment variables set: + + ``` export B2_ACCOUNT_ID="your-account-id" export B2_APPLICATION_KEY="your-application-key" ``` -# Logging - slf4j + + + + + + +# Logging - slf4j [top](#documentr_top) slf4j is the logging framework used for this project. In order to set up a logging framework with this project, sample configurations are below: -## Log4j + + + + +## Log4j [top](#documentr_top) You will need to include dependencies for this - note that the versions may need to be updated. ### Maven + + ``` org.apache.logging.log4j @@ -210,8 +315,12 @@ You will need to include dependencies for this - note that the versions may need ``` + + ### Gradle < 2.1 + + ``` dependencies { ... @@ -220,8 +329,12 @@ dependencies { ... } ``` + + ### Gradle >= 2.1 + + ``` dependencies { ... @@ -232,10 +345,14 @@ dependencies { ``` + + ### Setting up the logging: A sample `log4j2.xml` is below: + + ``` @@ -251,24 +368,40 @@ A sample `log4j2.xml` is below: ``` -# Artefact Publishing - Github -This project publishes artefacts to [GitHib](https://github.com/) + + + + + +# Artefact Publishing - Github [top](#documentr_top) + +This project publishes artefacts to [GitHub](https://github.com/) > Note that the latest version can be found [https://github.com/synapticloop/backblaze-b2-java-api/releases](https://github.com/synapticloop/backblaze-b2-java-api/releases) As such, this is not a repository, but a location to download files from. -# Artefact Publishing - Bintray + + + + +# Artefact Publishing - Bintray [top](#documentr_top) This project publishes artefacts to [bintray](https://bintray.com/) > Note that the latest version can be found [https://bintray.com/synapticloop/maven/backblaze-b2-java-api/view](https://bintray.com/synapticloop/maven/backblaze-b2-java-api/view) -## maven setup + + + + +## maven setup [top](#documentr_top) this comes from the jcenter bintray, to set up your repository: + + ``` @@ -303,10 +436,18 @@ this comes from the jcenter bintray, to set up your repository: ``` -## gradle setup + + + + + + +## gradle setup [top](#documentr_top) Repository + + ``` repositories { maven { @@ -315,46 +456,76 @@ repositories { } ``` + + or just + + ``` repositories { jcenter() } ``` -## Dependencies - Gradle + + + + + + +## Dependencies - Gradle [top](#documentr_top) + + ``` dependencies { - runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.0.2', ext: 'jar') + runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.0', ext: 'jar') - compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.0.2', ext: 'jar') + compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.0', ext: 'jar') } ``` + + or, more simply for versions of gradle greater than 2.1 + + ``` dependencies { - runtime 'synapticloop:backblaze-b2-java-api:2.0.2' + runtime 'synapticloop:backblaze-b2-java-api:2.1.0' - compile 'synapticloop:backblaze-b2-java-api:2.0.2' + compile 'synapticloop:backblaze-b2-java-api:2.1.0' } ``` -## Dependencies - Maven + + + + + + +## Dependencies - Maven [top](#documentr_top) + + ``` synapticloop backblaze-b2-java-api - 2.0.2 + 2.1.0 jar ``` -## Dependencies - Downloads + + + + + + +## Dependencies - Downloads [top](#documentr_top) You will also need to download the following dependencies: @@ -368,38 +539,44 @@ You will also need to download the following dependencies: ### compile dependencies - - org.apache.httpcomponents:httpclient:4.5.1: (It may be available on one of: [bintray](https://bintray.com/org.apache.httpcomponents/maven/httpclient/4.5.1/view#files/org.apache.httpcomponents/httpclient/4.5.1) [mvn central](http://search.maven.org/#artifactdetails|org.apache.httpcomponents|httpclient|4.5.1|jar)) - - commons-io:commons-io:2.4: (It may be available on one of: [bintray](https://bintray.com/commons-io/maven/commons-io/2.4/view#files/commons-io/commons-io/2.4) [mvn central](http://search.maven.org/#artifactdetails|commons-io|commons-io|2.4|jar)) - - org.json:json:20160212: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160212/view#files/org.json/json/20160212) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160212|jar)) + - org.apache.httpcomponents:httpclient:4.5.2: (It may be available on one of: [bintray](https://bintray.com/org.apache.httpcomponents/maven/httpclient/4.5.2/view#files/org.apache.httpcomponents/httpclient/4.5.2) [mvn central](http://search.maven.org/#artifactdetails|org.apache.httpcomponents|httpclient|4.5.2|jar)) + - commons-io:commons-io:2.5: (It may be available on one of: [bintray](https://bintray.com/commons-io/maven/commons-io/2.5/view#files/commons-io/commons-io/2.5) [mvn central](http://search.maven.org/#artifactdetails|commons-io|commons-io|2.5|jar)) + - org.json:json:20160810: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160810/view#files/org.json/json/20160810) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160810|jar)) - org.slf4j:slf4j-api:1.7.13: (It may be available on one of: [bintray](https://bintray.com/org.slf4j/maven/slf4j-api/1.7.13/view#files/org.slf4j/slf4j-api/1.7.13) [mvn central](http://search.maven.org/#artifactdetails|org.slf4j|slf4j-api|1.7.13|jar)) ### runtime dependencies - - org.apache.httpcomponents:httpclient:4.5.1: (It may be available on one of: [bintray](https://bintray.com/org.apache.httpcomponents/maven/httpclient/4.5.1/view#files/org.apache.httpcomponents/httpclient/4.5.1) [mvn central](http://search.maven.org/#artifactdetails|org.apache.httpcomponents|httpclient|4.5.1|jar)) - - commons-io:commons-io:2.4: (It may be available on one of: [bintray](https://bintray.com/commons-io/maven/commons-io/2.4/view#files/commons-io/commons-io/2.4) [mvn central](http://search.maven.org/#artifactdetails|commons-io|commons-io|2.4|jar)) - - org.json:json:20160212: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160212/view#files/org.json/json/20160212) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160212|jar)) + - org.apache.httpcomponents:httpclient:4.5.2: (It may be available on one of: [bintray](https://bintray.com/org.apache.httpcomponents/maven/httpclient/4.5.2/view#files/org.apache.httpcomponents/httpclient/4.5.2) [mvn central](http://search.maven.org/#artifactdetails|org.apache.httpcomponents|httpclient|4.5.2|jar)) + - commons-io:commons-io:2.5: (It may be available on one of: [bintray](https://bintray.com/commons-io/maven/commons-io/2.5/view#files/commons-io/commons-io/2.5) [mvn central](http://search.maven.org/#artifactdetails|commons-io|commons-io|2.5|jar)) + - org.json:json:20160810: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160810/view#files/org.json/json/20160810) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160810|jar)) - org.slf4j:slf4j-api:1.7.13: (It may be available on one of: [bintray](https://bintray.com/org.slf4j/maven/slf4j-api/1.7.13/view#files/org.slf4j/slf4j-api/1.7.13) [mvn central](http://search.maven.org/#artifactdetails|org.slf4j|slf4j-api|1.7.13|jar)) ### testCompile dependencies - junit:junit:4.12: (It may be available on one of: [bintray](https://bintray.com/junit/maven/junit/4.12/view#files/junit/junit/4.12) [mvn central](http://search.maven.org/#artifactdetails|junit|junit|4.12|jar)) - - org.apache.logging.log4j:log4j-slf4j-impl:2.5: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-slf4j-impl/2.5/view#files/org.apache.logging.log4j/log4j-slf4j-impl/2.5) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-slf4j-impl|2.5|jar)) - - org.apache.logging.log4j:log4j-core:2.5: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-core/2.5/view#files/org.apache.logging.log4j/log4j-core/2.5) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-core|2.5|jar)) - - org.json:json:20160212: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160212/view#files/org.json/json/20160212) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160212|jar)) + - org.apache.logging.log4j:log4j-slf4j-impl:2.7: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-slf4j-impl/2.7/view#files/org.apache.logging.log4j/log4j-slf4j-impl/2.7) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-slf4j-impl|2.7|jar)) + - org.apache.logging.log4j:log4j-core:2.7: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-core/2.7/view#files/org.apache.logging.log4j/log4j-core/2.7) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-core|2.7|jar)) + - org.json:json:20160810: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160810/view#files/org.json/json/20160810) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160810|jar)) ### testRuntime dependencies - junit:junit:4.12: (It may be available on one of: [bintray](https://bintray.com/junit/maven/junit/4.12/view#files/junit/junit/4.12) [mvn central](http://search.maven.org/#artifactdetails|junit|junit|4.12|jar)) - - org.apache.logging.log4j:log4j-slf4j-impl:2.5: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-slf4j-impl/2.5/view#files/org.apache.logging.log4j/log4j-slf4j-impl/2.5) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-slf4j-impl|2.5|jar)) - - org.apache.logging.log4j:log4j-core:2.5: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-core/2.5/view#files/org.apache.logging.log4j/log4j-core/2.5) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-core|2.5|jar)) - - org.json:json:20160212: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160212/view#files/org.json/json/20160212) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160212|jar)) + - org.apache.logging.log4j:log4j-slf4j-impl:2.7: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-slf4j-impl/2.7/view#files/org.apache.logging.log4j/log4j-slf4j-impl/2.7) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-slf4j-impl|2.7|jar)) + - org.apache.logging.log4j:log4j-core:2.7: (It may be available on one of: [bintray](https://bintray.com/org.apache.logging.log4j/maven/log4j-core/2.7/view#files/org.apache.logging.log4j/log4j-core/2.7) [mvn central](http://search.maven.org/#artifactdetails|org.apache.logging.log4j|log4j-core|2.7|jar)) + - org.json:json:20160810: (It may be available on one of: [bintray](https://bintray.com/org.json/maven/json/20160810/view#files/org.json/json/20160810) [mvn central](http://search.maven.org/#artifactdetails|org.json|json|20160810|jar)) **NOTE:** You may need to download any dependencies of the above dependencies in turn (i.e. the transitive dependencies) -# License + + + + +# License [top](#documentr_top) + + ``` The MIT License (MIT) @@ -426,9 +603,10 @@ SOFTWARE. ``` + + -- > `This README.md file was hand-crafted with care utilising synapticloop`[`templar`](https://github.com/synapticloop/templar/)`->`[`documentr`](https://github.com/synapticloop/documentr/) -- - diff --git a/build.gradle b/build.gradle index ea42e56..267652e 100644 --- a/build.gradle +++ b/build.gradle @@ -3,17 +3,18 @@ plugins { id 'eclipse' id "maven" id "maven-publish" - id 'net.saliman.cobertura' version '2.3.0' - id "com.jfrog.bintray" version "1.6" + id 'net.saliman.cobertura' version '2.3.2' + id "com.jfrog.bintray" version "1.7" id 'co.riiid.gradle' version '0.4.2' - id 'synapticloop.documentr' version '1.3.4' + id 'synapticloop.documentr' version '2.6.1' + id 'com.github.ben-manes.versions' version '0.13.0' } group = 'synapticloop' archivesBaseName = 'backblaze-b2-java-api' description = """A java api for the truly excellent backblaze b2 storage service""" -version = '2.0.2' +version = '2.1.0' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -27,25 +28,25 @@ repositories { } dependencies { - runtime 'org.apache.httpcomponents:httpclient:4.5.1' - runtime 'commons-io:commons-io:2.4' - runtime 'org.json:json:20160212' + runtime 'org.apache.httpcomponents:httpclient:4.5.2' + runtime 'commons-io:commons-io:2.5' + runtime 'org.json:json:20160810' runtime 'org.slf4j:slf4j-api:1.7.13' - compile 'org.apache.httpcomponents:httpclient:4.5.1' - compile 'commons-io:commons-io:2.4' - compile 'org.json:json:20160212' + compile 'org.apache.httpcomponents:httpclient:4.5.2' + compile 'commons-io:commons-io:2.5' + compile 'org.json:json:20160810' compile 'org.slf4j:slf4j-api:1.7.13' testCompile 'junit:junit:4.12' - testCompile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5' - testCompile 'org.apache.logging.log4j:log4j-core:2.5' - testCompile 'org.json:json:20160212' + testCompile 'org.apache.logging.log4j:log4j-slf4j-impl:2.7' + testCompile 'org.apache.logging.log4j:log4j-core:2.7' + testCompile 'org.json:json:20160810' testRuntime 'junit:junit:4.12' - testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5' - testRuntime 'org.apache.logging.log4j:log4j-core:2.5' - testRuntime 'org.json:json:20160212' + testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.7' + testRuntime 'org.apache.logging.log4j:log4j-core:2.7' + testRuntime 'org.json:json:20160810' } configurations.all { diff --git a/documentr.json b/documentr.json index 4fc57dd..d366c6a 100644 --- a/documentr.json +++ b/documentr.json @@ -10,9 +10,20 @@ { "type":"inbuilt", "value":"project-name" }, { "type":"inbuilt", "value":"project-description" }, + { "type": "markup", "value": "\n\n# Table of Contents\n\n" }, + + { "type": "toc", "value": "2" }, + { "type": "toclinks", "value": "true" }, + { "type": "toplink", "value": " " }, + { "type": "tocbacktotop", "value": " [top](#documentr_top)" }, + { "type":"file", "value":"src/docs/gui.md" }, - { "type":"file", "value":"src/docs/usage.md" }, + { "type":"file", "value":"src/docs/usage-001.md" }, + + { "type":"file", "value":"src/test/java/synapticloop/b2/QuickExampleMain.java" }, + + { "type":"file", "value":"src/docs/usage-002.md" }, { "type":"inbuilt", "value":"gradle-build" }, { "type":"inbuilt", "value":"gradle-test" }, diff --git a/src/docs/usage-001.md b/src/docs/usage-001.md new file mode 100644 index 0000000..31e5b60 --- /dev/null +++ b/src/docs/usage-001.md @@ -0,0 +1,5 @@ +# Usage + +``` + + diff --git a/src/docs/usage.md b/src/docs/usage-002.md similarity index 73% rename from src/docs/usage.md rename to src/docs/usage-002.md index 6566daf..039ae66 100644 --- a/src/docs/usage.md +++ b/src/docs/usage-002.md @@ -1,27 +1,4 @@ -# Usage -``` -// required imports -import synapticloop.b2.B2ApiClient; -import synapticloop.b2.exception.B2ApiException; -import synapticloop.b2.request.*; -import synapticloop.b2.response.*; - - -String b2AccountId = ""; // your b2 account ID -String b2ApplicationKey = ""; // your b2 application Key - -B2ApiClient b2ApiClient = new B2ApiClient(); -b2ApiClient.authorize(b2AccountId, b2ApplicationKey); - -// now create a private bucket -B2BucketResponse createPrivateBucket = b2ApiClient.createBucket("super-secret-bucket" , BucketType.ALL_PRIVATE); - -// or a public one -B2BucketResponse createPublicBucket = b2ApiClient.createBucket("everyone-has-access" , BucketType.ALL_PUBLIC); - -// upload a file -b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File("/tmp/temporary-file.txt")); ``` see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blob/master/src/main/java/synapticloop/b2/B2ApiClient.java) for a complete list of relatively self-explanatory methods. @@ -30,8 +7,8 @@ see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blo // create a new B2ApiClient B2ApiClient() -// authorize the client -authorize(String, String) +// authenticate the client +authenticate(String, String) // create a bucket createBucket(String, BucketType) @@ -39,9 +16,6 @@ createBucket(String, BucketType) // delete bucket deleteBucket(String) -// delete bucket and all containing files -deleteBucketFully(String) - // delete a version of a file deleteFileVersion(String, String) diff --git a/src/main/java/synapticloop/b2/response/BaseB2Response.java b/src/main/java/synapticloop/b2/response/BaseB2Response.java index b84ebc2..ac9ccc9 100644 --- a/src/main/java/synapticloop/b2/response/BaseB2Response.java +++ b/src/main/java/synapticloop/b2/response/BaseB2Response.java @@ -34,7 +34,7 @@ public abstract class BaseB2Response { * Create a new B2 Response object by parsing the passed in String * * @param json the Response (in json format) - * @throws B2ApiException if there was an error in the parsing of the reponse + * @throws B2ApiException if there was an error in the parsing of the response */ public BaseB2Response(final String json) throws B2ApiException { this(parse(json)); diff --git a/src/test/java/synapticloop/b2/QuickExampleMain.java b/src/test/java/synapticloop/b2/QuickExampleMain.java new file mode 100644 index 0000000..06e6390 --- /dev/null +++ b/src/test/java/synapticloop/b2/QuickExampleMain.java @@ -0,0 +1,32 @@ +package synapticloop.b2; + +import java.io.File; +import java.io.IOException; + +import synapticloop.b2.exception.B2ApiException; +import synapticloop.b2.response.B2BucketResponse; + +public class QuickExampleMain { + + public static void main(String[] args) throws B2ApiException, IOException { + String b2AccountId = ""; // your b2 account ID + String b2ApplicationKey = ""; // your b2 application Key + + try { + B2ApiClient b2ApiClient = new B2ApiClient(); + b2ApiClient.authenticate(b2AccountId, b2ApplicationKey); + + // now create a private bucket + B2BucketResponse createPrivateBucket = b2ApiClient.createBucket("super-secret-bucket" , BucketType.allPrivate); + + // or a public one + B2BucketResponse createPublicBucket = b2ApiClient.createBucket("everyone-has-access" , BucketType.allPublic); + + // upload a file + b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File("/tmp/temporary-file.txt")); + } catch(B2ApiException | IOException ex) { + ex.printStackTrace(); + } + } + +} diff --git a/src/test/java/synapticloop/b2/request/B2DownloadFileRequestTest.java b/src/test/java/synapticloop/b2/request/B2DownloadFileRequestTest.java index 8500799..7fabad2 100644 --- a/src/test/java/synapticloop/b2/request/B2DownloadFileRequestTest.java +++ b/src/test/java/synapticloop/b2/request/B2DownloadFileRequestTest.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileWriter; +import java.nio.charset.Charset; import org.apache.commons.io.IOUtils; import org.apache.http.impl.client.HttpClients; @@ -64,10 +65,10 @@ public void testDownloadFileBy() throws Exception { b2FileResponse = B2TestHelper.uploadTemporaryFileToBucket(randomPrivateBucket.getBucketId()); B2DownloadFileResponse b2DownloadFileResponse = new B2DownloadFileByNameRequest(HttpClients.createDefault(), B2TestHelper.getB2AuthorizeAccountResponse(), randomPrivateBucket.getBucketName(), b2FileResponse.getFileName()).getResponse(); - assertEquals(B2TestHelper.DUMMY_FILE_CONTENT, IOUtils.toString(b2DownloadFileResponse.getContent())); + assertEquals(B2TestHelper.DUMMY_FILE_CONTENT, IOUtils.toString(b2DownloadFileResponse.getContent(), Charset.defaultCharset())); b2DownloadFileResponse = new B2DownloadFileByIdRequest(HttpClients.createDefault(), B2TestHelper.getB2AuthorizeAccountResponse(), b2FileResponse.getFileId()).getResponse(); - assertEquals(B2TestHelper.DUMMY_FILE_CONTENT, IOUtils.toString(b2DownloadFileResponse.getContent())); + assertEquals(B2TestHelper.DUMMY_FILE_CONTENT, IOUtils.toString(b2DownloadFileResponse.getContent(), Charset.defaultCharset())); B2TestHelper.deleteFile(b2FileResponse.getFileName(), b2FileResponse.getFileId()); B2TestHelper.deleteBucket(randomPrivateBucket.getBucketId());