org.scribe.builder.api.LinkedInApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-sdk-api Show documentation
Show all versions of aem-sdk-api Show documentation
The Adobe Experience Manager SDK
package org.scribe.builder.api;
import org.scribe.model.*;
import java.util.*;
public class LinkedInApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s";
private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken";
private final Set scopes;
public LinkedInApi()
{
scopes = Collections.emptySet();
}
public LinkedInApi(Set scopes)
{
this.scopes = Collections.unmodifiableSet(scopes);
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.linkedin.com/uas/oauth/accessToken";
}
@Override
public String getRequestTokenEndpoint()
{
return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString();
}
private String scopesAsString()
{
StringBuilder builder = new StringBuilder();
for(String scope : scopes)
{
builder.append("+" + scope);
}
return builder.substring(1);
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
public static LinkedInApi withScopes(String... scopes)
{
Set scopeSet = new HashSet(Arrays.asList(scopes));
return new LinkedInApi(scopeSet);
}
}