Skip to content

Commit e46e02c

Browse files
rudrankriyamclaude
andcommitted
Remove unused LibraryItemWrapper and refactor to use existing LibraryMusicItemType
- Remove unused LibraryItemWrapper.swift file - Remove custom MusicItemType enum - Use existing LibraryMusicItemType instead (songs, albums, artists, playlists, musicVideos) - Remove redundant extend=inFavorites query parameters from playlist methods - Update path construction to use rawValue directly (already pluralized) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7014a82 commit e46e02c

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

Sources/MusadoraKit/Library/InFavoritesParser.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77

88
import Foundation
99

10-
/// The type of music item being parsed for inFavorites status.
11-
internal enum MusicItemType: String {
12-
case song
13-
case album
14-
case artist
15-
case playlist
16-
case musicVideo = "music-video"
17-
}
18-
1910
/// Response structure for Apple Music API inFavorites queries.
2011
private struct InFavoritesResponse: Decodable {
2112
let data: [InFavoritesResponseItem]
@@ -51,7 +42,7 @@ internal enum InFavoritesParser {
5142
/// - itemType: The type of music item being parsed
5243
/// - Returns: The inFavorites boolean value
5344
/// - Throws: MusadoraKitError if parsing fails, item not found, not in library, or inFavorites not found
54-
static func parse(from data: Data, itemType: MusicItemType) throws -> Bool {
45+
static func parse(from data: Data, itemType: LibraryMusicItemType) throws -> Bool {
5546
let response = try JSONDecoder().decode(InFavoritesResponse.self, from: data)
5647

5748
guard let item = response.data.first else {
@@ -78,10 +69,10 @@ internal enum InFavoritesParser {
7869
/// - itemType: The type of music item
7970
/// - Returns: `true` if the item is in favorites, `false` otherwise
8071
/// - Throws: An error if the item is not in library or if the request fails
81-
static func fetchInFavorites(for id: MusicItemID, itemType: MusicItemType) async throws -> Bool {
72+
static func fetchInFavorites(for id: MusicItemID, itemType: LibraryMusicItemType) async throws -> Bool {
8273
let storefront = try await MusicDataRequest.currentCountryCode
8374
var components = AppleMusicURLComponents()
84-
components.path = "catalog/\(storefront)/\(itemType.rawValue)s/\(id.rawValue)"
75+
components.path = "catalog/\(storefront)/\(itemType.rawValue)/\(id.rawValue)"
8576
components.queryItems = [
8677
URLQueryItem(name: "relate", value: "library"),
8778
URLQueryItem(name: "extend", value: "inFavorites")

Sources/MusadoraKit/Library/MLibrary+Album.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public extension Album {
226226
var inFavorites: Bool {
227227
get async throws {
228228
let catalogId = try self.catalogID
229-
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .album)
229+
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .albums)
230230
}
231231
}
232232
}

Sources/MusadoraKit/Library/MLibrary+Artist.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public extension Artist {
158158
/// - Throws: An error if the artist is not in library or if the request fails.
159159
var inFavorites: Bool {
160160
get async throws {
161-
return try await InFavoritesParser.fetchInFavorites(for: id, itemType: .artist)
161+
return try await InFavoritesParser.fetchInFavorites(for: id, itemType: .artists)
162162
}
163163
}
164164
}

Sources/MusadoraKit/Library/MLibrary+Playlist.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public extension Playlist {
328328
/// - Throws: An error if the playlist is not in library or if the request fails.
329329
var inFavorites: Bool {
330330
get async throws {
331-
return try await InFavoritesParser.fetchInFavorites(for: id, itemType: .playlist)
331+
return try await InFavoritesParser.fetchInFavorites(for: id, itemType: .playlists)
332332
}
333333
}
334334
}

Sources/MusadoraKit/Library/MLibrary+Song.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ public extension Song {
518518
throw MusadoraKitError.notFound(for: "catalogId")
519519
}
520520

521-
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .song)
521+
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .songs)
522522
}
523523
}
524524
}

Tests/MusadoraKitTests/Library/InFavoritesTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct InFavoritesTests {
2828
"""
2929

3030
let data = try #require(json.data(using: .utf8))
31-
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .song)
31+
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .songs)
3232

3333
#expect(inFavorites == true)
3434
}
@@ -54,7 +54,7 @@ struct InFavoritesTests {
5454
"""
5555

5656
let data = try #require(json.data(using: .utf8))
57-
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .song)
57+
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .songs)
5858

5959
#expect(inFavorites == false)
6060
}
@@ -82,7 +82,7 @@ struct InFavoritesTests {
8282
let data = try #require(json.data(using: .utf8))
8383

8484
#expect(throws: MusadoraKitError.self) {
85-
try InFavoritesParser.parse(from: data, itemType: .song)
85+
try InFavoritesParser.parse(from: data, itemType: .songs)
8686
}
8787
}
8888

@@ -109,7 +109,7 @@ struct InFavoritesTests {
109109
"""
110110

111111
let data = try #require(json.data(using: .utf8))
112-
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .album)
112+
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .albums)
113113

114114
#expect(inFavorites == true)
115115
}
@@ -137,7 +137,7 @@ struct InFavoritesTests {
137137
"""
138138

139139
let data = try #require(json.data(using: .utf8))
140-
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .artist)
140+
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .artists)
141141

142142
#expect(inFavorites == true)
143143
}
@@ -165,7 +165,7 @@ struct InFavoritesTests {
165165
"""
166166

167167
let data = try #require(json.data(using: .utf8))
168-
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .playlist)
168+
let inFavorites = try InFavoritesParser.parse(from: data, itemType: .playlists)
169169

170170
#expect(inFavorites == true)
171171
}
@@ -194,7 +194,7 @@ struct InFavoritesTests {
194194
let data = try #require(json.data(using: .utf8))
195195

196196
#expect(throws: MusadoraKitError.self) {
197-
try InFavoritesParser.parse(from: data, itemType: .song)
197+
try InFavoritesParser.parse(from: data, itemType: .songs)
198198
}
199199
}
200200

@@ -209,7 +209,7 @@ struct InFavoritesTests {
209209
let data = try #require(json.data(using: .utf8))
210210

211211
#expect(throws: MusadoraKitError.self) {
212-
try InFavoritesParser.parse(from: data, itemType: .song)
212+
try InFavoritesParser.parse(from: data, itemType: .songs)
213213
}
214214
}
215215
}

0 commit comments

Comments
 (0)