11package com .github .scribejava .apis ;
22
3- import java .util .Arrays ;
4- import java .util .Collections ;
5- import java .util .HashSet ;
6- import java .util .Set ;
73import com .github .scribejava .core .builder .api .DefaultApi10a ;
84import com .github .scribejava .core .model .Token ;
95
@@ -20,14 +16,22 @@ public static LinkedInApi instance() {
2016 return InstanceHolder .INSTANCE ;
2117 }
2218
23- private final Set < String > scopes ;
19+ private final String scopesAsString ;
2420
2521 public LinkedInApi () {
26- scopes = Collections .emptySet ();
27- }
28-
29- public LinkedInApi (final Set <String > scopes ) {
30- this .scopes = Collections .unmodifiableSet (scopes );
22+ scopesAsString = null ;
23+ }
24+
25+ public LinkedInApi (final String ... scopes ) {
26+ if (scopes == null || scopes .length == 0 ) {
27+ scopesAsString = null ;
28+ } else {
29+ final StringBuilder builder = new StringBuilder ();
30+ for (final String scope : scopes ) {
31+ builder .append ('+' ).append (scope );
32+ }
33+ scopesAsString = "?scope=" + builder .substring (1 );
34+ }
3135 }
3236
3337 @ Override
@@ -37,25 +41,11 @@ public String getAccessTokenEndpoint() {
3741
3842 @ Override
3943 public String getRequestTokenEndpoint () {
40- return scopes .isEmpty () ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString ();
41- }
42-
43- private String scopesAsString () {
44- final StringBuilder builder = new StringBuilder ();
45- for (final String scope : scopes ) {
46- builder .append ("+" + scope );
47- }
48- return builder .substring (1 );
44+ return scopesAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopesAsString ;
4945 }
5046
5147 @ Override
5248 public String getAuthorizationUrl (final Token requestToken ) {
5349 return String .format (AUTHORIZE_URL , requestToken .getToken ());
5450 }
55-
56- public static LinkedInApi withScopes (final String ... scopes ) {
57- final Set <String > scopeSet = new HashSet <>(Arrays .asList (scopes ));
58- return new LinkedInApi (scopeSet );
59- }
60-
6151}
0 commit comments