Skip to content

Commit c46d1fd

Browse files
committed
add stubs for client api samples
1 parent c453c77 commit c46d1fd

File tree

10 files changed

+120
-20
lines changed

10 files changed

+120
-20
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package private
3+
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
6+
fun main() {
7+
// instantiate api
8+
val api = spotifyClientApi(
9+
System.getenv("SPOTIFY_CLIENT_ID"),
10+
System.getenv("SPOTIFY_CLIENT_SECRET"),
11+
System.getenv("SPOTIFY_REDIRECT_URI")) {
12+
authorization {
13+
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
14+
}
15+
}.build()
16+
17+
}

samples/src/main/kotlin/public/AlbumApiSample.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ fun main() {
1818

1919
// get album "Kids in Love"'s tracks
2020
println(api.albums.getAlbumTracks("spotify:album:4M2p2BIRHIeBu8Ew9IBQ0s").complete().map { it.name })
21-
2221
}

samples/src/main/kotlin/public/UserApiSample.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fun main() {
1313
// get profile for adamratzman1
1414
println(api.users.getProfile("adamratzman1").complete())
1515

16-
1716
// get profile of non-existant user
1817
println(api.users.getProfile("nonexistantuserjjjjjjjjjjj"))
1918
}

src/commonMain/kotlin/com.adamratzman.spotify/http/HttpConnection.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@ enum class HttpRequestMethod(internal val externalMethod: HttpMethod) {
2828
DELETE(HttpMethod.Delete);
2929
}
3030

31-
internal data class HttpHeader(val key: String, val value: String)
31+
data class HttpHeader(val key: String, val value: String)
3232

33-
internal data class HttpResponse(val responseCode: Int, val body: String, val headers: List<HttpHeader>)
33+
data class HttpResponse(val responseCode: Int, val body: String, val headers: List<HttpHeader>)
3434

3535
/**
3636
* Provides a fast, easy, and slim way to execute and retrieve HTTP GET, POST, PUT, and DELETE requests
3737
*/
38-
internal class HttpConnection constructor(
39-
private val url: String,
40-
private val method: HttpRequestMethod,
41-
private val bodyMap: Map<*, *>?,
42-
private val bodyString: String?,
38+
class HttpConnection constructor(
39+
val url: String,
40+
val method: HttpRequestMethod,
41+
val bodyMap: Map<*, *>?,
42+
val bodyString: String?,
4343
contentType: String?,
44-
private val headers: List<HttpHeader> = listOf(),
44+
val headers: List<HttpHeader> = listOf(),
4545
val api: SpotifyApi<*, *>? = null
4646
) {
47-
private val contentType: ContentType = contentType?.let { ContentType.parse(it) } ?: ContentType.Application.Json
47+
val contentType: ContentType = contentType?.let { ContentType.parse(it) } ?: ContentType.Application.Json
4848

4949
companion object {
5050
private val client = HttpClient()
5151
}
5252

53-
private fun String?.toByteArrayContent(): ByteArrayContent? {
53+
fun String?.toByteArrayContent(): ByteArrayContent? {
5454
return if (this == null) null else ByteArrayContent(this.toByteArray(), contentType)
5555
}
5656

57-
private fun buildRequest(additionalHeaders: List<HttpHeader>?): HttpRequestBuilder = HttpRequestBuilder().apply {
57+
fun buildRequest(additionalHeaders: List<HttpHeader>?): HttpRequestBuilder = HttpRequestBuilder().apply {
5858
url(this@HttpConnection.url)
5959
method = this@HttpConnection.method.externalMethod
6060

@@ -84,7 +84,7 @@ internal class HttpConnection constructor(
8484
}
8585
}
8686

87-
internal suspend fun execute(
87+
suspend fun execute(
8888
additionalHeaders: List<HttpHeader>? = null,
8989
retryIf502: Boolean = true
9090
): HttpResponse {
@@ -159,6 +159,6 @@ internal class HttpConnection constructor(
159159
}
160160
}
161161

162-
internal enum class HttpConnectionStatus(val code: Int) {
162+
enum class HttpConnectionStatus(val code: Int) {
163163
HTTP_NOT_MODIFIED(304);
164164
}

src/commonTest/kotlin/com.adamratzman/spotify/public/PublicFollowingAPITest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ class PublicFollowingAPITest : Spek({
1313
val f = api.following
1414
describe("do users follow playlist") {
1515
it("invalid users, valid playlist") {
16-
assertFailsWith<SpotifyException.BadRequestException> { f.areFollowingPlaylist("spotify", "37i9dQZF1DXcBWIGoYBM5M", "udontexist89").complete()[0] }
16+
assertFailsWith<SpotifyException.BadRequestException> { f.areFollowingPlaylist("37i9dQZF1DXcBWIGoYBM5M", "udontexist89").complete()[0] }
1717
}
1818
it("no users, valid playlist") {
1919
assertFailsWith<SpotifyException.BadRequestException> {
20-
f.areFollowingPlaylist("spotify", "37i9dQZF1DXcBWIGoYBM5M").complete()
20+
f.areFollowingPlaylist("37i9dQZF1DXcBWIGoYBM5M").complete()
2121
}
2222
}
2323
it("valid users, invalid playlist") {
2424
assertFailsWith<SpotifyException.BadRequestException> {
25-
f.areFollowingPlaylist("spotify", "asdkfjajksdfjkasdf", "adamratzman1").complete()
25+
f.areFollowingPlaylist("asdkfjajksdfjkasdf", "adamratzman1").complete()
2626
}
2727
}
2828
it("valid users, valid playlist") {
2929
assertEquals(listOf(true, false),
30-
f.areFollowingPlaylist("spotify", "37i9dQZF1DXcBWIGoYBM5M", "adamratzman1", "adamratzman").complete())
30+
f.areFollowingPlaylist("37i9dQZF1DXcBWIGoYBM5M", "adamratzman1", "adamratzman").complete())
3131
}
3232
it("mix of valid and invalid users, valid playlist") {
3333
assertFailsWith<SpotifyException.BadRequestException> {
34-
f.areFollowingPlaylist("spotify", "37i9dQZF1DXcBWIGoYBM5M", "udontexist89", "adamratzman1").complete()
34+
f.areFollowingPlaylist("37i9dQZF1DXcBWIGoYBM5M", "udontexist89", "adamratzman1").complete()
3535
}
3636
}
3737
}

0 commit comments

Comments
 (0)