Skip to content

Commit 3ef3ba4

Browse files
committed
use ktlint to standardize code style
Signed-off-by: Adam Ratzman <adam@adamratzman.com>
1 parent 0925e31 commit 3ef3ba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+750
-205
lines changed

build.gradle

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1+
plugins {
2+
id "com.diffplug.gradle.spotless" version "3.16.0"
3+
id "base"
4+
id "io.codearte.nexus-staging" version "0.12.0"
5+
id "com.bmuschko.nexus" version "2.3.1"
6+
id "org.jetbrains.kotlin.jvm" version "1.3.11"
7+
}
8+
19
group 'com.adamratzman'
210
version '2.0.0'
311

4-
buildscript {
5-
ext.kotlin_version = '1.3.11'
6-
7-
repositories {
8-
mavenCentral()
9-
jcenter()
10-
}
11-
dependencies {
12-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13-
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
14-
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
15-
}
16-
}
17-
apply plugin: 'java'
18-
apply plugin: 'kotlin'
19-
apply plugin: 'base'
20-
apply plugin: 'com.bmuschko.nexus'
21-
apply plugin: 'io.codearte.nexus-staging'
22-
2312
archivesBaseName = 'spotify-api-kotlin'
2413

2514
sourceCompatibility = 1.8
@@ -35,23 +24,31 @@ dependencies {
3524
implementation('org.jsoup:jsoup:1.10.3')
3625
implementation("com.google.code.gson:gson:2.8.1")
3726

38-
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
39-
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.0"
27+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11"
28+
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.11"
4029

4130
// Spek testing requirements
42-
testImplementation ('org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1') {
31+
testImplementation('org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1') {
4332
exclude group: 'org.jetbrains.kotlin'
4433
}
45-
testRuntimeOnly ('org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1') {
34+
testRuntimeOnly('org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1') {
4635
exclude group: 'org.junit.platform'
4736
exclude group: 'org.jetbrains.kotlin'
4837
}
4938

5039
testImplementation('org.junit.jupiter:junit-jupiter-api:5.2.0')
5140
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
52-
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
41+
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:1.3.11"
5342
}
5443

44+
spotless {
45+
kotlin {
46+
ktlint()
47+
licenseHeader '/* Created by Adam Ratzman (2018) */' // License header
48+
}
49+
}
50+
51+
5552
test {
5653
systemProperties project.properties.subMap(
5754
["clientId", "clientSecret", "spotifyTokenString", "spotifyRedirectUri"]

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientFollowingAPI.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.endpoints.public.FollowingAPI
45
import com.adamratzman.spotify.main.SpotifyAPI
56
import com.adamratzman.spotify.main.SpotifyClientAPI
67
import com.adamratzman.spotify.main.SpotifyRestAction
78
import com.adamratzman.spotify.main.SpotifyRestPagingAction
8-
import com.adamratzman.spotify.utils.*
9+
import com.adamratzman.spotify.utils.Artist
10+
import com.adamratzman.spotify.utils.ArtistURI
11+
import com.adamratzman.spotify.utils.CursorBasedPagingObject
12+
import com.adamratzman.spotify.utils.EndpointBuilder
13+
import com.adamratzman.spotify.utils.PlaylistURI
14+
import com.adamratzman.spotify.utils.SpotifyPublicUser
15+
import com.adamratzman.spotify.utils.UserURI
16+
import com.adamratzman.spotify.utils.encode
17+
import com.adamratzman.spotify.utils.toCursorBasedPagingObject
18+
import com.adamratzman.spotify.utils.toObject
919
import java.util.function.Supplier
1020

1121
/**
@@ -158,7 +168,6 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
158168
put(EndpointBuilder("/playlists/${PlaylistURI(playlist).id}/followers").toString(), "{\"public\": $followPublicly}")
159169
Unit
160170
})
161-
162171
}
163172

164173
/**

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientLibraryAPI.kt

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.main.SpotifyAPI
45
import com.adamratzman.spotify.main.SpotifyRestAction
56
import com.adamratzman.spotify.main.SpotifyRestPagingAction
6-
import com.adamratzman.spotify.utils.*
7+
import com.adamratzman.spotify.utils.AlbumURI
8+
import com.adamratzman.spotify.utils.EndpointBuilder
9+
import com.adamratzman.spotify.utils.Market
10+
import com.adamratzman.spotify.utils.PagingObject
11+
import com.adamratzman.spotify.utils.SavedAlbum
12+
import com.adamratzman.spotify.utils.SavedTrack
13+
import com.adamratzman.spotify.utils.SpotifyEndpoint
14+
import com.adamratzman.spotify.utils.TrackURI
15+
import com.adamratzman.spotify.utils.encode
16+
import com.adamratzman.spotify.utils.toObject
17+
import com.adamratzman.spotify.utils.toPagingObject
718
import java.util.function.Supplier
819

920
/**
@@ -15,10 +26,16 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
1526
*
1627
* @return Paging Object of [SavedTrack] ordered by position in library
1728
*/
18-
fun getSavedTracks(limit: Int? = null, offset: Int? = null, market: Market? = null): SpotifyRestPagingAction<SavedTrack, PagingObject<SavedTrack>> {
29+
fun getSavedTracks(
30+
limit: Int? = null,
31+
offset: Int? = null,
32+
market: Market? = null
33+
): SpotifyRestPagingAction<SavedTrack, PagingObject<SavedTrack>> {
1934
return toPagingObjectAction(Supplier {
20-
get(EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.code)
21-
.toString()).toPagingObject(endpoint = this, tClazz = SavedTrack::class.java)
35+
get(
36+
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.code)
37+
.toString()
38+
).toPagingObject(endpoint = this, tClazz = SavedTrack::class.java)
2239
})
2340
}
2441

@@ -27,10 +44,16 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2744
*
2845
* @return Paging Object of [SavedAlbum] ordered by position in library
2946
*/
30-
fun getSavedAlbums(limit: Int? = null, offset: Int? = null, market: Market? = null): SpotifyRestPagingAction<SavedAlbum, PagingObject<SavedAlbum>> {
47+
fun getSavedAlbums(
48+
limit: Int? = null,
49+
offset: Int? = null,
50+
market: Market? = null
51+
): SpotifyRestPagingAction<SavedAlbum, PagingObject<SavedAlbum>> {
3152
return toPagingObjectAction(Supplier {
32-
get(EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.code)
33-
.toString()).toPagingObject(endpoint = this, tClazz = SavedAlbum::class.java)
53+
get(
54+
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.code)
55+
.toString()
56+
).toPagingObject(endpoint = this, tClazz = SavedAlbum::class.java)
3457
})
3558
}
3659

@@ -52,8 +75,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5275
*/
5376
fun contains(type: LibraryType, vararg ids: String): SpotifyRestAction<List<Boolean>> {
5477
return toAction(Supplier {
55-
get(EndpointBuilder("/me/$type/contains").with("ids", ids.joinToString(",") { type.id(it).encode() })
56-
.toString()).toObject(api, mutableListOf<Boolean>().javaClass).toList()
78+
get(
79+
EndpointBuilder("/me/$type/contains").with("ids", ids.joinToString(",") { type.id(it).encode() })
80+
.toString()
81+
).toObject(api, mutableListOf<Boolean>().javaClass).toList()
5782
})
5883
}
5984

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPersonalizationAPI.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.main.SpotifyAPI
45
import com.adamratzman.spotify.main.SpotifyRestPagingAction
5-
import com.adamratzman.spotify.utils.*
6+
import com.adamratzman.spotify.utils.Artist
7+
import com.adamratzman.spotify.utils.EndpointBuilder
8+
import com.adamratzman.spotify.utils.PagingObject
9+
import com.adamratzman.spotify.utils.SpotifyEndpoint
10+
import com.adamratzman.spotify.utils.Track
11+
import com.adamratzman.spotify.utils.toPagingObject
612
import java.util.function.Supplier
713

814
/**
@@ -52,5 +58,4 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5258
.with("time_range", timeRange).toString()).toPagingObject(endpoint = this, tClazz = Track::class.java)
5359
})
5460
}
55-
5661
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlayerAPI.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.main.SpotifyAPI
45
import com.adamratzman.spotify.main.SpotifyRestAction
56
import com.adamratzman.spotify.main.SpotifyRestPagingAction
6-
import com.adamratzman.spotify.utils.*
7+
import com.adamratzman.spotify.utils.AlbumURI
8+
import com.adamratzman.spotify.utils.ArtistURI
9+
import com.adamratzman.spotify.utils.BadRequestException
10+
import com.adamratzman.spotify.utils.CurrentlyPlayingContext
11+
import com.adamratzman.spotify.utils.CurrentlyPlayingObject
12+
import com.adamratzman.spotify.utils.CursorBasedPagingObject
13+
import com.adamratzman.spotify.utils.Device
14+
import com.adamratzman.spotify.utils.EndpointBuilder
15+
import com.adamratzman.spotify.utils.PlayHistory
16+
import com.adamratzman.spotify.utils.PlaylistURI
17+
import com.adamratzman.spotify.utils.SpotifyEndpoint
18+
import com.adamratzman.spotify.utils.TrackURI
19+
import com.adamratzman.spotify.utils.encode
20+
import com.adamratzman.spotify.utils.toCursorBasedPagingObject
21+
import com.adamratzman.spotify.utils.toInnerObject
22+
import com.adamratzman.spotify.utils.toObject
723
import org.json.JSONObject
824
import java.util.function.Supplier
925

@@ -102,8 +118,15 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
102118
*
103119
* @throws BadRequestException if more than one type of play type is specified or the offset is illegal.
104120
*/
105-
fun startPlayback(album: String? = null, artist: String? = null, playlist: PlaylistURI? = null,
106-
offsetNum: Int? = null, offsetTrackId: String? = null, deviceId: String? = null, vararg tracksToPlay: String): SpotifyRestAction<Unit> {
121+
fun startPlayback(
122+
album: String? = null,
123+
artist: String? = null,
124+
playlist: PlaylistURI? = null,
125+
offsetNum: Int? = null,
126+
offsetTrackId: String? = null,
127+
deviceId: String? = null,
128+
vararg tracksToPlay: String
129+
): SpotifyRestAction<Unit> {
107130
return toAction(Supplier {
108131
val url = EndpointBuilder("/me/player/play").with("device_id", deviceId).toString()
109132
val body = JSONObject()

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlaylistAPI.kt

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.endpoints.public.PlaylistsAPI
45
import com.adamratzman.spotify.main.SpotifyAPI
56
import com.adamratzman.spotify.main.SpotifyClientAPI
67
import com.adamratzman.spotify.main.SpotifyRestAction
78
import com.adamratzman.spotify.main.SpotifyRestPagingAction
8-
import com.adamratzman.spotify.utils.*
9+
import com.adamratzman.spotify.utils.BadRequestException
10+
import com.adamratzman.spotify.utils.EndpointBuilder
11+
import com.adamratzman.spotify.utils.ErrorObject
12+
import com.adamratzman.spotify.utils.PagingObject
13+
import com.adamratzman.spotify.utils.Playlist
14+
import com.adamratzman.spotify.utils.PlaylistURI
15+
import com.adamratzman.spotify.utils.SimplePlaylist
16+
import com.adamratzman.spotify.utils.TrackURI
17+
import com.adamratzman.spotify.utils.UserURI
18+
import com.adamratzman.spotify.utils.encode
19+
import com.adamratzman.spotify.utils.toObject
20+
import com.adamratzman.spotify.utils.toPagingObject
921
import org.json.JSONObject
1022
import java.awt.image.BufferedImage
1123
import java.io.ByteArrayOutputStream
@@ -16,7 +28,6 @@ import javax.imageio.IIOException
1628
import javax.imageio.ImageIO
1729
import javax.xml.bind.DatatypeConverter
1830

19-
2031
/**
2132
* Endpoints for retrieving information about a user’s playlists and for managing a user’s playlists.
2233
*/
@@ -36,15 +47,24 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
3647
*
3748
* @return The created [Playlist] object with no tracks
3849
*/
39-
fun createPlaylist(name: String, description: String? = null, public: Boolean? = null, collaborative: Boolean? = null, user: String = (api as SpotifyClientAPI).userId): SpotifyRestAction<Playlist> {
50+
fun createPlaylist(
51+
name: String,
52+
description: String? = null,
53+
public: Boolean? = null,
54+
collaborative: Boolean? = null,
55+
user: String = (api as SpotifyClientAPI).userId
56+
): SpotifyRestAction<Playlist> {
4057
if (name.isEmpty()) throw BadRequestException(ErrorObject(400, "Name cannot be empty"))
4158
return toAction(Supplier {
4259
val json = JSONObject()
4360
json.put("name", name)
4461
if (description != null) json.put("description", description)
4562
if (public != null) json.put("public", public)
4663
if (collaborative != null) json.put("collaborative", collaborative)
47-
post(EndpointBuilder("/users/${UserURI(user).id.encode()}/playlists").toString(), json.toString()).toObject(api, Playlist::class.java)
64+
post(EndpointBuilder("/users/${UserURI(user).id.encode()}/playlists").toString(), json.toString()).toObject(
65+
api,
66+
Playlist::class.java
67+
)
4868
})
4969
}
5070

@@ -81,8 +101,13 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
81101
*
82102
* @throws BadRequestException if the playlist is not found or parameters exceed the max length
83103
*/
84-
fun changePlaylistDescription(playlist: String, name: String? = null, public: Boolean? = null, collaborative: Boolean? = null,
85-
description: String? = null): SpotifyRestAction<Unit> {
104+
fun changePlaylistDescription(
105+
playlist: String,
106+
name: String? = null,
107+
public: Boolean? = null,
108+
collaborative: Boolean? = null,
109+
description: String? = null
110+
): SpotifyRestAction<Unit> {
86111
val json = JSONObject()
87112
if (name != null) json.put("name", name)
88113
if (public != null) json.put("public", public)
@@ -103,12 +128,15 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
103128
*
104129
* @throws BadRequestException if the filters provided are illegal
105130
*/
106-
fun getClientPlaylists(limit: Int? = null, offset: Int? = null): SpotifyRestPagingAction<SimplePlaylist, PagingObject<SimplePlaylist>> {
131+
fun getClientPlaylists(
132+
limit: Int? = null,
133+
offset: Int? = null
134+
): SpotifyRestPagingAction<SimplePlaylist, PagingObject<SimplePlaylist>> {
107135
if (limit != null && limit !in 1..50) throw IllegalArgumentException("Limit must be between 1 and 50. Provided $limit")
108136
if (offset != null && offset !in 0..100000) throw IllegalArgumentException("Offset must be between 0 and 100,000. Provided $limit")
109137
return toPagingObjectAction(Supplier {
110138
get(EndpointBuilder("/me/playlists").with("limit", limit).with("offset", offset).toString())
111-
.toPagingObject(endpoint = this, tClazz = SimplePlaylist::class.java)
139+
.toPagingObject(endpoint = this, tClazz = SimplePlaylist::class.java)
112140
})
113141
}
114142

@@ -156,16 +184,21 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
156184
*
157185
* @throws BadRequestException if the playlist is not found or illegal filters are applied
158186
*/
159-
fun reorderTracks(playlist: String, reorderRangeStart: Int, reorderRangeLength: Int? = null, insertionPoint: Int,
160-
snapshotId: String? = null): SpotifyRestAction<Snapshot> {
187+
fun reorderTracks(
188+
playlist: String,
189+
reorderRangeStart: Int,
190+
reorderRangeLength: Int? = null,
191+
insertionPoint: Int,
192+
snapshotId: String? = null
193+
): SpotifyRestAction<Snapshot> {
161194
return toAction(Supplier {
162195
val json = JSONObject()
163196
json.put("range_start", reorderRangeStart)
164197
json.put("insert_before", insertionPoint)
165198
if (reorderRangeLength != null) json.put("range_length", reorderRangeLength)
166199
if (snapshotId != null) json.put("snapshot_id", snapshotId)
167200
put(EndpointBuilder("/playlists/${PlaylistURI(playlist).id.encode()}/tracks").toString(), json.toString())
168-
.toObject(api, Snapshot::class.java)
201+
.toObject(api, Snapshot::class.java)
169202
})
170203
}
171204

@@ -213,9 +246,14 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
213246
* @throws IIOException if the image is not found
214247
* @throws BadRequestException if invalid data is provided
215248
*/
216-
fun uploadPlaylistCover(playlist: String, imagePath: String? = null,
217-
imageFile: File? = null, image: BufferedImage? = null, imageData: String? = null,
218-
imageUrl: String? = null): SpotifyRestAction<Unit> {
249+
fun uploadPlaylistCover(
250+
playlist: String,
251+
imagePath: String? = null,
252+
imageFile: File? = null,
253+
image: BufferedImage? = null,
254+
imageData: String? = null,
255+
imageUrl: String? = null
256+
): SpotifyRestAction<Unit> {
219257
return toAction(Supplier {
220258
val data = imageData ?: when {
221259
image != null -> encode(image)
@@ -224,8 +262,10 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistsAPI(api) {
224262
imagePath != null -> encode(ImageIO.read(URL("file:///$imagePath")))
225263
else -> throw IllegalArgumentException("No cover image was specified")
226264
}
227-
put(EndpointBuilder("/playlists/${PlaylistURI(playlist).id.encode()}/images").toString(),
228-
data, contentType = "image/jpeg")
265+
put(
266+
EndpointBuilder("/playlists/${PlaylistURI(playlist).id.encode()}/images").toString(),
267+
data, contentType = "image/jpeg"
268+
)
229269
Unit
230270
})
231271
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientUserAPI.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Created by Adam Ratzman (2018) */
12
package com.adamratzman.spotify.endpoints.client
23

34
import com.adamratzman.spotify.endpoints.public.UserAPI

0 commit comments

Comments
 (0)