-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create a Java ONLY example to ensure that the Kotlin Dependency isn't required for non-android usage. * Dependency Guard
- Loading branch information
1 parent
7639bd5
commit d45dd9e
Showing
10 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
id("java") | ||
id("com.dropbox.dependency-guard") | ||
} | ||
|
||
dependencyGuard { | ||
configuration("compileClasspath") | ||
configuration("runtimeClasspath") | ||
} | ||
|
||
description = 'Java Examples' | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
dependencies { | ||
implementation(project(":dropbox-sdk-java")) | ||
|
||
testImplementation(dropboxJavaSdkLibs.test.junit) | ||
} | ||
|
||
test { | ||
// Uses the "ci" gradle property and sets it as an environment variable for the test | ||
environment("ci", project.findProperty("ci")) | ||
|
||
// Ensure that tests are always run because integration tests are non-deterministic | ||
outputs.upToDateWhen { false } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.fasterxml.jackson.core:jackson-core:2.7.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.fasterxml.jackson.core:jackson-core:2.7.9 |
43 changes: 43 additions & 0 deletions
43
examples/java/src/main/java/com/dropbox/core/examples/CredentialsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.dropbox.core.examples; | ||
|
||
import com.dropbox.core.DbxAuthInfo; | ||
import com.dropbox.core.json.JsonReader; | ||
import com.dropbox.core.oauth.DbxCredential; | ||
|
||
import java.io.File; | ||
|
||
public final class CredentialsUtil { | ||
/** | ||
* JSON file that is generated at auth_output when the ./generate-ci-auth-file script is run | ||
* with the required parameters. This is read in CI during integration tests. | ||
*/ | ||
public static final File authOutputFile = new File("../../auth_output"); | ||
|
||
public static DbxCredential getDbxCredential() { | ||
try { | ||
return DbxCredential.Reader.readFromFile(authOutputFile); | ||
} catch (JsonReader.FileLoadException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public final DbxAuthInfo getAuthInfo() { | ||
try { | ||
return DbxAuthInfo.Reader.readFromFile(authOutputFile); | ||
} catch (JsonReader.FileLoadException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static final class OAuth2TokenInputs { | ||
public final String appKey; | ||
public final String appSecret; | ||
public final String refreshToken; | ||
|
||
public OAuth2TokenInputs(String appKey, String appSecret, String refreshToken) { | ||
this.appKey = appKey; | ||
this.appSecret = appSecret; | ||
this.refreshToken = refreshToken; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/java/src/main/java/com/dropbox/core/examples/account_info/AccountInfoExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dropbox.core.examples.account_info; | ||
|
||
import com.dropbox.core.DbxException; | ||
import com.dropbox.core.DbxRequestConfig; | ||
import com.dropbox.core.examples.CredentialsUtil; | ||
import com.dropbox.core.oauth.DbxCredential; | ||
import com.dropbox.core.v2.DbxClientV2; | ||
import com.dropbox.core.v2.users.FullAccount; | ||
|
||
|
||
public final class AccountInfoExample { | ||
|
||
public static void main(String[] args) { | ||
DbxCredential credential = CredentialsUtil.getDbxCredential(); | ||
new AccountInfoExample().runExample(credential); | ||
} | ||
|
||
public void runExample(DbxCredential credential) { | ||
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-account-info"); | ||
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, credential); | ||
|
||
try { | ||
FullAccount dbxAccountInfo = dbxClient.users().getCurrentAccount(); | ||
System.out.println(dbxAccountInfo.toStringMultiline()); | ||
} catch (DbxException ex) { | ||
throw new RuntimeException("Error making API call: " + ex.getMessage()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...les/java/src/test/java/com/dropbox/core/examples/account_info/AccountInfoExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.dropbox.core.examples.account_info; | ||
|
||
import static org.junit.Assume.assumeTrue; | ||
|
||
import com.dropbox.core.examples.CredentialsUtil; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class AccountInfoExampleTest { | ||
|
||
@Before | ||
public void setup() { | ||
// Only run if this is running in CI | ||
Boolean isRunningInCI = System.getenv("ci").equals("true"); | ||
assumeTrue(isRunningInCI); | ||
} | ||
|
||
@Test | ||
public void accountInfo() { | ||
new AccountInfoExample().runExample(CredentialsUtil.getDbxCredential()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters