Skip to content

Commit f77391e

Browse files
softpropsfernandezpablo85
authored andcommitted
Add meetup.com oauth adapter
1 parent 6cfdf97 commit f77391e

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@
7575
[1.3.0]
7676
* FEATURE: Multiple parameters with the same name supported.
7777
* FEAUTRE: 'debug' mode that logs useful information about the signature making
78+
79+
[1.3.1]
80+
* FEATURE: Meetup.com Api
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.model.Token;
4+
5+
/**
6+
* OAuth access to the Meetup.com API.
7+
* For more information visit http://www.meetup.com/api
8+
*/
9+
public class MeetupApi extends DefaultApi10a
10+
{
11+
private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s";
12+
13+
@Override
14+
public String getRequestTokenEndpoint()
15+
{
16+
return "http://api.meetup.com/oauth/request/";
17+
}
18+
19+
@Override
20+
public String getAccessTokenEndpoint()
21+
{
22+
return "http://api.meetup.com/oauth/access/";
23+
}
24+
25+
@Override
26+
public String getAuthorizationUrl(Token requestToken)
27+
{
28+
return String.format(AUTHORIZE_URL, requestToken.getToken());
29+
}
30+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.scribe.examples;
2+
3+
import java.util.Scanner;
4+
5+
import org.scribe.builder.ServiceBuilder;
6+
import org.scribe.builder.api.MeetupApi;
7+
import org.scribe.model.OAuthRequest;
8+
import org.scribe.model.Response;
9+
import org.scribe.model.Token;
10+
import org.scribe.model.Verb;
11+
import org.scribe.model.Verifier;
12+
import org.scribe.oauth.OAuthService;
13+
14+
public class MeetupExample
15+
{
16+
private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self";
17+
18+
public static void main(String[] args)
19+
{
20+
OAuthService service = new ServiceBuilder()
21+
.provider(MeetupApi.class)
22+
.apiKey("j1khkp0dus323ftve0sdcv6ffe")
23+
.apiSecret("6s6gt6q59gvfjtsvgcmht62gq4")
24+
.build();
25+
Scanner in = new Scanner(System.in);
26+
27+
System.out.println("=== Meetup's OAuth Workflow ===");
28+
System.out.println();
29+
30+
// Obtain the Request Token
31+
System.out.println("Fetching the Request Token...");
32+
Token requestToken = service.getRequestToken();
33+
System.out.println("Got the Request Token!");
34+
System.out.println();
35+
36+
System.out.println("Now go and authorize Scribe here:");
37+
System.out.println(service.getAuthorizationUrl(requestToken));
38+
System.out.println("And paste the verifier here");
39+
System.out.print(">>");
40+
Verifier verifier = new Verifier(in.nextLine());
41+
System.out.println();
42+
43+
// Trade the Request Token and Verfier for the Access Token
44+
System.out.println("Trading the Request Token for an Access Token...");
45+
Token accessToken = service.getAccessToken(requestToken, verifier);
46+
System.out.println("Got the Access Token!");
47+
System.out.println("(if your curious it looks like this: " + accessToken + " )");
48+
System.out.println();
49+
50+
// Now let's go and ask for a protected resource!
51+
System.out.println("Now we're going to access a protected resource...");
52+
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
53+
service.signRequest(accessToken, request);
54+
Response response = request.send();
55+
System.out.println("Got it! Lets see what we found...");
56+
System.out.println();
57+
System.out.println(response.getBody());
58+
59+
System.out.println();
60+
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
61+
}
62+
}

0 commit comments

Comments
 (0)