File tree Expand file tree Collapse file tree
authorization/authorization_code
main/java/com/wrapper/spotify
test/java/com/wrapper/spotify Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ The following (random) data should be used when modifying examples:
77### Authorization
88- Client ID: ` "zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g" `
99- Client secret: ` "zudknyqbh3wunbhcvg9uyvo7uwzeu6nne" `
10- - Redirect URI: ` new URIBuilder().setScheme ("https").setHost(" example.com").setPath(" spotify-redirect").build( )`
10+ - Redirect URI: ` SpotifyHttpManager.makeUri ("https:// example.com/ spotify-redirect")`
1111- Refresh token: ` "b0KuPuLw77Z0hQhCsK-GTHoEx_kethtn357V7iqwEpCTIsLgqbBC_vQBTGC6M5rINl0FrqHK-D3cbOsMOlfyVKuQPvpyGcLcxAoLOTpYXc28nVwB7iBq2oKj9G9lHkFOUKn" `
1212- Access token: ` "taHZ2SdB-bPA3FsK3D7ZN5npZS47cMy-IEySVEGttOhXmqaVAIo0ESvTCLjLBifhHOHOIuhFUKPW1WMDP7w6dj3MAZdWT8CLI2MkZaXbYLTeoDvXesf2eeiLYPBGdx8tIwQJKgV8XdnzH_DONk" `
1313
Original file line number Diff line number Diff line change 11package authorization .authorization_code ;
22
33import com .wrapper .spotify .SpotifyApi ;
4+ import com .wrapper .spotify .SpotifyHttpManager ;
45import com .wrapper .spotify .model_objects .credentials .AuthorizationCodeCredentials ;
56import com .wrapper .spotify .requests .authorization .authorization_code .AuthorizationCodeRequest ;
6- import org .apache .http .client .utils .URIBuilder ;
77
88import java .net .URI ;
9- import java .net .URISyntaxException ;
109import java .util .concurrent .Future ;
1110
1211public class AuthorizationCodeExample {
1312 private static final String clientId = "zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g" ;
1413 private static final String clientSecret = "zudknyqbh3wunbhcvg9uyvo7uwzeu6nne" ;
15- private static URI redirectUri = null ;
14+ private static final URI redirectUri = SpotifyHttpManager . makeUri ( "https://example.com/spotify-redirect" ) ;
1615 private static final String code = "" ;
1716
18- static {
19- try {
20- redirectUri = new URIBuilder ().setScheme ("https" ).setHost ("example.com" ).setPath ("spotify-redirect" ).build ();
21- } catch (URISyntaxException e ) {
22- e .printStackTrace ();
23- }
24- }
25-
2617 private static final SpotifyApi spotifyApi = new SpotifyApi .Builder ()
2718 .setClientId (clientId )
2819 .setClientSecret (clientSecret )
Original file line number Diff line number Diff line change 33import com .wrapper .spotify .SpotifyApi ;
44import com .wrapper .spotify .model_objects .credentials .AuthorizationCodeCredentials ;
55import com .wrapper .spotify .requests .authorization .authorization_code .AuthorizationCodeRefreshRequest ;
6- import org .apache .http .client .utils .URIBuilder ;
76
8- import java .net .URI ;
9- import java .net .URISyntaxException ;
107import java .util .concurrent .Future ;
118
129public class AuthorizationCodeRefreshExample {
Original file line number Diff line number Diff line change 11package authorization .authorization_code ;
22
33import com .wrapper .spotify .SpotifyApi ;
4+ import com .wrapper .spotify .SpotifyHttpManager ;
45import com .wrapper .spotify .requests .authorization .authorization_code .AuthorizationCodeUriRequest ;
5- import org .apache .http .client .utils .URIBuilder ;
66
77import java .net .URI ;
8- import java .net .URISyntaxException ;
98import java .util .concurrent .Future ;
109
1110public class AuthorizationCodeUriExample {
1211 private static final String clientId = "zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g" ;
1312 private static final String clientSecret = "zudknyqbh3wunbhcvg9uyvo7uwzeu6nne" ;
14- private static URI redirectUri = null ;
15-
16- static {
17- try {
18- redirectUri = new URIBuilder ().setScheme ("https" ).setHost ("example.com" ).setPath ("spotify-redirect" ).build ();
19- } catch (URISyntaxException e ) {
20- e .printStackTrace ();
21- }
22- }
13+ private static final URI redirectUri = SpotifyHttpManager .makeUri ("https://example.com/spotify-redirect" );
2314
2415 private static final SpotifyApi spotifyApi = new SpotifyApi .Builder ()
2516 .setClientId (clientId )
Original file line number Diff line number Diff line change @@ -1735,21 +1735,6 @@ public Builder setRedirectUri(URI redirectUri) {
17351735 return this ;
17361736 }
17371737
1738- /**
1739- * The redirect URI setter.
1740- *
1741- * @param redirectUri A redirect URI of your application.
1742- * @return A {@link SpotifyApi.Builder}.
1743- */
1744- public Builder setRedirectUri (String redirectUri ) {
1745- try {
1746- return setRedirectUri (new URI (redirectUri ));
1747- } catch (URISyntaxException e ) {
1748- e .printStackTrace ();
1749- return null ;
1750- }
1751- }
1752-
17531738 /**
17541739 * The access token setter.
17551740 *
Original file line number Diff line number Diff line change 2424
2525import java .io .IOException ;
2626import java .net .URI ;
27+ import java .net .URISyntaxException ;
2728import java .nio .charset .Charset ;
2829import java .util .List ;
2930import java .util .logging .Level ;
3031
3132public class SpotifyHttpManager implements IHttpManager {
3233
33-
3434 private static final int DEFAULT_CACHE_MAX_ENTRIES = 1000 ;
3535 private static final int DEFAULT_CACHE_MAX_OBJECT_SIZE = 8192 ;
3636 private static CloseableHttpClient httpClient = CachingHttpClients .custom ().build ();
@@ -87,6 +87,17 @@ public SpotifyHttpManager(Builder builder) {
8787 .build ();
8888 }
8989
90+ public static URI makeUri (String uriString ) {
91+ try {
92+ return new URI (uriString );
93+ } catch (URISyntaxException e ) {
94+ SpotifyApi .LOGGER .log (
95+ Level .SEVERE ,
96+ "URI Syntax Exception for \" " + uriString + "\" " );
97+ return null ;
98+ }
99+ }
100+
90101 public HttpHost getProxy () {
91102 return proxy ;
92103 }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ public interface ITest<T> {
1010 SpotifyApi SPOTIFY_API = new SpotifyApi .Builder ().setAccessToken ("AccessToken" )
1111 .setClientId ("ClientId" )
1212 .setClientSecret ("ClientSecret" )
13- .setRedirectUri ("RedirectUri" )
13+ .setRedirectUri (SpotifyHttpManager . makeUri ( "RedirectUri" ) )
1414 .setRefreshToken ("RefreshToken" )
1515 .build ();
1616
You can’t perform that action at this time.
0 commit comments