package org.scribe.builder.api;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.Token;
import org.scribe.model.Verb;
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()));
	}
	
    @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);
                }
            }
        };
    }
}
@@ -434,17 +434,17 @@
 i20 
-%0D%0A
 %7B%0D%0A
-%09
 %0D%0A
-%09
+    
 priv
@@ -603,20 +603,22 @@
 i=%25s%22;%0D%0A
-%09
 %0D%0A
-%09
+    
 @Overrid
@@ -612,33 +612,36 @@
 %0A    @Override%0D%0A
-%09
+    
 public String ge
@@ -663,24 +663,27 @@
 point() 
-%0D%0A%09%7B%0D%0A%09%09
+%7B%0D%0A        
 return %22
@@ -773,18 +773,21 @@
 %22;%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A
-%09%0D%0A%09
+    
 @Ove
@@ -793,17 +793,20 @@
 erride%0D%0A
-%09
+    
 public S
@@ -855,16 +855,19 @@
 ig) 
-%0D%0A%09%7B%0D%0A%09%09
+%7B%0D%0A        
 retu
@@ -967,13 +967,15 @@
 );%0D%0A
-%09
+    
 %7D%0D%0A
-%09
 %0D%0A  
@@ -1061,20 +1061,16 @@
 %0A    %7D%0D%0A
-    
 %0D%0A    @O
@@ -1184,28 +1184,16 @@
 or() %7B%0D%0A
-            
 %0D%0A      
@@ -1475,12 +1475,24 @@
 %22;%0D%0A
-%09%09%09%09
+                
 Matc
@@ -1583,37 +1583,22 @@
 .find())
+ %7B
 %0D%0A  
-              %7B%0D%0A
         
@@ -1672,32 +1672,34 @@
                 
+  
 return new Token
@@ -1744,51 +1744,18 @@
   %7D 
-%0D%0A                
 else
+ %7B
 %0D%0A  
-              %7B%0D%0A
     

Update src/main/java/org/scribe/builder/api/ConstantContactApi2.java