GeezerVison is showing github.com — simplify async examples to reflect use of new OAuthService unified me… · revant/scribejava@ad79556
File treeExpand file treeCollapse file tree Open diff view settings scribejava-apis/src/test/java/com/github/scribejava/apis/examples scribejava-core/src/main/java/com/github/scribejava/core/oauth
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,7 +73,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 73 | 73 |
| 74 | 74 | // Trade the Request Token and Verfier for the Access Token | 75 | 75 | System.out.println("Trading the Request Token for an Access Token..."); | 76 | | - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); | | 76 | + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); | 77 | 77 | System.out.println("Got the Access Token!"); | 78 | 78 | System.out.println("(if your curious it looks like this: " + accessToken | 79 | 79 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -83,7 +83,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 83 | 83 | System.out.println("Now we're going to access a protected resource..."); | 84 | 84 | final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); | 85 | 85 | service.signRequest(accessToken, request); | 86 | | - final Response response = service.execute(request, null).get(); | | 86 | + final Response response = service.execute(request); | 87 | 87 | System.out.println("Got it! Lets see what we found..."); | 88 | 88 | System.out.println(); | 89 | 89 | System.out.println(response.getCode()); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,7 +65,7 @@ public static void main(String... args) throws IOException, ExecutionException, | 65 | 65 |
| 66 | 66 | // Trade the Request Token and Verfier for the Access Token | 67 | 67 | System.out.println("Trading the Request Token for an Access Token..."); | 68 | | - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); | | 68 | + final OAuth2AccessToken accessToken = service.getAccessToken(code); | 69 | 69 | System.out.println("Got the Access Token!"); | 70 | 70 | System.out.println("(if your curious it looks like this: " + accessToken | 71 | 71 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -75,7 +75,7 @@ public static void main(String... args) throws IOException, ExecutionException, | 75 | 75 | System.out.println("Now we're going to access a protected resource..."); | 76 | 76 | final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); | 77 | 77 | service.signRequest(accessToken, request); | 78 | | - final Response response = service.execute(request, null).get(); | | 78 | + final Response response = service.execute(request); | 79 | 79 | System.out.println("Got it! Lets see what we found..."); | 80 | 80 | System.out.println(); | 81 | 81 | System.out.println(response.getCode()); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,13 +82,13 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 82 | 82 |
| 83 | 83 | // Trade the Request Token and Verfier for the Access Token | 84 | 84 | System.out.println("Trading the Request Token for an Access Token..."); | 85 | | - OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); | | 85 | + OAuth2AccessToken accessToken = service.getAccessToken(code); | 86 | 86 | System.out.println("Got the Access Token!"); | 87 | 87 | System.out.println("(if your curious it looks like this: " + accessToken | 88 | 88 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | 89 | 89 |
| 90 | 90 | System.out.println("Refreshing the Access Token..."); | 91 | | - accessToken = service.refreshAccessTokenAsync(accessToken.getRefreshToken(), null).get(); | | 91 | + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); | 92 | 92 | System.out.println("Refreshed the Access Token!"); | 93 | 93 | System.out.println("(if your curious it looks like this: " + accessToken | 94 | 94 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -113,7 +113,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 113 | 113 |
| 114 | 114 | final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); | 115 | 115 | service.signRequest(accessToken, request); | 116 | | - final Response response = service.execute(request, null).get(); | | 116 | + final Response response = service.execute(request); | 117 | 117 | System.out.println(); | 118 | 118 | System.out.println(response.getCode()); | 119 | 119 | System.out.println(response.getBody()); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 59 | 59 |
| 60 | 60 | // Trade the Request Token and Verfier for the Access Token | 61 | 61 | System.out.println("Trading the Request Token for an Access Token..."); | 62 | | - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); | | 62 | + final OAuth2AccessToken accessToken = service.getAccessToken(code); | 63 | 63 | System.out.println("Got the Access Token!"); | 64 | 64 | System.out.println("(if your curious it looks like this: " + accessToken | 65 | 65 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -68,7 +68,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 68 | 68 | System.out.println("Now we're going to access a protected resource..."); | 69 | 69 | final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); | 70 | 70 | service.signRequest(accessToken, request); | 71 | | - final Response response = service.execute(request, null).get(); | | 71 | + final Response response = service.execute(request); | 72 | 72 |
| 73 | 73 | System.out.println("Got it! Lets see what we found..."); | 74 | 74 | System.out.println(); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,7 +67,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 67 | 67 | final String codeEncoded = URLDecoder.decode(code, "UTF-8"); | 68 | 68 | // Trade the Request Token and Verifier for the Access Token | 69 | 69 | System.out.println("Trading the Request Token for an Access Token..."); | 70 | | - final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); | | 70 | + final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); | 71 | 71 | System.out.println("Got the Access Token!"); | 72 | 72 | System.out.println("(if your curious it looks like this: " + accessToken | 73 | 73 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -83,7 +83,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx | 83 | 83 | System.out.println(); | 84 | 84 | System.out.println("Full URL: " + url); | 85 | 85 | final OAuthRequest request = new OAuthRequest(Verb.GET, url); | 86 | | - final Response response = service.execute(request, null).get(); | | 86 | + final Response response = service.execute(request); | 87 | 87 | System.out.println(); | 88 | 88 | System.out.println(response.getCode()); | 89 | 89 | System.out.println(response.getBody()); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,7 +64,7 @@ public static void main(String... args) throws IOException, InterruptedException | 64 | 64 |
| 65 | 65 | // Trade the Request Token and Verfier for the Access Token | 66 | 66 | System.out.println("Trading the Request Token for an Access Token..."); | 67 | | - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); | | 67 | + final OAuth2AccessToken accessToken = service.getAccessToken(code); | 68 | 68 | System.out.println("Got the Access Token!"); | 69 | 69 | System.out.println("(if your curious it looks like this: " + accessToken | 70 | 70 | + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); | @@ -74,7 +74,7 @@ public static void main(String... args) throws IOException, InterruptedException | 74 | 74 | System.out.println("Now we're going to access a protected resource..."); | 75 | 75 | final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); | 76 | 76 | service.signRequest(accessToken, request); | 77 | | - final Response response = service.execute(request, null).get(); | | 77 | + final Response response = service.execute(request); | 78 | 78 | System.out.println("Got it! Lets see what we found..."); | 79 | 79 | System.out.println(); | 80 | 80 | System.out.println(response.getCode()); | |
Collapse file Copy file name to clipboardExpand all lines: scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +44-10Lines changed: 44 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,17 +54,35 @@ public OAuth2AccessToken convert(Response response) throws IOException { | 54 | 54 | }); | 55 | 55 | } | 56 | 56 |
| | 57 | + public final Future<OAuth2AccessToken> getAccessTokenAsync(String code) { | | 58 | + return getAccessToken(code, null); | | 59 | + } | | 60 | + | | 61 | + /** | | 62 | + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token | | 63 | + * when it is available. | | 64 | + * | | 65 | + * @param code code | | 66 | + * @param callback optional callback | | 67 | + * @return Future | | 68 | + * @deprecated user {@link #getAccessToken(java.lang.String, | | 69 | + * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } | | 70 | + */ | | 71 | + @Deprecated | | 72 | + public final Future<OAuth2AccessToken> getAccessTokenAsync(String code, | | 73 | + OAuthAsyncRequestCallback<OAuth2AccessToken> callback) { | | 74 | + final OAuthRequest request = createAccessTokenRequest(code); | | 75 | + | | 76 | + return sendAccessTokenRequestAsync(request, callback); | | 77 | + } | | 78 | + | 57 | 79 | public final OAuth2AccessToken getAccessToken(String code) | 58 | 80 | throws IOException, InterruptedException, ExecutionException { | 59 | 81 | final OAuthRequest request = createAccessTokenRequest(code); | 60 | 82 |
| 61 | 83 | return sendAccessTokenRequestSync(request); | 62 | 84 | } | 63 | 85 |
| 64 | | - public final Future<OAuth2AccessToken> getAccessTokenAsync(String code) { | 65 | | - return getAccessTokenAsync(code, null); | 66 | | - } | 67 | | - | 68 | 86 | /** | 69 | 87 | * Start the request to retrieve the access token. The optionally provided callback will be called with the Token | 70 | 88 | * when it is available. | @@ -73,7 +91,7 @@ public final Future<OAuth2AccessToken> getAccessTokenAsync(String code) { | 73 | 91 | * @param callback optional callback | 74 | 92 | * @return Future | 75 | 93 | */ | 76 | | - public final Future<OAuth2AccessToken> getAccessTokenAsync(String code, | | 94 | + public final Future<OAuth2AccessToken> getAccessToken(String code, | 77 | 95 | OAuthAsyncRequestCallback<OAuth2AccessToken> callback) { | 78 | 96 | final OAuthRequest request = createAccessTokenRequest(code); | 79 | 97 |
| @@ -95,18 +113,34 @@ protected OAuthRequest createAccessTokenRequest(String code) { | 95 | 113 | return request; | 96 | 114 | } | 97 | 115 |
| | 116 | + public final Future<OAuth2AccessToken> refreshAccessTokenAsync(String refreshToken) { | | 117 | + return refreshAccessToken(refreshToken, null); | | 118 | + } | | 119 | + | | 120 | + /** | | 121 | + * | | 122 | + * @param refreshToken refreshToken | | 123 | + * @param callback callback | | 124 | + * @return future | | 125 | + * @deprecated use {@link #refreshAccessToken(java.lang.String, | | 126 | + * com.github.scribejava.core.model.OAuthAsyncRequestCallback)} | | 127 | + */ | | 128 | + @Deprecated | | 129 | + public final Future<OAuth2AccessToken> refreshAccessTokenAsync(String refreshToken, | | 130 | + OAuthAsyncRequestCallback<OAuth2AccessToken> callback) { | | 131 | + final OAuthRequest request = createRefreshTokenRequest(refreshToken); | | 132 | + | | 133 | + return sendAccessTokenRequestAsync(request, callback); | | 134 | + } | | 135 | + | 98 | 136 | public final OAuth2AccessToken refreshAccessToken(String refreshToken) | 99 | 137 | throws IOException, InterruptedException, ExecutionException { | 100 | 138 | final OAuthRequest request = createRefreshTokenRequest(refreshToken); | 101 | 139 |
| 102 | 140 | return sendAccessTokenRequestSync(request); | 103 | 141 | } | 104 | 142 |
| 105 | | - public final Future<OAuth2AccessToken> refreshAccessTokenAsync(String refreshToken) { | 106 | | - return refreshAccessTokenAsync(refreshToken, null); | 107 | | - } | 108 | | - | 109 | | - public final Future<OAuth2AccessToken> refreshAccessTokenAsync(String refreshToken, | | 143 | + public final Future<OAuth2AccessToken> refreshAccessToken(String refreshToken, | 110 | 144 | OAuthAsyncRequestCallback<OAuth2AccessToken> callback) { | 111 | 145 | final OAuthRequest request = createRefreshTokenRequest(refreshToken); | 112 | 146 |
| |
Collapse file Copy file name to clipboardExpand all lines: scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,6 +68,14 @@ public OAuthConfig getConfig() { | 68 | 68 |
| 69 | 69 | public abstract void signRequest(T token, OAuthRequest request); | 70 | 70 |
| | 71 | + public Future<Response> executeAsync(OAuthRequest request) { | | 72 | + return execute(request, null); | | 73 | + } | | 74 | + | | 75 | + public Future<Response> execute(OAuthRequest request, OAuthAsyncRequestCallback<Response> callback) { | | 76 | + return execute(request, callback, null); | | 77 | + } | | 78 | + | 71 | 79 | public <R> Future<R> execute(OAuthRequest request, OAuthAsyncRequestCallback<R> callback, | 72 | 80 | OAuthRequest.ResponseConverter<R> converter) { | 73 | 81 |
| @@ -84,10 +92,6 @@ public <R> Future<R> execute(OAuthRequest request, OAuthAsyncRequestCallback<R> | 84 | 92 | } | 85 | 93 | } | 86 | 94 |
| 87 | | - public Future<Response> execute(OAuthRequest request, OAuthAsyncRequestCallback<Response> callback) { | 88 | | - return execute(request, callback, null); | 89 | | - } | 90 | | - | 91 | 95 | public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { | 92 | 96 | final File filePayload = request.getFilePayload(); | 93 | 97 | if (filePayload != null) { | |
|