Skip to content

Commit 7f88c8b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 587cf4c + 6ae769e commit 7f88c8b

4 files changed

Lines changed: 93 additions & 2 deletions

File tree

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# kickstart travis
1+
# kickstart travis.
22
language: java
3+
4+
# need to override travis 'install' since it will try gpg sign and fail.
5+
install: mvn clean package -DskipTests=true

README.textile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
h2. Welcome to the home of Scribe, the simple OAuth Java lib!
22

3+
!https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)!
4+
35
h1. Why use Scribe?
46

57
h3. Dead Simple
@@ -74,7 +76,7 @@ h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe-java/fa
7476

7577
h1. Questions?
7678

77-
Feel free to drop me an email, but there's already a "StackOvferflow":http://stackoverflow.com tag for "scribe":http://stackoverflow.com/questions/tagged/scribe you should use. I'm subscribed to it so I'll pick the question immediately.
79+
Feel free to drop me an email, but there's already a "StackOverflow":http://stackoverflow.com tag for "scribe":http://stackoverflow.com/questions/tagged/scribe you should use. I'm subscribed to it so I'll pick the question immediately.
7880

7981
Note that it really helps to run scribe on "debug mode":https://github.com/fernandezpablo85/scribe-java/wiki/debug-mode (since 1.3.0), to get additional info. To do this simply call the @.debug()@ method on the @ServiceBuilder@.
8082

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

0 commit comments

Comments
 (0)