Skip to content

Commit

Permalink
Update src/main/java/org/scribe/builder/api/ConstantContactApi2.java
Browse files Browse the repository at this point in the history
fixed indentation (4 spaces, no wrap)
  • Loading branch information
eranation committed Aug 17, 2012
1 parent a121c3a commit 6e6fd53
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions src/main/java/org/scribe/builder/api/ConstantContactApi2.java
Expand Up @@ -11,47 +11,40 @@
import org.scribe.utils.OAuthEncoder;
import org.scribe.utils.Preconditions;

public class ConstantContactApi2 extends DefaultApi20
{

private static final String AUTHORIZE_URL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s";

@Override
public String getAccessTokenEndpoint()
{
return "https://oauth2.constantcontact.com/oauth2/oauth/token?grant_type=authorization_code";
}


@Override
public String getAuthorizationUrl(OAuthConfig config)
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}

public class ConstantContactApi2 extends DefaultApi20 {

private static final String AUTHORIZE_URL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s";

@Override
public String getAccessTokenEndpoint() {
return "https://oauth2.constantcontact.com/oauth2/oauth/token?grant_type=authorization_code";
}

@Override
public String getAuthorizationUrl(OAuthConfig config) {
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}

@Override
public Verb getAccessTokenVerb() {
return Verb.POST;
}

@Override
public AccessTokenExtractor getAccessTokenExtractor() {
return new AccessTokenExtractor() {

@Override
public Token extract(String response) {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");

String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\"";
Matcher matcher = Pattern.compile(regex).matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
Matcher matcher = Pattern.compile(regex).matcher(response);
if (matcher.find()) {
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, "", response);
} else {
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
};
Expand Down

0 comments on commit 6e6fd53

Please sign in to comment.