-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e879846
commit 4a18b18
Showing
26 changed files
with
833 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Sources/MusadoraLabsKit/Apple Music Endpoint/Albums/AlbumCatalogEndpoint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// AlbumCatalogEndpoint.swift | ||
// AlbumCatalogEndpoint | ||
// | ||
// Created by Rudrank Riyam on 19/04/22. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Requesting Catalog Albums | ||
|
||
public enum AlbumCatalogEndpoint { | ||
case id(id: String) | ||
case ids(ids: [String]) | ||
case upcs(upcs: [String]) | ||
} | ||
|
||
// MARK: - Endpoint | ||
|
||
extension AlbumCatalogEndpoint: Endpoint { | ||
public var name: String { | ||
switch self { | ||
case .id: | ||
return "Get a Catalog Album" | ||
case .ids: | ||
return "Get Multiple Catalog Albums" | ||
case .upcs: | ||
return "Get Multiple Catalog Albums by UPC" | ||
} | ||
} | ||
|
||
public var description: String { | ||
switch self { | ||
case .id: | ||
return "Fetch an album by using its identifier." | ||
case .ids: | ||
return "Fetch one or more albums by using their identifiers." | ||
case .upcs: | ||
return "Fetch one or more albums by using their UPC values." | ||
} | ||
} | ||
|
||
var previewURL: String { | ||
switch self { | ||
case .id: | ||
return "https://api.music.apple.com/v1/catalog/{storefront}/albums/{id}" | ||
case .ids: | ||
return "https://api.music.apple.com/v1/catalog/{storefront}/albums?ids={ids}" | ||
case .upcs: | ||
return "https://api.music.apple.com/v1/catalog/{storefront}/albums?filter[upc]={upcs}" | ||
} | ||
} | ||
|
||
var url: URL { | ||
get async throws { | ||
switch self { | ||
case let .id(id): | ||
return try await MusadoraLabsKit.catalogAlbum(id: id) | ||
case let .ids(ids): | ||
return try await MusadoraLabsKit.catalogAlbums(ids: ids) | ||
case let .upcs(upcs): | ||
return try await MusadoraLabsKit.catalogAlbums(upcs: upcs) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Identifiable | ||
|
||
extension AlbumCatalogEndpoint: Hashable, Identifiable { | ||
public var id: Self { self } | ||
} | ||
|
||
// MARK: - CaseIterable | ||
|
||
extension AlbumCatalogEndpoint: CaseIterable { | ||
public static var allCases: [AlbumCatalogEndpoint] = [.id(id: ""), .ids(ids: []), .upcs(upcs: [])] | ||
} |
41 changes: 41 additions & 0 deletions
41
Sources/MusadoraLabsKit/Apple Music Endpoint/Albums/AlbumEndpointURLs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// AlbumsEndpoint.swift | ||
// AlbumsEndpoint | ||
// | ||
// Created by Rudrank Riyam on 18/04/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension MusadoraLabsKit { | ||
// MARK: - Catalog Albums | ||
|
||
static func catalogAlbum(id: String, storeFront: String? = nil) async throws -> URL { | ||
try await MusadoraLabsKit(library: .catalog, path: MusicItemPath.albums.id(id), storeFront: storeFront).url | ||
} | ||
|
||
static func catalogAlbums(ids: [String], storeFront: String? = nil) async throws -> URL { | ||
let query = URLQueryItem(name: "ids", value: ids.joined(separator: ",")) | ||
return try await MusadoraLabsKit(library: .catalog, path: .albums, storeFront: storeFront, queryItems: [query]).url | ||
} | ||
|
||
static func catalogAlbums(upcs: [String], storeFront: String? = nil) async throws -> URL { | ||
let query = URLQueryItem(name: "filter[upc]", value: upcs.joined(separator: ",")) | ||
return try await MusadoraLabsKit(library: .catalog, path: .albums, storeFront: storeFront, queryItems: [query]).url | ||
} | ||
|
||
// MARK: - Library Albums | ||
|
||
static func libraryAlbum(id: String) async throws -> URL { | ||
try await MusadoraLabsKit(library: .library, path: MusicItemPath.albums.id(id)).url | ||
} | ||
|
||
static func libraryAlbums(ids: [String]) async throws -> URL { | ||
let query = URLQueryItem(name: "ids", value: ids.joined(separator: ",")) | ||
return try await MusadoraLabsKit(library: .library, path: .albums, queryItems: [query]).url | ||
} | ||
|
||
static func libraryAlbums() async throws -> URL { | ||
try await MusadoraLabsKit(library: .library, path: .albums).url | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Sources/MusadoraLabsKit/Apple Music Endpoint/Albums/AlbumLibraryEndpoint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// AlbumLibraryEndpoint.swift | ||
// AlbumLibraryEndpoint | ||
// | ||
// Created by Rudrank Riyam on 20/04/22. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Requesting User Library Albums | ||
|
||
enum AlbumLibraryEndpoint { | ||
case all | ||
case id(id: String) | ||
case ids(ids: [String]) | ||
} | ||
|
||
// MARK: - Endpoint | ||
|
||
extension AlbumLibraryEndpoint: Endpoint { | ||
var name: String { | ||
switch self { | ||
case .all: | ||
return "Get All Library Albums" | ||
case .id: | ||
return "Get a Library Album" | ||
case .ids: | ||
return "Get Multiple Library Albums" | ||
} | ||
} | ||
|
||
var description: String { | ||
switch self { | ||
case .all: | ||
return "Fetch all the library albums in alphabetical order." | ||
case .id: | ||
return "Fetch a library album by using its identifier." | ||
case .ids: | ||
return "Fetch one or more library albums by using their identifiers." | ||
} | ||
} | ||
|
||
var previewURL: String { | ||
switch self { | ||
case .all: | ||
return "https://api.music.apple.com/v1/me/library/albums/{id}" | ||
case .id: | ||
return "https://api.music.apple.com/v1/me/library/albums?ids={ids}" | ||
case .ids: | ||
return "https://api.music.apple.com/v1/me/library/albums" | ||
} | ||
} | ||
|
||
var url: URL { | ||
get async throws { | ||
switch self { | ||
case .all: | ||
return try await MusadoraLabsKit.libraryAlbums() | ||
case let .id(id): | ||
return try await MusadoraLabsKit.libraryAlbum(id: id) | ||
case let .ids(ids): | ||
return try await MusadoraLabsKit.libraryAlbums(ids: ids) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Identifiable | ||
|
||
extension AlbumLibraryEndpoint: Hashable, Identifiable { | ||
public var id: Self { self } | ||
} | ||
|
||
// MARK: - CaseIterable | ||
|
||
// extension AlbumLibraryEndpoint: CaseIterable { | ||
// static public var allCases: [AlbumCatalogEndpoint] = [.all, .id(id: ""), .ids(ids: [])] | ||
// } |
39 changes: 0 additions & 39 deletions
39
Sources/MusadoraLabsKit/Apple Music Endpoint/AlbumsEndpoint.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Sources/MusadoraLabsKit/Apple Music Endpoint/Endpoint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Endpoint.swift | ||
// Endpoint | ||
// | ||
// Created by Rudrank Riyam on 19/04/22. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol Endpoint { | ||
var name: String { get } | ||
var description: String { get } | ||
var previewURL: String { get } | ||
var url: URL { get async throws } | ||
} |
Oops, something went wrong.