Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trello.com oauth adapter #218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -95,3 +95,4 @@

[1.3.3]
* FEATURE: accessToken and requestToken timeouts default to 2 seconds and can be specified.
* FEATURE: Trello.com Api
35 changes: 35 additions & 0 deletions src/main/java/org/scribe/builder/api/TrelloApi.java
@@ -0,0 +1,35 @@
package org.scribe.builder.api;

import org.scribe.model.Token;

/**
* OAuth access to the trello.com api.
* <p/>
* For more information visit http://trello.com/api
*
* @author Harald Wartig <hwartig@googlemail.com>
*/
public class TrelloApi extends DefaultApi10a
{

private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s";

@Override
public String getRequestTokenEndpoint()
{
return "https://trello.com/1/OAuthGetRequestToken";
}

@Override
public String getAccessTokenEndpoint()
{
return "https://trello.com/1/OAuthGetAccessToken";
}

@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}

81 changes: 81 additions & 0 deletions src/test/java/org/scribe/examples/TrelloExample.java
@@ -0,0 +1,81 @@
package org.scribe.examples;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TrelloApi;
import org.scribe.model.*;
import org.scribe.oauth.OAuthService;

import java.util.Scanner;

/**
* Shows you how to use scribe with trello.com .
*
* @author Harald Wartig <hwartig@googlemail.com>
*/
public class TrelloExample
{
private static final String PROTECTED_RESOURCE_URL = "https://api.trello.com/1/members/me/boards";

public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "";
String apiSecret = "";

Scanner in = new Scanner(System.in);

if (apiKey.isEmpty() || apiSecret.isEmpty()) {
System.out.println("=== Setup ===");
System.out.println();

System.out.println("We need your apiKey:");
System.out.print(">>");
apiKey = in.nextLine();

System.out.println(".. and your apiSecret too:");
System.out.print(">>");
apiSecret = in.nextLine();
}

OAuthService service = new ServiceBuilder()
.provider(TrelloApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();

System.out.println("=== Trello's OAuth Workflow ===");
System.out.println();

// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();

System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();

// Trade the Request Token and Verifier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();

// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets take a look at your board list...");
System.out.println();
System.out.println(response.getBody());

System.out.println();
System.out.println("Go and build something awesome with Scribe & trello.com :)");
}
}