Skip to content

Commit 57686c8

Browse files
authored
Merge pull request #314 from adamint/dev/adamint/dependencies-update-add-token-string
update dependencies and save scopes to credential store
2 parents 01afa60 + fcc510a commit 57686c8

File tree

8 files changed

+56
-35
lines changed

8 files changed

+56
-35
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: CI Test Workflow
55

66
on:
77
push:
8-
branches: [ master, dev ]
8+
branches: [ main, dev ]
99
pull_request:
10-
branches: [ master, dev ]
10+
branches: [ main, dev ]
1111

1212
jobs:
1313
test_android_jvm_linux:

build.gradle.kts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UnstableApiUsage")
2+
13
import org.jetbrains.dokka.gradle.DokkaTask
24
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
35
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
@@ -11,9 +13,9 @@ plugins {
1113
id("io.codearte.nexus-staging") version "0.30.0"
1214
id("com.android.library")
1315
kotlin("plugin.serialization")
14-
id("com.diffplug.spotless") version "6.3.0"
16+
id("com.diffplug.spotless") version "6.7.2"
1517
id("com.moowork.node") version "1.3.1"
16-
id("org.jetbrains.dokka")
18+
id("org.jetbrains.dokka") version "1.7.10"
1719
}
1820

1921
repositories {
@@ -46,18 +48,18 @@ tasks.withType<Test> {
4648
}
4749

4850
android {
49-
compileSdkVersion(30)
51+
compileSdk = 30
5052
compileOptions {
5153
sourceCompatibility = JavaVersion.VERSION_1_8
5254
targetCompatibility = JavaVersion.VERSION_1_8
5355
}
5456
packagingOptions {
55-
exclude("META-INF/*.md")
57+
resources.excludes.add("META-INF/*.md")
5658
}
5759
defaultConfig {
58-
minSdkVersion(23)
59-
targetSdkVersion(30)
60-
compileSdkVersion(30)
60+
minSdk = 23
61+
targetSdk = 30
62+
setCompileSdkVersion(30)
6163
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
6264
}
6365
buildTypes {
@@ -217,10 +219,12 @@ kotlin {
217219
val kotlinxDatetimeVersion = "0.3.1"
218220

219221
sourceSets {
220-
val serializationVersion = "1.3.2"
221-
val ktorVersion = "1.6.8"
222-
val korlibsVersion = "2.2.0"
222+
val kotlinxDatetimeVersion = "0.4.0"
223+
val serializationVersion = "1.3.3"
224+
val ktorVersion = "2.0.3"
223225
val sparkVersion = "2.9.3"
226+
227+
val korlibsVersion = "2.2.0"
224228
val androidSpotifyAuthVersion = "1.2.5"
225229
val androidCryptoVersion = "1.0.0"
226230
val coroutineMTVersion = "1.6.0-native-mt"
@@ -231,7 +235,6 @@ kotlin {
231235
implementation("io.ktor:ktor-client-core:$ktorVersion")
232236
implementation("com.soywiz.korlibs.krypto:krypto:$korlibsVersion")
233237
implementation("com.soywiz.korlibs.korim:korim:$korlibsVersion")
234-
235238
}
236239
}
237240

@@ -298,7 +301,7 @@ kotlin {
298301
implementation("com.pnikosis:materialish-progress:1.7")
299302
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
300303
implementation("androidx.security:security-crypto:$androidCryptoVersion")
301-
implementation("androidx.appcompat:appcompat:1.3.1")
304+
implementation("androidx.appcompat:appcompat:1.4.2")
302305
}
303306
}
304307

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ kotlin.native.enableDependencyPropagation=false
1919
android.useAndroidX=true
2020
android.enableJetifier=true
2121
kotlin.mpp.enableGranularSourceSetsMetadata=true
22-
kotlinVersion=1.6.10
22+
kotlinVersion=1.7.10
2323
androidBuildToolsVersion=7.0.0

src/androidMain/kotlin/com/adamratzman/spotify/auth/SpotifyDefaultCredentialStore.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public class SpotifyDefaultCredentialStore(
3838
applicationContext: Context
3939
) {
4040
public companion object {
41+
/**
42+
* The key used with spotify scope string in [EncryptedSharedPreferences]
43+
*/
44+
public const val SpotifyScopeStringKey: String = "spotifyTokenScopes"
45+
4146
/**
4247
* The key used with spotify token expiry in [EncryptedSharedPreferences]
4348
*/
@@ -106,6 +111,13 @@ public class SpotifyDefaultCredentialStore(
106111
get() = encryptedPreferences.getString(SpotifyRefreshTokenKey, null)
107112
set(value) = encryptedPreferences.edit().putString(SpotifyRefreshTokenKey, value).apply()
108113

114+
/**
115+
* Get/set the Spotify scope string.
116+
*/
117+
public var spotifyScopeString: String?
118+
get() = encryptedPreferences.getString(SpotifyScopeStringKey, null)
119+
set(value) = encryptedPreferences.edit().putString(SpotifyScopeStringKey, value).apply()
120+
109121
/**
110122
* Get/set the current Spotify PKCE code verifier.
111123
*/
@@ -128,7 +140,8 @@ public class SpotifyDefaultCredentialStore(
128140
accessToken,
129141
"Bearer",
130142
(tokenExpiresAt - System.currentTimeMillis()).toInt() / 1000,
131-
refreshToken
143+
refreshToken,
144+
scopeString = spotifyScopeString
132145
)
133146
}
134147
set(token) {
@@ -138,10 +151,12 @@ public class SpotifyDefaultCredentialStore(
138151
spotifyRefreshToken = null
139152

140153
credentialTypeStored = null
154+
spotifyScopeString = null
141155
} else {
142156
spotifyAccessToken = token.accessToken
143157
spotifyTokenExpiresAt = token.expiresAt
144158
spotifyRefreshToken = token.refreshToken
159+
spotifyScopeString = token.scopeString
145160

146161
credentialTypeStored =
147162
if (token.refreshToken != null) CredentialType.Pkce else CredentialType.ImplicitGrant

src/androidMain/kotlin/com/adamratzman/spotify/auth/implicit/AbstractSpotifyAppCompatImplicitLoginActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public abstract class AbstractSpotifyAppCompatImplicitLoginActivity : SpotifyImp
2424
triggerLoginActivity()
2525
}
2626

27+
@Suppress("OVERRIDE_DEPRECATION")
2728
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
2829
super.onActivityResult(requestCode, resultCode, intent)
2930
processActivityResult(requestCode, resultCode, intent)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.adamratzman.spotify.models.serialization.nonstrictJson
99
import com.adamratzman.spotify.models.serialization.toObject
1010
import com.adamratzman.spotify.utils.urlEncodeBase64String
1111
import com.soywiz.krypto.SHA256
12-
import io.ktor.client.features.ServerResponseException
12+
import io.ktor.client.plugins.ServerResponseException
1313
import io.ktor.utils.io.core.toByteArray
1414
import kotlinx.coroutines.CancellationException
1515
import kotlinx.serialization.json.Json

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.adamratzman.spotify
33

44
import com.adamratzman.spotify.models.AuthenticationError
55
import com.adamratzman.spotify.models.ErrorObject
6-
import io.ktor.client.features.ResponseException
6+
import io.ktor.client.plugins.ResponseException
77

88
public sealed class SpotifyException(message: String, cause: Throwable? = null) : Exception(message, cause) {
99
public abstract class UnNullableException(message: String) : SpotifyException(message)

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import com.adamratzman.spotify.models.ErrorResponse
1111
import com.adamratzman.spotify.models.SpotifyRatelimitedException
1212
import com.adamratzman.spotify.models.serialization.nonstrictJson
1313
import com.adamratzman.spotify.models.serialization.toObject
14-
import com.soywiz.korio.dynamic.KDynamic.Companion.toLong
1514
import io.ktor.client.HttpClient
16-
import io.ktor.client.features.ResponseException
15+
import io.ktor.client.plugins.ResponseException
1716
import io.ktor.client.request.HttpRequestBuilder
1817
import io.ktor.client.request.header
1918
import io.ktor.client.request.request
19+
import io.ktor.client.request.setBody
2020
import io.ktor.client.request.url
21-
import io.ktor.client.statement.readText
21+
import io.ktor.client.statement.bodyAsText
2222
import io.ktor.http.ContentType
2323
import io.ktor.http.HttpMethod
2424
import io.ktor.http.content.ByteArrayContent
@@ -62,19 +62,21 @@ public class HttpConnection constructor(
6262
url(this@HttpConnection.url)
6363
method = this@HttpConnection.method.externalMethod
6464

65-
body = when (this@HttpConnection.method) {
66-
HttpRequestMethod.DELETE -> {
67-
bodyString.toByteArrayContent() ?: body
68-
}
69-
HttpRequestMethod.PUT, HttpRequestMethod.POST -> {
70-
val contentString = if (contentType == ContentType.Application.FormUrlEncoded) {
71-
bodyMap?.map { "${it.key}=${it.value}" }?.joinToString("&") ?: bodyString
72-
} else bodyString
65+
setBody(
66+
when (this@HttpConnection.method) {
67+
HttpRequestMethod.DELETE -> {
68+
bodyString.toByteArrayContent() ?: body
69+
}
70+
HttpRequestMethod.PUT, HttpRequestMethod.POST -> {
71+
val contentString = if (contentType == ContentType.Application.FormUrlEncoded) {
72+
bodyMap?.map { "${it.key}=${it.value}" }?.joinToString("&") ?: bodyString
73+
} else bodyString
7374

74-
contentString.toByteArrayContent() ?: ByteArrayContent("".toByteArray(), contentType)
75+
contentString.toByteArrayContent() ?: ByteArrayContent("".toByteArray(), contentType)
76+
}
77+
else -> body
7578
}
76-
else -> body
77-
}
79+
)
7880

7981
// let additionalHeaders overwrite headers
8082
val allHeaders = if (additionalHeaders == null) this@HttpConnection.headers
@@ -92,7 +94,7 @@ public class HttpConnection constructor(
9294
val httpRequest = buildRequest(additionalHeaders)
9395
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: Request: $this")
9496
try {
95-
return httpClient.request<io.ktor.client.statement.HttpResponse>(httpRequest).let { response ->
97+
return httpClient.request(httpRequest).let { response ->
9698
val respCode = response.status.value
9799

98100
if (respCode in 500..599 && (retryIfInternalServerErrorLeft == null || retryIfInternalServerErrorLeft == -1 || retryIfInternalServerErrorLeft > 0)) {
@@ -116,7 +118,7 @@ public class HttpConnection constructor(
116118
} else throw SpotifyRatelimitedException(ratelimit)
117119
}
118120

119-
val body: String = response.readText()
121+
val body: String = response.bodyAsText()
120122
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: $body")
121123

122124
if (respCode == 401 && body.contains("access token") && api?.spotifyApiOptions?.automaticRefresh == true) {
@@ -145,7 +147,7 @@ public class HttpConnection constructor(
145147
} catch (e: CancellationException) {
146148
throw e
147149
} catch (e: ResponseException) {
148-
val errorBody = e.response.readText()
150+
val errorBody = e.response.bodyAsText()
149151
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: $errorBody")
150152
try {
151153
val respCode = e.response.status.value

0 commit comments

Comments
 (0)