Skip to content

Commit 200fc53

Browse files
committed
Added: Search API : search for a specific item
1 parent ccbb229 commit 200fc53

File tree

9 files changed

+359
-0
lines changed

9 files changed

+359
-0
lines changed

src/main/java/Client/SpotifyClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class SpotifyClient extends SpotifyRestAPI{
2323
private Show show;
2424
private Player player;
2525
private Playlist playlist;
26+
private Item item;
2627

2728
public SpotifyClient(){
2829
super();
@@ -44,6 +45,7 @@ public SpotifyClient(String apiKey, String secretKey) throws IOException {
4445
this.show = new Show();
4546
this.player = new Player();
4647
this.playlist = new Playlist();
48+
this.item = new Item();
4749
}
4850

4951
public SpotifyClient(String apiKey, String secretKey, String token){
@@ -60,6 +62,15 @@ public SpotifyClient(String apiKey, String secretKey, String token){
6062
this.show = new Show();
6163
this.player = new Player();
6264
this.playlist = new Playlist();
65+
this.item = new Item();
66+
}
67+
68+
public Item getItem() {
69+
return item;
70+
}
71+
72+
public void setItem(Item items) {
73+
this.item = items;
6374
}
6475

6576
public Playlist getPlaylist() {

src/main/java/Client/SpotifyRestAPI.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import Controller.BrowseController.Recommendations.BaseRecommendation;
1313
import Controller.BrowseController.Recommendations.RecommendationGenreList;
1414
import Controller.EpisodeController.BaseEpisode;
15+
import Controller.ItemController.BaseItem;
1516
import Controller.LibraryController.BaseTrack;
1617
import Controller.LibraryController.Show.BaseShow;
1718
import Controller.MarketController.Market;
@@ -1499,7 +1500,24 @@ public boolean uploadCustomPlaylistImage(SpotifyClient client) throws IOExceptio
14991500
15001501
*************************************************************************/
15011502

1503+
public BaseItem searchForItem(SpotifyClient client) throws IOException {
15021504

1505+
String url = baseUrl + "/v1/search/";
1506+
1507+
Retrofit retrofit = new Retrofit.Builder()
1508+
.baseUrl(url)
1509+
.addConverterFactory(GsonConverterFactory.create())
1510+
.build();
1511+
1512+
searchInterface searchInterface = retrofit.create(Model.searchInterface.class);
1513+
1514+
Call<BaseItem> call = searchInterface.searchForAnItem(getTokenString(client.getToken()),client.getItem().getQueryType(),client.getItem().convertItemTypes());
1515+
1516+
Response<BaseItem> response = call.execute();
1517+
1518+
return response.body();
1519+
1520+
}
15031521

15041522

15051523

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package Controller.ItemController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
public class Artists {
9+
10+
@SerializedName("href")
11+
@Expose
12+
private String href;
13+
@SerializedName("items")
14+
@Expose
15+
private List<Item> items = null;
16+
@SerializedName("limit")
17+
@Expose
18+
private Integer limit;
19+
@SerializedName("next")
20+
@Expose
21+
private Object next;
22+
@SerializedName("offset")
23+
@Expose
24+
private Integer offset;
25+
@SerializedName("previous")
26+
@Expose
27+
private Object previous;
28+
@SerializedName("total")
29+
@Expose
30+
private Integer total;
31+
32+
public String getHref() {
33+
return href;
34+
}
35+
36+
public void setHref(String href) {
37+
this.href = href;
38+
}
39+
40+
public List<Item> getItems() {
41+
return items;
42+
}
43+
44+
public void setItems(List<Item> items) {
45+
this.items = items;
46+
}
47+
48+
public Integer getLimit() {
49+
return limit;
50+
}
51+
52+
public void setLimit(Integer limit) {
53+
this.limit = limit;
54+
}
55+
56+
public Object getNext() {
57+
return next;
58+
}
59+
60+
public void setNext(Object next) {
61+
this.next = next;
62+
}
63+
64+
public Integer getOffset() {
65+
return offset;
66+
}
67+
68+
public void setOffset(Integer offset) {
69+
this.offset = offset;
70+
}
71+
72+
public Object getPrevious() {
73+
return previous;
74+
}
75+
76+
public void setPrevious(Object previous) {
77+
this.previous = previous;
78+
}
79+
80+
public Integer getTotal() {
81+
return total;
82+
}
83+
84+
public void setTotal(Integer total) {
85+
this.total = total;
86+
}
87+
88+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Controller.ItemController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class BaseItem {
7+
8+
@SerializedName("artists")
9+
@Expose
10+
private Artists artists;
11+
12+
public Artists getArtists() {
13+
return artists;
14+
}
15+
16+
public void setArtists(Artists artists) {
17+
this.artists = artists;
18+
}
19+
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Controller.ItemController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class ExternalUrls {
7+
8+
@SerializedName("spotify")
9+
@Expose
10+
private String spotify;
11+
12+
public String getSpotify() {
13+
return spotify;
14+
}
15+
16+
public void setSpotify(String spotify) {
17+
this.spotify = spotify;
18+
}
19+
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package Controller.ItemController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class Image {
7+
8+
@SerializedName("height")
9+
@Expose
10+
private Integer height;
11+
@SerializedName("url")
12+
@Expose
13+
private String url;
14+
@SerializedName("width")
15+
@Expose
16+
private Integer width;
17+
18+
public Integer getHeight() {
19+
return height;
20+
}
21+
22+
public void setHeight(Integer height) {
23+
this.height = height;
24+
}
25+
26+
public String getUrl() {
27+
return url;
28+
}
29+
30+
public void setUrl(String url) {
31+
this.url = url;
32+
}
33+
34+
public Integer getWidth() {
35+
return width;
36+
}
37+
38+
public void setWidth(Integer width) {
39+
this.width = width;
40+
}
41+
42+
43+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package Controller.ItemController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
public class Item {
9+
10+
@SerializedName("external_urls")
11+
@Expose
12+
private ExternalUrls externalUrls;
13+
@SerializedName("genres")
14+
@Expose
15+
private List<Object> genres = null;
16+
@SerializedName("href")
17+
@Expose
18+
private String href;
19+
@SerializedName("id")
20+
@Expose
21+
private String id;
22+
@SerializedName("images")
23+
@Expose
24+
private List<Image> images = null;
25+
@SerializedName("name")
26+
@Expose
27+
private String name;
28+
@SerializedName("popularity")
29+
@Expose
30+
private Integer popularity;
31+
@SerializedName("type")
32+
@Expose
33+
private String type;
34+
@SerializedName("uri")
35+
@Expose
36+
private String uri;
37+
38+
public ExternalUrls getExternalUrls() {
39+
return externalUrls;
40+
}
41+
42+
public void setExternalUrls(ExternalUrls externalUrls) {
43+
this.externalUrls = externalUrls;
44+
}
45+
46+
public List<Object> getGenres() {
47+
return genres;
48+
}
49+
50+
public void setGenres(List<Object> genres) {
51+
this.genres = genres;
52+
}
53+
54+
public String getHref() {
55+
return href;
56+
}
57+
58+
public void setHref(String href) {
59+
this.href = href;
60+
}
61+
62+
public String getId() {
63+
return id;
64+
}
65+
66+
public void setId(String id) {
67+
this.id = id;
68+
}
69+
70+
public List<Image> getImages() {
71+
return images;
72+
}
73+
74+
public void setImages(List<Image> images) {
75+
this.images = images;
76+
}
77+
78+
public String getName() {
79+
return name;
80+
}
81+
82+
public void setName(String name) {
83+
this.name = name;
84+
}
85+
86+
public Integer getPopularity() {
87+
return popularity;
88+
}
89+
90+
public void setPopularity(Integer popularity) {
91+
this.popularity = popularity;
92+
}
93+
94+
public String getType() {
95+
return type;
96+
}
97+
98+
public void setType(String type) {
99+
this.type = type;
100+
}
101+
102+
public String getUri() {
103+
return uri;
104+
}
105+
106+
public void setUri(String uri) {
107+
this.uri = uri;
108+
}
109+
110+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package Model;
2+
3+
import Controller.ItemController.BaseItem;
4+
import retrofit2.Call;
5+
import retrofit2.http.GET;
6+
import retrofit2.http.Header;
7+
import retrofit2.http.Query;
8+
9+
public interface searchInterface {
10+
11+
@GET("https://api.spotify.com/v1/search")
12+
Call<BaseItem> searchForAnItem(@Header("Authorization") String auth, @Query("q") String q, @Query("type") String type);
13+
14+
}

0 commit comments

Comments
 (0)