package org.scribe.builder.api;

import org.scribe.model.*;

import org.scribe.utils.*;

public class FacebookApi extends DefaultApi20
{
  private static final String AUTHORIZE_URL = "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s";
  private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
  private static final String GRANT_TYPE_PARAM = "&grant_type=%s";

  private static final String SCOPED_GRANT_TYPED_URL = SCOPED_AUTHORIZE_URL+GRANT_TYPE_PARAM;
  private static final String GRANT_TYPED_URL = AUTHORIZE_URL + GRANT_TYPE_PARAM;

  private static final String ACCESS_TOKEN_ENDPOINT = "https://graph.facebook.com/oauth/access_token";


  @Override
  public String getAccessTokenEndpoint()
  {
    return ACCESS_TOKEN_ENDPOINT;
  }

  @Override
  public String getAuthorizationUrl(OAuthConfig config)
  {
    Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Facebook does not support OOB");

    // Append scope and/or grant type if present
    if(config.hasScope() && !config.hasGrantType())
    {
      return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
    }
    else if(config.hasScope() && config.hasGrantType())
    {
      return String.format(SCOPED_GRANT_TYPED_URL, config.getApiKey(),OAuthEncoder.encode(config.getCallback()),
                           OAuthEncoder.encode(config.getScope()),OAuthEncoder.encode(config.getGrantType()));
    }
    else if(!config.hasScope() && config.hasGrantType())
    {
      return String.format(GRANT_TYPED_URL, config.getApiKey(),OAuthEncoder.encode(config.getCallback()),
                             OAuthEncoder.encode(config.getGrantType()));
    }
    else
    {
      return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
    }
  }
}

@@ -130,16 +130,18 @@
 Api20%0A%7B%0A
+  
   privat
@@ -244,24 +244,26 @@
 ct_uri=%25s%22;%0A
+  
   private st
@@ -336,454 +336,145 @@
 s%22;%0A
+%0A
   
-private static final String GRANT_TYPE_PARAM = %22&grant_type=%25s%22;%0A%0A  private static final String SCOPED_GRANT_TYPED_URL = SCOPED_AUTHORIZE_URL+GRANT_TYPE_PARAM;%0A  private static final String GRANT_TYPED_URL = AUTHORIZE_URL + GRANT_TYPE_PARAM;%0A%0A  private static final String ACCESS_TOKEN_ENDPOINT = %22https://graph.facebook.com/oauth/access_token%22;%0A%0A%0A  @Override%0A  public String getAccessTokenEndpoint()%0A  %7B%0A    return ACCESS_TOKEN_ENDPOINT;%0A  %7D%0A%0A
+  @Override%0A    public String getAccessTokenEndpoint()%0A    %7B%0A        return %22https://graph.facebook.com/oauth/access_token%22;%0A    %7D%0A%0A  
   @O
@@ -481,16 +481,18 @@
 verride%0A
+  
   public
@@ -541,18 +541,24 @@
 nfig)%0A  
-%7B%0A
+  %7B%0A    
     Prec
@@ -676,16 +676,20 @@
 OOB%22);%0A%0A
+    
     // A
@@ -704,245 +704,48 @@
 ope 
-and/or grant type if present%0A    if(config.hasScope() && !config.hasGrantType())%0A    %7B%0A      return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.get
+if present%0A        if(config.has
 Scope())
 );%0A 
@@ -744,79 +744,25 @@
 e())
-)
-;
 %0A    
-%7D%0A
     
-else if(config.hasScope() && config.hasGrantType())%0A    %7B%0A
+%7B%0A      
     
@@ -791,27 +791,25 @@
 (SCOPED_
-GRANT_TYPED
+AUTHORIZE
 _URL, co
@@ -817,32 +817,33 @@
 fig.getApiKey(),
+ 
 OAuthEncoder.enc
@@ -872,35 +872,8 @@
 ()),
-%0A                          
  OAu
@@ -911,324 +911,50 @@
 e())
-,OAuthEncoder.encode(config.getGrantType())
 );%0A    
-%7D%0A
     
-else if(!config.hasScope() && config.hasGrantType())%0A    %7B%0A      return String.format(GRANT_TYPED_URL, config.getApiKey(),OAuthEncoder.encode(config.getCallback()),%0A                             OAuthEncoder.encode(config.getGrantType()));%0A    %7D%0A    else%0A    %7B%0A
+%7D%0A        else%0A        %7B%0A      
     
@@ -1059,16 +1059,21 @@
 ));%0A
+    
     %7D%0A
+  
   %7D%0A%7D
-%0A

fix bad merge