Skip to content

Commit 77080d2

Browse files
authored
Release 0.5.0 (#6)
* Refactor data provider service to use new request coordinator protocol * Rename catalog resources objects * Improve & restructure overall resources model definitions, project clean up * Add async support to DataProvider class * Fix encapsulation issues * Add macOS API availability definitions * Add async support for search methods * Update README file
1 parent 3cff7fc commit 77080d2

37 files changed

+813
-664
lines changed

README.md

Lines changed: 42 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,146 +32,114 @@ amuseProvider.setUserToken("USER_TOKEN")
3232
amuseProvider.setUserCountryCode("USER_COUNTRY_CODE")
3333
```
3434

35-
### Retrieve multiple Albums from Apple Music catalog by ids.
35+
### Retrieve Apple Music catalog resources by ids.
3636

37-
```swift
38-
amuseProvider.catalog(.albums, ids: ["123", "456", "789"])
39-
.sink { _ in
40-
} receiveValue: { response in
41-
print(response.data)
42-
}
43-
```
44-
45-
### Retrieve multiple Artists from Apple Music catalog by ids.
37+
Supported values are: `albums, artists, musicVideos, playlists, songs`.
4638

4739
```swift
48-
amuseProvider.catalog(.artists, ids: ["123", "456", "789"])
49-
.sink { _ in
50-
} receiveValue: { response in
51-
print(response.data)
52-
}
40+
let response = try await amuseProvider.catalog(.albums, ids: ["123", "456", "789"])
41+
print(response.data)
5342
```
5443

55-
### Retrieve multiple Music Videos from Apple Music catalog by ids.
56-
5744
```swift
58-
amuseProvider.catalog(.musicVideos, ids: ["123", "456", "789"])
59-
.sink { _ in
60-
} receiveValue: { response in
61-
print(response.data)
62-
}
63-
```
64-
65-
### Retrieve multiple Playlists from Apple Music catalog by ids.
66-
67-
```swift
68-
amuseProvider.catalog(.playlists, ids: ["123", "456", "789"])
45+
amuseProvider.catalog(.albums, ids: ["123", "456", "789"])
6946
.sink { _ in
7047
} receiveValue: { response in
7148
print(response.data)
7249
}
7350
```
7451

75-
### Retrieve multiple Songs from Apple Music catalog by ids.
52+
### Search on Apple Music catalog.
7653

7754
```swift
78-
amuseProvider.catalog(.songs, ids: ["123", "456", "789"])
79-
.sink { _ in
80-
} receiveValue: { response in
81-
print(response.data)
82-
}
55+
let response = try await amuseProvider.catalogSearch(searchTerm: "YOUR_QUERY_TEXT")
56+
print(response.results?.albums)
57+
print(response.results?.artists)
58+
print(response.results?.musicVideos)
59+
print(response.results?.playlists)
60+
print(response.results?.songs)
61+
print(response.results?.stations)
8362
```
8463

85-
### Search on Apple Music catalog.
86-
8764
```swift
8865
amuseProvider.catalogSearch(searchTerm: "YOUR_QUERY_TEXT")
8966
.sink { _ in
9067
} receiveValue: { response in
9168
// content will be found under results properties.
9269
print(response.results?.albums)
9370
print(response.results?.artists)
71+
print(response.results?.musicVideos)
9472
print(response.results?.playlists)
9573
print(response.results?.songs)
74+
print(response.results?.stations)
9675
}
9776
```
9877

99-
### Search on Apple Music catalog for specific types.
78+
### Search on Apple Music catalog for specific resources types.
10079

10180
```swift
102-
amuseProvider.catalogSearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
103-
.sink { _ in
104-
} receiveValue: { response in
105-
print(response.results?.playlists)
106-
print(response.results?.songs)
107-
}
81+
let response = try await amuseProvider.catalogSearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
82+
print(response.results?.playlists)
83+
print(response.results?.songs)
10884
```
10985

110-
### Retrieve All User's Library Albums.
111-
11286
```swift
113-
amuseProvider.library(.albums)
87+
amuseProvider.catalogSearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
11488
.sink { _ in
11589
} receiveValue: { response in
116-
print(response.data)
90+
print(response.results?.playlists)
91+
print(response.results?.songs)
11792
}
11893
```
11994

120-
### Retrieve All User's Library Artists.
95+
### Retrieve User Library resources.
12196

122-
```swift
123-
amuseProvider.library(.artists)
124-
.sink { _ in
125-
} receiveValue: { response in
126-
print(response.data)
127-
}
128-
```
129-
130-
### Retrieve All User Library Music Videos.
97+
Supported values are: `albums, artists, musicVideos, playlists, songs`.
13198

13299
```swift
133-
amuseProvider.library(.musicVideos)
134-
.sink { _ in
135-
} receiveValue: { response in
136-
print(response.data)
137-
}
100+
let response = try await dataProvider.library(.albums)
101+
print(response.data)
138102
```
139103

140-
### Retrieve All User's Library Playlists.
141-
142104
```swift
143-
amuseProvider.library(.playlists)
105+
amuseProvider.library(.albums)
144106
.sink { _ in
145107
} receiveValue: { response in
146108
print(response.data)
147109
}
148110
```
149111

150-
### Retrieve All User's Library Songs.
112+
### Search on User Library.
151113

152114
```swift
153-
amuseProvider.library(.songs)
154-
.sink { _ in
155-
} receiveValue: { response in
156-
print(response.data)
157-
}
115+
let response = try await amuseProvider.librarySearch(searchTerm: "YOUR_QUERY_TEXT")
116+
print(response.results?.albums)
117+
print(response.results?.artists)
118+
print(response.results?.musicVideos)
119+
print(response.results?.playlists)
120+
print(response.results?.songs)
158121
```
159122

160-
### Search on User's Library.
161-
162123
```swift
163124
amuseProvider.librarySearch(searchTerm: "YOUR_QUERY_TEXT")
164125
.sink { _ in
165126
} receiveValue: { response in
166127
// content will be found under results properties.
167128
print(response.results?.albums)
168129
print(response.results?.artists)
130+
print(response.results?.musicVideos)
169131
print(response.results?.playlists)
170132
print(response.results?.songs)
171133
}
172134
```
173135

174-
### Search on User's Library for specific types.
136+
### Search on User Library for specific resources types.
137+
138+
```swift
139+
let response = try await amuseProvider.librarySearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
140+
print(response.results?.playlists)
141+
print(response.results?.songs)
142+
```
175143

176144
```swift
177145
amuseProvider.librarySearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")

Sources/AmuseKit/AmuseKit.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77

88
import Foundation
99

10-
protocol AmuseOption: RawRepresentable, Hashable, CaseIterable {}
10+
public enum AmuseKit {}
1111

12-
public class AmuseKit {
13-
enum AmuseError: Error {
14-
case missingDevToken
15-
case missingUserToken
16-
}
12+
enum AmuseKitError: Error {
13+
case missingDevToken
14+
case missingUserToken
1715
}
1816

19-
extension AmuseKit.AmuseError: LocalizedError {
17+
extension AmuseKitError: LocalizedError {
2018
public var errorDescription: String? {
2119
switch self {
2220
case .missingDevToken:
@@ -26,3 +24,4 @@ extension AmuseKit.AmuseError: LocalizedError {
2624
}
2725
}
2826
}
27+

Sources/AmuseKit/Models/Relationship.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ public extension AmuseKit {
1717
public let href: String
1818
public let next: String?
1919
}
20+
21+
typealias CuratorsRelationship = Relationship<CuratorResource>
22+
typealias GenresRelationship = Relationship<GenreResource>
2023

21-
typealias AlbumsRelationship = Relationship<Album>
22-
typealias ArtistsRelationship = Relationship<Artist>
23-
typealias CuratorsRelationship = Relationship<Curator>
24-
typealias GenresRelationship = Relationship<Genre>
25-
typealias MusicVideosRelationship = Relationship<MusicVideo>
26-
typealias PlaylistRelationship = Relationship<Playlist>
27-
typealias SongRelationship = Relationship<Song>
24+
typealias CatalogAlbumsRelationship = Relationship<CatalogAlbum>
25+
typealias CatalogArtistsRelationship = Relationship<CatalogArtist>
26+
typealias CatalogMusicVideosRelationship = Relationship<CatalogMusicVideo>
27+
typealias CatalogPlaylistsRelationship = Relationship<CatalogPlaylist>
28+
typealias CatalogSongsRelationship = Relationship<CatalogSong>
2829

2930
typealias LibraryAlbumsRelationship = Relationship<LibraryAlbum>
3031
typealias LibraryArtistsRelationship = Relationship<LibraryArtist>

Sources/AmuseKit/Models/Resource.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,58 @@ protocol Resource: Codable, Identifiable {
1919
var relationships: Relationships? { get }
2020
var type: String { get }
2121
}
22+
23+
// An object that represents artwork.
24+
// https://developer.apple.com/documentation/applemusicapi/artwork
25+
26+
public struct ResourceArtwork: Codable {
27+
public let bgColor: String?
28+
public let height: Int?
29+
public let width: Int?
30+
public let textColor1: String?
31+
public let textColor2: String?
32+
public let textColor3: String?
33+
public let textColor4: String?
34+
public let url: String
35+
}
36+
37+
public extension ResourceArtwork {
38+
typealias ArtworkSize = (width: Int, height: Int)
39+
/// Returns artwork formatted url for specific size when possible.
40+
/// if `size` parameter is nil `width` & `height` properties will be used as default values for size.
41+
/// if `width` and `height` property are also nil full size image URL will be returned.
42+
func formattedURL(size: ArtworkSize? = nil) -> URL? {
43+
guard let width = size?.width ?? width, let height = size?.height ?? height else {
44+
return URL(string: url)
45+
}
46+
47+
return URL(string: url.replacingOccurrences(of: "{w}x{h}", with: "\(width)x\(height)"))
48+
}
49+
}
50+
51+
// An object that represents notes.
52+
// https://developer.apple.com/documentation/applemusicapi/editorialnotes
53+
54+
public struct ResourceEditorialNotes: Codable {
55+
public var short: String?
56+
public var standard: String?
57+
}
58+
59+
// An object that represents play parameters for resources.
60+
// https://developer.apple.com/documentation/applemusicapi/playparameters
61+
62+
public struct ResourcePlayParameters: Codable {
63+
public let id: String
64+
public let kind: String
65+
public let catalogId: String?
66+
public let isLibrary: Bool?
67+
public let reporting: Bool?
68+
}
69+
70+
// An object that represents a preview for resources.
71+
// https://developer.apple.com/documentation/applemusicapi/preview
72+
73+
public struct ResourcePreview: Codable {
74+
public let artwork: ResourceArtwork?
75+
public let url: String
76+
}

Sources/AmuseKit/Models/Resources/Catalog/Artist.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

Sources/AmuseKit/Models/Resources/Catalog/Curator.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)