forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Apis
Stas Gromov edited this page Feb 24, 2016
·
4 revisions
You probably will have to work with an API that's not supported out of the box by ScribeJava. This is almost as easy, you'll just gonna need to create a simple class.
Creating your Api class
Let's suppose you want to work with a 1.0a provider called Jimbo, it's api has the following endpoints:
request token: http://jimbo.com/oauth/request_token
access token: http://jimbo.com/oauth/access_token
authorize: http://jimbo.com/oauth/authorize_jimbo?token=<your token here>
ScribeJava does not support it out of the box so naturally, you panic. Don't. The only thing you need to do is make your JimboApi.class like this:
public class JimboApi extends DefaultApi10a {
private static final String AUTHORIZE_URL = "http://jimbo.com/oauth/authorize?token=%s";
protected JimboApi() {
}
private static class InstanceHolder {
private static final JimboApi INSTANCE = new JimboApi();
}
public static JimboApi instance() {
return InstanceHolder.INSTANCE;
}
@Override
public String getAccessTokenEndpoint(){
return "http://jimbo.com/oauth/access_token";
}
@Override
public String getRequestTokenEndpoint() {
return "http://jimbo.com/oauth/request_token";
}
@Override
public String getAuthorizationUrl(OAuth1RequestToken requestToken) {
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}final OAuth10aService service = new ServiceBuilder()
.apiKey("6icbcAXyZx67r8uTAUM5Qw")
.apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s")
.build(JimboApi.instance());The default signature type for ScribeJava uses the request's header. If your API uses query string parameters for the signature, be sure to add:
.signatureType(SignatureType.QueryString)after the apiSecret.
Well you got it! easy right?