|
3 | 3 | We use [Spek](https://github.com/spekframework/spek) to run unit tests. You must add Maven Central to the gradle repositories
|
4 | 4 | in order to pull Spek.
|
5 | 5 |
|
| 6 | +You must create a Spotify application [here](https://developer.spotify.com/dashboard/applications) to get credentials. |
| 7 | + |
6 | 8 | To run **only** public endpoint tests, run
|
7 | 9 |
|
8 |
| -`gradle test -PclientId=YOUR_CLIENT_ID -PclientSecret=YOUR_CLIENT_SECRET` |
| 10 | +`gradle check` |
| 11 | + |
| 12 | +Note: You must have `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET` as environment variables. |
9 | 13 |
|
10 | 14 | To run **all** tests, you need a valid Spotify application, redirect uri, and token string. use:
|
11 | 15 |
|
12 |
| -`gradle test -PclientId=YOUR_CLIENT_ID -PclientSecret=YOUR_CLIENT_SECRET -PspotifyRedirectUri=SPOTIFY_REDIRECT_URI -PspotifyTokenString=SPOTIFY_TOKEN` |
| 16 | +`gradle check` |
| 17 | + |
| 18 | +Note: In addition to `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET`, you also must have the following environment |
| 19 | +variables set up: `SPOTIFY_REDIRECT_URI` and `SPOTIFY_TOKEN_STRING` |
13 | 20 |
|
14 | 21 | Some tests may fail if you do not allow access to all required scopes. To mitigate this, you can individually grant
|
15 | 22 | each scope or use the following code snippet to print out the Spotify token string (given a generated authorization code)
|
16 | 23 |
|
17 | 24 | **How to generate an authorization URL**
|
18 | 25 | ```kotlin
|
19 | 26 | import com.adamratzman.spotify.main.SpotifyScope
|
20 |
| -import com.adamratzman.spotify.main.spotifyApi |
21 |
| - |
22 |
| -spotifyApi { |
23 |
| - credentials { |
24 |
| - clientId = "YOUR_CLIENT_ID" |
25 |
| - clientSecret = "YOUR_CLIENT_SECRET" |
26 |
| - redirectUri = "YOUR_REDIRECT_URI" |
| 27 | +import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi |
| 28 | + |
| 29 | +val api = spotifyClientApi( |
| 30 | + "SPOTIFY_CLIENT_ID", |
| 31 | + "SPOTIFY_CLIENT_SECRET", |
| 32 | + "SPOTIFY_REDIRECT_URI") { |
| 33 | + authorization { |
| 34 | + tokenString = "SPOTIFY_TOKEN_STRING" |
27 | 35 | }
|
28 | 36 | }.getAuthorizationUrl(*SpotifyScope.values())
|
29 | 37 |
|
30 | 38 | ```
|
31 | 39 |
|
32 | 40 | **How to get a Spotify token**
|
33 | 41 | ```kotlin
|
34 |
| -import com.adamratzman.spotify.main.spotifyApi |
35 |
| - |
36 |
| -spotifyApi { |
37 |
| - credentials { |
38 |
| - clientId = "YOUR_CLIENT_ID" |
39 |
| - clientSecret = "YOUR_CLIENT_SECRET" |
40 |
| - redirectUri = "YOUR_REDIRECT_URI" |
41 |
| - } |
42 |
| - clientAuthentication { |
43 |
| - authorizationCode = "SPOTIFY_AUTHORIZATION_CODE" |
| 42 | +import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi |
| 43 | + |
| 44 | +val api = spotifyClientApi( |
| 45 | + "SPOTIFY_CLIENT_ID", |
| 46 | + "SPOTIFY_CLIENT_SECRET", |
| 47 | + "SPOTIFY_REDIRECT_URI") { |
| 48 | + authorization { |
| 49 | + tokenString = "SPOTIFY_TOKEN_STRING" |
44 | 50 | }
|
45 |
| -}.buildClient().token.access_token.let { println(it) } |
| 51 | +}.build().token.accessToken.let { println(it) } |
46 | 52 | ```
|
0 commit comments