Skip to content

Commit 1758467

Browse files
authored
Merge pull request #15 from Gruncan/v1.3.0
V1.3.0a
2 parents 1546d17 + 792806f commit 1758467

60 files changed

Lines changed: 1969 additions & 301 deletions

Some content is hidden

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

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.spotstat</groupId>
99
<artifactId>S4J</artifactId>
10-
<version>1.1.2a</version>
10+
<version>1.2.0a</version>
1111

1212
<properties>
1313
<maven.compiler.source>17</maven.compiler.source>

src/main/HowRequestsWork.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
## Want to add your own request? and serialize them into objects?
2+
3+
1. Simply create a new class with any name you want
4+
2. Make `AbstractRequest` its super class
5+
6+
```java
7+
public class MyClass extends AbstractRequest {
8+
}
9+
```
10+
11+
3. Annotated it with
12+
13+
```Java
14+
@SpotifyRequest("<request>")
15+
```
16+
17+
replacing `<request>` with the request you are wanting to call E.g. It will be evaluated
18+
as `"https://api.spotify.com/v1/<request>"`
19+
20+
So for `<request> = albums`,
21+
22+
```java
23+
24+
@SpotifyRequest("albums")
25+
public class MyClass extends AbstractRequest {
26+
}
27+
```
28+
29+
the url will be `"https://api.spotify.com/v1/albums"`
30+
31+
4. If there are variables within the URL like `"https://api.spotify.com/v1/albums/{id}"`
32+
33+
Add `@SpotifySubRequest` to the required field
34+
35+
```java
36+
@SpotifyRequest("albums")
37+
public class MyClass extends AbstractRequest {
38+
39+
@SpotifySubRequest
40+
private final String id;
41+
}
42+
```
43+
44+
(For SubRequest annotated fields, they will be evaluated in order of declaration in the class, therefore **order
45+
matters**)
46+
47+
5. For parameters within the url like `https://api.spotify.com/v1/albums/{id}?parameter=value`
48+
49+
Add `@SpotifyRequestField` to the required fields
50+
51+
```java
52+
@SpotifyRequest("albums")
53+
public class MyClass extends AbstractRequest {
54+
55+
@SpotifySubRequest
56+
private final String id;
57+
58+
@SpotifyRequestField
59+
private Market market;
60+
}
61+
```
62+
63+
Where `parameter = market`, the field name. The `value` is the value within the specific field
64+
65+
So for
66+
67+
```java
68+
@SpotifyRequest("albums")
69+
public class MyClass extends AbstractRequest {
70+
71+
@SpotifySubRequest
72+
private final String id = "382ObEPsp2rxGrnsizN5TX";
73+
74+
@SpotifyRequestField
75+
private Market market = Market.ES;
76+
}
77+
```
78+
79+
the url will be evaluated as `https://api.spotify.com/v1/albums/382ObEPsp2rxGrnsizN5TX?market=ES`
80+
81+
Fields with types other than String will call `toString`
82+
83+
Fields with the type of array, the array contents will be put into a comma seperated list of their respected string
84+
contents.
85+
86+
(RequestField will again be evaluated in order of declaration within the class however order doesn't matter with url
87+
parameters)
88+
89+
and finally to execute the request, after creating a SpotifyClient instance,
90+
91+
```java
92+
MyClass myClass=new MyClass();
93+
SpotifyRepsonse sr=spotifyClient.executeRequest(myClass);
94+
JSONObject json=sr.getJsonObject();
95+
```

src/main/java/com/spotify/SpotifyResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public SpotifyResponse(RequestResponse response, Class<? extends SpotifyObject>
2727

2828
}
2929

30-
public RequestResponse getRequestResponse() {
31-
return this.requestResponse;
30+
public JSONObject getJsonObject() {
31+
return this.requestResponse.ok();
3232
}
3333

3434
@SuppressWarnings("unchecked")

src/main/java/com/spotify/objects/SpotifySerializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ else if (jsonPath == null || jsonPath.isNull(name))
8383
Class<?> componentRawType = fieldType.getComponentType();
8484
Class<? extends Serializable> componentType = (Class<? extends Serializable>) componentRawType;
8585

86-
8786
JSONArray jsonArray = jsonPath.getJSONArray(name);
8887
field.set(e, this.createArray(componentType, jsonArray));
8988
} else {

src/main/java/com/spotify/objects/tracks/Album.java renamed to src/main/java/com/spotify/objects/albums/Album.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package com.spotify.objects.tracks;
1+
package com.spotify.objects.albums;
22

33
import com.spotify.objects.SpotifyField;
44
import com.spotify.objects.SpotifyObject;
55
import com.spotify.objects.SpotifyOptional;
6+
import com.spotify.objects.artists.SimplifiedArtist;
67
import com.spotify.objects.wrappers.Market;
78
import com.spotify.objects.wrappers.SpotifyCopyright;
89
import com.spotify.objects.wrappers.SpotifyExternalID;
@@ -23,6 +24,7 @@ public class Album implements SpotifyObject {
2324
@SpotifyField("total_tracks")
2425
private int totalTracks;
2526

27+
@SpotifyOptional
2628
@SpotifyField("available_markets")
2729
private Market[] markets;
2830

@@ -90,7 +92,7 @@ public String toString() {
9092
return "Album{" +
9193
"albumType='" + albumType + '\'' +
9294
", totalTracks=" + totalTracks +
93-
", markets=" + markets.length +
95+
", markets=" + (this.markets != null ? String.valueOf(markets.length) : "null") +
9496
", externalIDs='" + externalIDs + '\'' +
9597
", href='" + href + '\'' +
9698
", id='" + id + '\'' +

src/main/java/com/spotify/objects/tracks/Artist.java renamed to src/main/java/com/spotify/objects/artists/Artist.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package com.spotify.objects.tracks;
1+
package com.spotify.objects.artists;
22

33
import com.spotify.objects.SpotifyField;
4-
import com.spotify.objects.SpotifyObject;
54
import com.spotify.objects.SpotifyOptional;
65
import com.spotify.objects.wrappers.SpotifyImage;
76
import lombok.Getter;
@@ -11,22 +10,19 @@
1110

1211
@Getter
1312
@Setter
14-
public class Artist extends SimplifiedArtist implements SpotifyObject {
13+
@SpotifyOptional
14+
public class Artist extends SimplifiedArtist {
1515

1616

17-
@SpotifyOptional
1817
@SpotifyField(value = "total", path = {"followers"})
1918
private int followers;
2019

21-
@SpotifyOptional
2220
@SpotifyField
2321
private String[] genres;
2422

25-
@SpotifyOptional
2623
@SpotifyField
2724
private SpotifyImage[] images;
2825

29-
@SpotifyOptional
3026
@SpotifyField
3127
private int popularity;
3228

src/main/java/com/spotify/objects/tracks/SimplifiedArtist.java renamed to src/main/java/com/spotify/objects/artists/SimplifiedArtist.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.spotify.objects.tracks;
1+
package com.spotify.objects.artists;
22

33
import com.spotify.objects.SpotifyField;
44
import com.spotify.objects.SpotifyObject;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.spotify.objects.audiobooks;
2+
3+
import com.spotify.objects.SpotifyObject;
4+
5+
public class Audiobook implements SpotifyObject {
6+
7+
public Audiobook() {
8+
}
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.spotify.objects.episodes;
2+
3+
import com.spotify.objects.SpotifyObject;
4+
5+
public class Episode implements SpotifyObject {
6+
7+
public Episode() {
8+
}
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.spotify.objects.playlists;
2+
3+
import com.spotify.objects.SpotifyObject;
4+
5+
public class Playlist implements SpotifyObject {
6+
7+
8+
public Playlist() {
9+
}
10+
}

0 commit comments

Comments
 (0)