Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ed1989

Browse files
Merge pull request scribejava#328 from luisdelarosa/trello
Added support for Trello API.
2 parents c1b3561 + 55fb59c commit 0ed1989

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.model.*;
4+
5+
public class TrelloApi extends DefaultApi10a
6+
{
7+
private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s";
8+
9+
@Override
10+
public String getAccessTokenEndpoint()
11+
{
12+
return "https://trello.com/1/OAuthGetAccessToken";
13+
}
14+
15+
@Override
16+
public String getRequestTokenEndpoint()
17+
{
18+
return "https://trello.com/1/OAuthGetRequestToken";
19+
}
20+
21+
@Override
22+
public String getAuthorizationUrl(Token requestToken)
23+
{
24+
return String.format(AUTHORIZE_URL, requestToken.getToken());
25+
}
26+
27+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.scribe.examples;
2+
3+
import java.util.Scanner;
4+
5+
import org.scribe.builder.*;
6+
import org.scribe.builder.api.*;
7+
import org.scribe.model.*;
8+
import org.scribe.oauth.*;
9+
10+
public class TrelloExample
11+
{
12+
private static final String API_KEY = "your_api_key";
13+
private static final String API_SECRET = "your_api_secret";
14+
private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me";
15+
public static void main(String[] args)
16+
{
17+
OAuthService service = new ServiceBuilder()
18+
.provider(TrelloApi.class)
19+
.apiKey(API_KEY)
20+
.apiSecret(API_SECRET)
21+
.build();
22+
Scanner in = new Scanner(System.in);
23+
24+
System.out.println("=== Trello's OAuth Workflow ===");
25+
System.out.println();
26+
27+
// Obtain the Request Token
28+
System.out.println("Fetching the Request Token...");
29+
Token requestToken = service.getRequestToken();
30+
System.out.println("Got the Request Token!");
31+
System.out.println();
32+
33+
System.out.println("Now go and authorize Scribe here:");
34+
System.out.println(service.getAuthorizationUrl(requestToken));
35+
System.out.println("And paste the verifier here");
36+
System.out.print(">>");
37+
Verifier verifier = new Verifier(in.nextLine());
38+
System.out.println();
39+
40+
// Trade the Request Token and Verfier for the Access Token
41+
System.out.println("Trading the Request Token for an Access Token...");
42+
Token accessToken = service.getAccessToken(requestToken, verifier);
43+
System.out.println("Got the Access Token!");
44+
System.out.println("(if your curious it looks like this: " + accessToken + " )");
45+
System.out.println();
46+
47+
// Now let's go and ask for a protected resource!
48+
System.out.println("Now we're going to access a protected resource...");
49+
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
50+
service.signRequest(accessToken, request);
51+
Response response = request.send();
52+
System.out.println("Got it! Lets see what we found...");
53+
System.out.println();
54+
System.out.println(response.getBody());
55+
56+
System.out.println();
57+
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
58+
}
59+
60+
}

0 commit comments

Comments
 (0)