Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add trello.com oauth adapter #218

Closed
wants to merge 1 commit into from

2 participants

@hwartig

Please consider including into the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2012
  1. @hwartig

    Add trello.com oauth adapter

    hwartig authored
This page is out of date. Refresh to see the latest.
View
1  changelog.txt
@@ -95,3 +95,4 @@
[1.3.3]
* FEATURE: accessToken and requestToken timeouts default to 2 seconds and can be specified.
+ * FEATURE: Trello.com Api
View
35 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());
+ }
+}
+
View
81 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 :)");
+ }
+}
Something went wrong with that request. Please try again.