Skip to content

Commit

Permalink
Release 0.4.2 (#5)
Browse files Browse the repository at this point in the history
* Add LICENSE file

* Fix wrong path being returned for music videos catalog requests, Improve custom error descriptions, Improve routers unit tests

* Improve DataProvider unit tests

* Modify methods encapsulation to public to make them available to library consumers

* Fix router generated path for catalog resources
  • Loading branch information
jjotaum committed Sep 19, 2022
1 parent 070d59a commit 3cff7fc
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 205 deletions.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Jota Uribe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 4 additions & 5 deletions Sources/AmuseKit/AmuseKit.swift
Expand Up @@ -11,7 +11,6 @@ protocol AmuseOption: RawRepresentable, Hashable, CaseIterable {}

public class AmuseKit {
enum AmuseError: Error {
case invalidRequest
case missingDevToken
case missingUserToken
}
Expand All @@ -20,10 +19,10 @@ public class AmuseKit {
extension AmuseKit.AmuseError: LocalizedError {
public var errorDescription: String? {
switch self {
case .invalidRequest:
return NSLocalizedString("", comment: "")
default:
return nil
case .missingDevToken:
return "Developer token is missing"
case .missingUserToken:
return "UserToken token is missing"
}
}
}
4 changes: 2 additions & 2 deletions Sources/AmuseKit/Networking/DataProvider.swift
Expand Up @@ -47,7 +47,7 @@ public extension AmuseKit {

// MARK: - Catalog Methods

func catalog<Resource: Codable>(_ resourceType: CatalogResourceConvertible<Resource>, ids: [String]) throws -> AnyPublisher<AmuseKit.ResponseRoot<Resource, EmptyCodable>, Error> {
public func catalog<Resource: Codable>(_ resourceType: CatalogResourceConvertible<Resource>, ids: [String]) throws -> AnyPublisher<AmuseKit.ResponseRoot<Resource, EmptyCodable>, Error> {
guard let developerToken = storage.developerToken else {
throw AmuseKit.AmuseError.missingDevToken
}
Expand All @@ -66,7 +66,7 @@ public extension AmuseKit {

// MARK: - Library Methods

func library<Resource: Codable>(_ resourceType: LibraryResourceConvertible<Resource>) throws -> AnyPublisher<AmuseKit.ResponseRoot<Resource, EmptyCodable>, Error> {
public func library<Resource: Codable>(_ resourceType: LibraryResourceConvertible<Resource>) throws -> AnyPublisher<AmuseKit.ResponseRoot<Resource, EmptyCodable>, Error> {
guard let developerToken = storage.developerToken else {
throw AmuseKit.AmuseError.missingDevToken
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/AmuseKit/Networking/ResourceConvertible.swift
Expand Up @@ -30,23 +30,23 @@ public extension AmuseKit {
}
}

extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryAlbum {
public extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryAlbum {
static var albums = Self.init(rawValue: .albums)
}

extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryArtist {
public extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryArtist {
static var artists = Self.init(rawValue: .artists)
}

extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryMusicVideo {
public extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryMusicVideo {
static var musicVideos = Self.init(rawValue: .musicVideos)
}

extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryPlaylist {
public extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibraryPlaylist {
static var playlists = Self.init(rawValue: .playlists)
}

extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibrarySong {
public extension AmuseKit.LibraryResourceConvertible where Model == AmuseKit.LibrarySong {
static var songs = Self.init(rawValue: .songs)
}

Expand All @@ -71,23 +71,23 @@ public extension AmuseKit {
}
}

extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Album {
public extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Album {
static var albums = Self.init(rawValue: .albums)
}

extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Artist {
public extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Artist {
static var artists = Self.init(rawValue: .artists)
}

extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.MusicVideo {
public extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.MusicVideo {
static var musicVideos = Self.init(rawValue: .musicVideos)
}

extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Playlist {
public extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Playlist {
static var playlists = Self.init(rawValue: .playlists)
}

extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Song {
public extension AmuseKit.CatalogResourceConvertible where Model == AmuseKit.Song {
static var songs = Self.init(rawValue: .songs)
}

Expand Down
17 changes: 14 additions & 3 deletions Sources/AmuseKit/Networking/Router.swift
Expand Up @@ -28,8 +28,8 @@ extension AmuseKit {
extension AmuseKit.Router: URLConvertible, URLRequestConvertible {
private var path: String {
switch self {
case .catalog(let countryCode, let resourceType):
return "/v1/catalog/\(countryCode)/search/\(resourceType)"
case .catalog(let countryCode, let type):
return "/v1/catalog/\(countryCode)/\(type.lastPathComponent)"
case .library(let type):
return "/v1/me/\(type.lastPathComponent)"
case .recommendations:
Expand All @@ -52,12 +52,23 @@ extension AmuseKit.Router: URLConvertible, URLRequestConvertible {

func asURLRequest(_ queryItems: [URLQueryItem]) throws -> URLRequest {
guard let url = asURL(queryItems) else {
throw AmuseKit.AmuseError.invalidRequest
throw URLError(.badURL)
}
return URLRequest(url: url)
}
}

fileprivate extension AmuseKit.CatalogResourceType {
var lastPathComponent: String {
switch self {
case .musicVideos:
return "music-videos"
default:
return rawValue
}
}
}

fileprivate extension AmuseKit.LibraryResourceType {
var lastPathComponent: String {
switch self {
Expand Down
11 changes: 11 additions & 0 deletions Tests/AmuseKitTests/DataModels/invalid_authentication.json
@@ -0,0 +1,11 @@
{
"errors": [
{
"id": "KHFHBMG2ZFDUYJQUMALKZAZ6LI",
"title": "Forbidden",
"detail": "Invalid authentication",
"status": "403",
"code": "40300"
}
]
}
Expand Up @@ -35,3 +35,4 @@ struct MockAPIService: APIService {
return publisher
}
}

21 changes: 21 additions & 0 deletions Tests/AmuseKitTests/Helpers/MockDataProvider.swift
@@ -0,0 +1,21 @@
//
// MockDataProvider.swift
// AmuseKit
//
// Created by Jota Uribe on 16/09/22.
//

@testable import AmuseKit


extension AmuseKit.DataProvider {
static func mock(resourceName: String) -> AmuseKit.DataProvider {
var service: MockAPIService = MockAPIService()
service.resourceName = resourceName
var mock: AmuseKit.DataProvider
mock = .init(storage: MockStorageService(),
service: service)
mock.setDeveloperToken("A1D2E3V4T5O6K7E8N9")
return mock
}
}
Expand Up @@ -8,7 +8,7 @@
import Foundation
@testable import AmuseKit

struct MockStorageService: StorageService {
class MockStorageService: StorageService {
var developerToken: String?
var userToken: String?
}

0 comments on commit 3cff7fc

Please sign in to comment.