Skip to content

Commit 1b3f534

Browse files
authored
Merge pull request #284 from adamint/dev
3.8.0
2 parents 92e906f + 23c8c74 commit 1b3f534

File tree

15 files changed

+650
-255
lines changed

15 files changed

+650
-255
lines changed

build.gradle.kts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
44
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
55

66
plugins {
7-
// id("lt.petuska.npm.publish") version "1.1.2"
7+
id("lt.petuska.npm.publish") version "1.1.2"
88
kotlin("multiplatform") version "1.5.0"
99
`maven-publish`
1010
signing
@@ -26,6 +26,7 @@ repositories {
2626
buildscript {
2727
repositories {
2828
google()
29+
mavenCentral()
2930
}
3031
dependencies {
3132
classpath("com.android.tools.build:gradle:3.5.4")
@@ -119,10 +120,11 @@ kotlin {
119120
mavenPublication {
120121
setupPom(artifactId)
121122
}
123+
122124
}
123125

124-
js(if (project.hasProperty("irOnly")) KotlinJsCompilerType.IR else KotlinJsCompilerType.BOTH) {
125-
//binaries.library()
126+
val irOnlyJs = project.hasProperty("irOnly")
127+
js(if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.BOTH) {
126128

127129
mavenPublication {
128130
setupPom(artifactId)
@@ -149,6 +151,8 @@ kotlin {
149151
}
150152
}
151153
}
154+
155+
if (irOnlyJs) binaries.library()
152156
}
153157

154158
// val hostOs = System.getProperty("os.name")
@@ -192,6 +196,7 @@ kotlin {
192196
setupPom(artifactId)
193197
}
194198
}
199+
195200
// disabled due to lack of coroutine/serialization library support (yet)
196201
/*watchos {
197202
binaries {
@@ -312,7 +317,7 @@ kotlin {
312317
dependsOn(commonMain)
313318

314319
dependencies {
315-
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineMTVersion") {
320+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineMTVersion") {
316321
version {
317322
strictly(coroutineMTVersion)
318323
}
@@ -353,7 +358,7 @@ kotlin {
353358
dependsOn(commonMain)
354359

355360
dependencies {
356-
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineMTVersion") {
361+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineMTVersion") {
357362
version {
358363
strictly(coroutineMTVersion)
359364
}
@@ -382,13 +387,13 @@ kotlin {
382387
dependsOn(nativeDarwinTest)
383388
}
384389

385-
/* val watchosMain by getting {
386-
dependsOn(nativeDarwinMain)
387-
}
390+
/* val watchosMain by getting {
391+
dependsOn(nativeDarwinMain)
392+
}
388393
389-
val watchosTest by getting {
390-
dependsOn(nativeDarwinTest)
391-
}*/
394+
val watchosTest by getting {
395+
dependsOn(nativeDarwinTest)
396+
}*/
392397

393398
all {
394399
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
@@ -410,6 +415,16 @@ signing {
410415
}
411416
}
412417

418+
npmPublishing {
419+
repositories {
420+
repository("npmjs") {
421+
registry = uri("https://registry.npmjs.org")
422+
(project.properties.get("npmauthtoken") as? String)?.let { authToken = it }
423+
println("auth token: $authToken")
424+
}
425+
}
426+
}
427+
413428
tasks {
414429
/*npmPublishing {
415430
readme = file("README.MD")

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
22
org.gradle.daemon=true
33
org.gradle.jvmargs=-Xmx8000m
44
kotlin.mpp.enableGranularSourceSetsMetadata=true
5-
kotlin.native.enableDependencyPropagation=false
5+
kotlin.native.enableDependencyPropagation=false
6+
kotlin.js.generate.externals=true

src/androidMain/kotlin/com/adamratzman/spotify/auth/pkce/AbstractSpotifyPkceLoginActivity.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
8686
super.onCreate(savedInstanceState)
8787
setContentView(R.layout.spotify_pkce_auth_layout)
8888

89-
authorizationIntent = Intent(Intent.ACTION_VIEW, getAuthorizationUrl())
9089
credentialStore = application.getDefaultCredentialStore(clientId, redirectUri)
9190

92-
startActivity(authorizationIntent)
91+
// This activity is recreated on every launch, therefore we need to make sure not to
92+
// launch the activity when a Spotify intent result has been received
93+
if (intent?.isSpotifyPkceAuthIntent(redirectUri) == false) {
94+
authorizationIntent = Intent(Intent.ACTION_VIEW, getAuthorizationUrl())
95+
startActivity(authorizationIntent)
96+
finish()
97+
}
9398
}
9499

95100
/**

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApi.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.adamratzman.spotify.endpoints.pub.ArtistApi
1717
import com.adamratzman.spotify.endpoints.pub.BrowseApi
1818
import com.adamratzman.spotify.endpoints.pub.EpisodeApi
1919
import com.adamratzman.spotify.endpoints.pub.FollowingApi
20+
import com.adamratzman.spotify.endpoints.pub.MarketsApi
2021
import com.adamratzman.spotify.endpoints.pub.PlaylistApi
2122
import com.adamratzman.spotify.endpoints.pub.SearchApi
2223
import com.adamratzman.spotify.endpoints.pub.ShowApi
@@ -56,6 +57,7 @@ import kotlinx.serialization.json.Json
5657
* @property tracks Provides access to Spotify [track endpoints](https://developer.spotify.com/documentation/web-api/reference/tracks/)
5758
* @property episodes Provides access to Spotify [episode endpoints](https://developer.spotify.com/documentation/web-api/reference/episodes/)
5859
* @property shows Provides access to Spotify [show endpoints](https://developer.spotify.com/documentation/web-api/reference/shows/)
60+
* @property markets Provides access to Spotify [market endpoints](https://developer.spotify.com/documentation/web-api/reference/#category-markets)
5961
*/
6062
public sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>(
6163
public val clientId: String?,
@@ -82,6 +84,7 @@ public sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B
8284
public abstract val following: FollowingApi
8385
public abstract val episodes: EpisodeApi
8486
public abstract val shows: ShowApi
87+
public abstract val markets: MarketsApi
8588

8689
/**
8790
* Base url for Spotify web api calls
@@ -397,6 +400,7 @@ public class SpotifyAppApi internal constructor(
397400
override val tracks: TrackApi = TrackApi(this)
398401
override val episodes: EpisodeApi = EpisodeApi(this)
399402
override val shows: ShowApi = ShowApi(this)
403+
override val markets: MarketsApi = MarketsApi(this)
400404

401405
/**
402406
* Provides access to **public** Spotify [playlist endpoints](https://developer.spotify.com/documentation/web-api/reference/playlists/)
@@ -491,6 +495,7 @@ public open class SpotifyClientApi(
491495
override val artists: ArtistApi = ArtistApi(this)
492496
override val tracks: TrackApi = TrackApi(this)
493497
override val search: SearchApi = SearchApi(this)
498+
override val markets: MarketsApi = MarketsApi(this)
494499

495500
override val episodes: ClientEpisodeApi = ClientEpisodeApi(this)
496501
override val shows: ClientShowApi = ClientShowApi(this)

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientLibraryApi.kt

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import com.adamratzman.spotify.SpotifyRestAction
77
import com.adamratzman.spotify.SpotifyScope
88
import com.adamratzman.spotify.http.SpotifyEndpoint
99
import com.adamratzman.spotify.models.AlbumUri
10+
import com.adamratzman.spotify.models.EpisodeUri
1011
import com.adamratzman.spotify.models.PagingObject
1112
import com.adamratzman.spotify.models.PlayableUri
1213
import com.adamratzman.spotify.models.SavedAlbum
14+
import com.adamratzman.spotify.models.SavedEpisode
15+
import com.adamratzman.spotify.models.SavedShow
1316
import com.adamratzman.spotify.models.SavedTrack
17+
import com.adamratzman.spotify.models.ShowUri
1418
import com.adamratzman.spotify.models.serialization.toList
1519
import com.adamratzman.spotify.models.serialization.toNonNullablePagingObject
1620
import com.adamratzman.spotify.utils.Market
@@ -118,6 +122,105 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
118122
market: Market? = null
119123
): SpotifyRestAction<PagingObject<SavedAlbum>> = SpotifyRestAction { getSavedAlbums(limit, offset, market) }
120124

125+
/**
126+
* Get a list of shows saved in the current Spotify user’s library.
127+
* Optional parameters can be used to limit the number of shows returned.
128+
*
129+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
130+
*
131+
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/)**
132+
*
133+
* @param limit The number of objects to return. Default: 50 (or api limit). Minimum: 1. Maximum: 50.
134+
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
135+
*
136+
* @return Paging Object of [SavedShow] ordered by position in library
137+
*/
138+
public suspend fun getSavedShows(
139+
limit: Int? = api.spotifyApiOptions.defaultLimit,
140+
offset: Int? = null
141+
): PagingObject<SavedShow> {
142+
requireScopes(SpotifyScope.USER_LIBRARY_READ)
143+
144+
return get(
145+
endpointBuilder("/me/shows").with("limit", limit).with("offset", offset).toString()
146+
).toNonNullablePagingObject(SavedShow.serializer(), api = api, json = json)
147+
}
148+
149+
/**
150+
* Get a list of shows saved in the current Spotify user’s library.
151+
* Optional parameters can be used to limit the number of shows returned.
152+
*
153+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
154+
*
155+
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/)**
156+
*
157+
* @param limit The number of objects to return. Default: 50 (or api limit). Minimum: 1. Maximum: 50.
158+
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
159+
*
160+
* @return Paging Object of [SavedShow] ordered by position in library
161+
*/
162+
public fun getSavedShowsRestAction(
163+
limit: Int? = api.spotifyApiOptions.defaultLimit,
164+
offset: Int? = null
165+
): SpotifyRestAction<PagingObject<SavedShow>> {
166+
return SpotifyRestAction {
167+
getSavedShows(limit, offset)
168+
}
169+
}
170+
171+
/**
172+
* Get a list of the episodes saved in the current Spotify user’s library.
173+
* This API endpoint is in beta and could change without warning.
174+
*
175+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
176+
*
177+
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/)**
178+
*
179+
* @param limit The number of objects to return. Default: 50 (or api limit). Minimum: 1. Maximum: 50.
180+
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
181+
* @param market Provide this parameter if you want the list of returned items to be relevant to a particular country.
182+
* If omitted, the returned items will be relevant to all countries.
183+
*
184+
* @return Paging Object of [SavedEpisode] ordered by position in library
185+
*/
186+
public suspend fun getSavedEpisodes(
187+
limit: Int? = api.spotifyApiOptions.defaultLimit,
188+
offset: Int? = null,
189+
market: Market? = null
190+
): PagingObject<SavedEpisode> {
191+
requireScopes(SpotifyScope.USER_LIBRARY_READ)
192+
193+
return get(
194+
endpointBuilder("/me/episodes").with("limit", limit).with("offset", offset).with("market", market)
195+
.toString()
196+
).toNonNullablePagingObject(SavedEpisode.serializer(), api = api, json = json)
197+
}
198+
199+
/**
200+
* Get a list of the episodes saved in the current Spotify user’s library.
201+
* This API endpoint is in beta and could change without warning.
202+
*
203+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
204+
*
205+
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/)**
206+
*
207+
* @param limit The number of objects to return. Default: 50 (or api limit). Minimum: 1. Maximum: 50.
208+
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
209+
* @param market Provide this parameter if you want the list of returned items to be relevant to a particular country.
210+
* If omitted, the returned items will be relevant to all countries.
211+
*
212+
* @return Paging Object of [SavedEpisode] ordered by position in library
213+
*/
214+
public suspend fun getSavedEpisodesRestAction(
215+
limit: Int? = api.spotifyApiOptions.defaultLimit,
216+
offset: Int? = null,
217+
market: Market? = null
218+
): SpotifyRestAction<PagingObject<SavedEpisode>> {
219+
return SpotifyRestAction {
220+
getSavedEpisodes(limit, offset, market)
221+
}
222+
}
223+
121224
/**
122225
* Check if the [LibraryType] with id [id] is already saved in the current Spotify user’s ‘Your Music’ library.
123226
*
@@ -144,7 +247,8 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
144247
*
145248
* @throws BadRequestException if [id] is not found
146249
*/
147-
public fun containsRestAction(type: LibraryType, id: String): SpotifyRestAction<Boolean> = SpotifyRestAction { contains(type, ids = arrayOf(id))[0] }
250+
public fun containsRestAction(type: LibraryType, id: String): SpotifyRestAction<Boolean> =
251+
SpotifyRestAction { contains(type, ids = arrayOf(id))[0] }
148252

149253
/**
150254
* Check if one or more of [LibraryType] is already saved in the current Spotify user’s ‘Your Music’ library.
@@ -215,7 +319,8 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
215319
*
216320
* @throws BadRequestException if the id is invalid
217321
*/
218-
public fun addRestAction(type: LibraryType, id: String): SpotifyRestAction<Unit> = SpotifyRestAction { add(type, id) }
322+
public fun addRestAction(type: LibraryType, id: String): SpotifyRestAction<Unit> =
323+
SpotifyRestAction { add(type, id) }
219324

220325
/**
221326
* Save one or more of [LibraryType] to the current user’s ‘Your Music’ library.
@@ -253,7 +358,8 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
253358
*
254359
* @throws BadRequestException if any of the provided ids is invalid
255360
*/
256-
public fun addRestAction(type: LibraryType, vararg ids: String): SpotifyRestAction<Unit> = SpotifyRestAction { add(type, *ids) }
361+
public fun addRestAction(type: LibraryType, vararg ids: String): SpotifyRestAction<Unit> =
362+
SpotifyRestAction { add(type, *ids) }
257363

258364
/**
259365
* Remove one of [LibraryType] (track or album) from the current user’s ‘Your Music’ library.
@@ -285,7 +391,8 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
285391
*
286392
* @throws BadRequestException if any of the provided ids is invalid
287393
*/
288-
public fun removeRestAction(type: LibraryType, id: String): SpotifyRestAction<Unit> = SpotifyRestAction { remove(type, ids = arrayOf(id)) }
394+
public fun removeRestAction(type: LibraryType, id: String): SpotifyRestAction<Unit> =
395+
SpotifyRestAction { remove(type, ids = arrayOf(id)) }
289396

290397
/**
291398
* Remove one or more of the [LibraryType] (tracks or albums) from the current user’s ‘Your Music’ library.
@@ -344,7 +451,9 @@ public class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
344451
*/
345452
public enum class LibraryType(private val value: String, internal val id: (String) -> String) {
346453
TRACK("tracks", { PlayableUri(it).id }),
347-
ALBUM("albums", { AlbumUri(it).id });
454+
ALBUM("albums", { AlbumUri(it).id }),
455+
EPISODE("episodes", { EpisodeUri(it).id }),
456+
SHOW("shows", { ShowUri(it).id });
348457

349458
override fun toString(): String = value
350459
}

0 commit comments

Comments
 (0)