Skip to content

Commit aab852e

Browse files
authored
Merge pull request #92 from adamint/dev
Moshi, ghttp
2 parents e132808 + 7326c4b commit aab852e

26 files changed

+506
-533
lines changed

.idea/misc.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repositories {
2929
jcenter()
3030
}
3131
32-
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.2.0'
32+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.3.0'
3333
```
3434

3535
To use the latest snapshot instead, you must add the Jitpack repository as well
@@ -51,7 +51,7 @@ dependencies {
5151
<dependency>
5252
<groupId>com.adamratzman</groupId>
5353
<artifactId>spotify-api-kotlin</artifactId>
54-
<version>2.2.0</version>
54+
<version>2.3.0</version>
5555
</dependency>
5656
5757
<repository>

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ apply plugin: 'kotlin'
2222
apply plugin: 'org.jetbrains.dokka'
2323

2424
group 'com.adamratzman'
25-
version '2.2.0'
25+
version '2.3.0'
2626

2727
archivesBaseName = 'spotify-api-kotlin'
2828

@@ -34,9 +34,13 @@ repositories {
3434

3535
dependencies {
3636
// Actual library dependencies
37-
compile 'com.beust:klaxon:5.0.5'
3837
compile 'com.neovisionaries:nv-i18n:1.25'
3938

39+
compile "com.squareup.moshi:moshi:1.8.0"
40+
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
41+
42+
compile group: 'com.google.http-client', name: 'google-http-client', version: '1.23.0'
43+
4044
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4145
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
4246

src/main/kotlin/com/adamratzman/spotify/Builder.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SpotifyApiBuilder(
2323
var tokenString: String? = null,
2424
var token: Token? = null,
2525
var useCache: Boolean = true,
26+
var cacheLimit: Int? = 200,
2627
var automaticRefresh: Boolean = true,
2728
var retryWhenRateLimited: Boolean = false,
2829
var enableLogger: Boolean = false
@@ -69,6 +70,11 @@ class SpotifyApiBuilder(
6970
*/
7071
fun useCache(useCache: Boolean) = apply { this.useCache = useCache }
7172

73+
/**
74+
* Set the maximum allowed amount of cached requests at one time. Null means no limit
75+
*/
76+
fun cacheLimit(cacheLimit: Int?) = apply { this.cacheLimit = cacheLimit }
77+
7278
/**
7379
* Set the application [redirect uri](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
7480
*/
@@ -200,6 +206,7 @@ class SpotifyUserAuthorizationBuilder(
200206
* @property authentication A holder for authentication methods. At least one needs to be provided in order to create
201207
* a **client** api
202208
* @property useCache Set whether to cache requests. Default: true
209+
* @property cacheLimit The maximum amount of cached requests allowed at one time. Null means no limit
203210
* @property automaticRefresh Enable or disable automatic refresh of the Spotify access token
204211
* @property retryWhenRateLimited Set whether to block the current thread and wait until the API can retry the request
205212
* @property enableLogger Set whether to enable to the exception logger
@@ -208,6 +215,7 @@ class SpotifyApiBuilderDsl {
208215
private var credentials: SpotifyCredentials = SpotifyCredentials(null, null, null)
209216
private var authentication = SpotifyUserAuthorizationBuilder()
210217
var useCache: Boolean = true
218+
var cacheLimit: Int? = 200
211219
var automaticRefresh: Boolean = true
212220
var retryWhenRateLimited: Boolean = false
213221
var enableLogger: Boolean = false
@@ -261,7 +269,7 @@ class SpotifyApiBuilderDsl {
261269
return when {
262270
authentication.token != null -> {
263271
SpotifyAppAPI(clientId ?: "not-set", clientSecret
264-
?: "not-set", authentication.token!!, useCache, false, retryWhenRateLimited, enableLogger)
272+
?: "not-set", authentication.token!!, useCache, cacheLimit, false, retryWhenRateLimited, enableLogger)
265273
}
266274
authentication.tokenString != null -> {
267275
SpotifyAppAPI(
@@ -272,6 +280,7 @@ class SpotifyApiBuilderDsl {
272280
60000, null, null
273281
),
274282
useCache,
283+
cacheLimit,
275284
automaticRefresh,
276285
retryWhenRateLimited,
277286
enableLogger
@@ -280,7 +289,7 @@ class SpotifyApiBuilderDsl {
280289
else -> try {
281290
if (clientId == null || clientSecret == null) throw IllegalArgumentException("Illegal credentials provided")
282291
val token = getCredentialedToken(clientId, clientSecret, null)
283-
SpotifyAppAPI(clientId, clientSecret, token, useCache, automaticRefresh, retryWhenRateLimited, enableLogger)
292+
SpotifyAppAPI(clientId, clientSecret, token, useCache, cacheLimit, automaticRefresh, retryWhenRateLimited, enableLogger)
284293
} catch (e: Exception) {
285294
throw SpotifyException("Invalid credentials provided in the login process", e)
286295
}
@@ -337,7 +346,8 @@ class SpotifyApiBuilderDsl {
337346
val response = executeTokenRequest(HttpConnection(
338347
url = "https://accounts.spotify.com/api/token",
339348
method = HttpRequestMethod.POST,
340-
body = "grant_type=authorization_code&code=$authorizationCode&redirect_uri=$redirectUri",
349+
bodyMap = null,
350+
bodyString = "grant_type=authorization_code&code=$authorizationCode&redirect_uri=$redirectUri",
341351
contentType = "application/x-www-form-urlencoded",
342352
api = null
343353
), clientId, clientSecret)
@@ -349,6 +359,7 @@ class SpotifyApiBuilderDsl {
349359
automaticRefresh,
350360
redirectUri ?: throw IllegalArgumentException(),
351361
useCache,
362+
cacheLimit,
352363
retryWhenRateLimited,
353364
enableLogger
354365
)
@@ -362,6 +373,7 @@ class SpotifyApiBuilderDsl {
362373
automaticRefresh,
363374
redirectUri ?: "not-set",
364375
useCache,
376+
cacheLimit,
365377
retryWhenRateLimited,
366378
enableLogger
367379
)
@@ -378,6 +390,7 @@ class SpotifyApiBuilderDsl {
378390
false,
379391
redirectUri ?: "not-set",
380392
useCache,
393+
cacheLimit,
381394
retryWhenRateLimited,
382395
enableLogger
383396
)

0 commit comments

Comments
 (0)