Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Release v0.2
  • Loading branch information
gcurtis committed Sep 29, 2014
2 parents 9a8b394 + 6c75538 commit 4967882
Show file tree
Hide file tree
Showing 29 changed files with 1,888 additions and 145 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
Box Java SDK
============

This SDK provides a Java interface for the [Box REST API](https://developers.box.com/docs/). Features from the [previous version of the Box Java SDK](https://github.com/box/box-java-sdk-v2) are being transitioned to this SDK.
This SDK provides a Java interface for the [Box REST
API](https://developers.box.com/docs/). Features from the [previous version of
the Box Java SDK](https://github.com/box/box-java-sdk-v2) are being transitioned
to this SDK.

Quickstart
----------

Here is a simple example of how to authenticate with the API using a developer token and then print the ID and name of each item in your root folder.
Here is a simple example of how to authenticate with the API using a developer
token and then print the ID and name of each item in your root folder.

```java
BoxAPIConnection api = new BoxAPIConnection("developer-token");
Expand All @@ -20,13 +24,19 @@ for (BoxItem item : rootFolder) {
Building
--------

The SDK uses Gradle for its build system. Running `gradle build` from the root of the repository will compile, lint, and test the SDK.
The SDK uses Gradle for its build system. Running `gradle build` from the root
of the repository will compile, lint, and test the SDK.

```bash
$ gradle build
```

The SDK also includes integration tests which make real API calls, and therefore are run separately from unit tests. Integration tests should be run against a test account since they create and delete data. To run the integration tests, remove the `.template` extension from `src/test/config/config.properties.template` and fill in your test account's information. Then run:
The SDK also includes integration tests which make real API calls, and therefore
are run separately from unit tests. Integration tests should be run against a
test account since they create and delete data. To run the integration tests,
remove the `.template` extension from
`src/test/config/config.properties.template` and fill in your test account's
information. Then run:

```bash
$ gradle integrationTest
Expand All @@ -41,4 +51,7 @@ You can find guides and tutorials in the `doc` directory.
* [Authentication](doc/authentication.md)
* [Events Stream](doc/events.md)

Javadocs are also generated when `gradle build` is run and can be found in `build/doc/javadoc`.
Javadoc reference documentation is [available here][1]. Javadocs are also
generated when `gradle javadoc` is run and can be found in `build/doc/javadoc`.

[1]:https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/package-summary.html
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies {
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'com.github.tomakehurst:wiremock:1.47'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.slf4j:slf4j-api:1.7.7'
testCompile 'org.slf4j:slf4j-nop:1.7.7'
}

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -60,3 +62,18 @@ task integrationTest(type: Test) {
includeCategories 'com.box.sdk.IntegrationTest'
}
}

javadoc {
options.windowTitle 'Box Java SDK'
options.noQualifiers 'all'
options.stylesheetFile file('doc/css/javadoc.css')
options.noTree true
options.noIndex true
options.noHelp true
options.noDeprecatedList true
options.noNavBar true
options.docEncoding 'utf-8'
options.charSet 'utf-8'
options.linkSource true
options.links 'http://docs.oracle.com/javase/8/docs/api/'
}
29 changes: 23 additions & 6 deletions doc/authentication.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
Authentication
==============

The Box API uses OAuth2 for authentication, which can be difficult to implement. The SDK makes it easier by providing classes that handle obtaining tokens and automatically refreshing them.
The Box API uses OAuth2 for authentication, which can be difficult to implement.
The SDK makes it easier by providing classes that handle obtaining tokens and
automatically refreshing them.

Ways to Authenticate
--------------------

### Developer Tokens

The fastest way to get started using the API is with developer tokens. A developer token is simply a short-lived access token that cannot be refreshed and can only be used with your own account. Therefore, they're only useful for testing an app and aren't suitable for production. You can obtain a developer token from your application's [developer console](https://cloud.app.box.com/developers/services).
The fastest way to get started using the API is with developer tokens. A
developer token is simply a short-lived access token that cannot be refreshed
and can only be used with your own account. Therefore, they're only useful for
testing an app and aren't suitable for production. You can obtain a developer
token from your application's [developer
console](https://cloud.app.box.com/developers/services).

The following example creates an API connection with a developer token:

Expand All @@ -18,17 +25,24 @@ BoxAPIConnection api = new BoxAPIConnection("YOUR-DEVELOPER-TOKEN");

### Normal Authentication

Using an auth code is the most common way of authenticating with the Box API. Your application must provide a way for the user to login to Box (usually with a browser or web view) in order to obtain an auth code.
Using an auth code is the most common way of authenticating with the Box API.
Your application must provide a way for the user to login to Box (usually with a
browser or web view) in order to obtain an auth code.

After a user logs in and grants your application access to their Box account, they will be redirected to your application's `redirect_uri` which will contain an auth code. This auth code can then be used along with your client ID and client secret to establish an API connection.
After a user logs in and grants your application access to their Box account,
they will be redirected to your application's `redirect_uri` which will contain
an auth code. This auth code can then be used along with your client ID and
client secret to establish an API connection.

```java
BoxAPIConnection api = new BoxAPIConnection("YOUR-CLIENT-ID", "YOUR-CLIENT-SECRET", "YOUR-AUTH-CODE");
```

### Manual Authentication

In certain advanced scenarios, you may want to obtain an access and refresh token yourself through manual calls to the API. In this case, you can create an API connection with the tokens directly.
In certain advanced scenarios, you may want to obtain an access and refresh
token yourself through manual calls to the API. In this case, you can create an
API connection with the tokens directly.

```java
BoxAPIConnection api = new BoxAPIConnection("YOUR-CLIENT-ID", "YOUR-CLIENT-SECRET", "YOUR-ACCESS-TOKEN",
Expand All @@ -38,7 +52,10 @@ BoxAPIConnection api = new BoxAPIConnection("YOUR-CLIENT-ID", "YOUR-CLIENT-SECRE
Auto-Refresh
------------

By default, a `BoxAPIConnection` will automatically refresh the access token if it has expired. To disable auto-refresh, set the connection's refresh token to null. Keep in mind that you will have to manually refresh and update the access token yourself.
By default, a `BoxAPIConnection` will automatically refresh the access token if
it has expired. To disable auto-refresh, set the connection's refresh token to
null. Keep in mind that you will have to manually refresh and update the access
token yourself.

```java
// This connection won't auto-refresh.
Expand Down
Loading

0 comments on commit 4967882

Please sign in to comment.