Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Swift 5.0 #28

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixed Japan (jp) and China (cn) country codes
Added options to lookup API
  • Loading branch information
Martin Rehder authored and Martin Rehder committed Mar 22, 2017
commit 0f7eea3118aeb43113b0ae815f274a004bfbc158
30 changes: 15 additions & 15 deletions Source/Country.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import Foundation

public enum Country: String {
case australia = "au"
case canada = "ca"
case china = "zh"
case denmark = "dk"
case france = "fr"
case germany = "de"
case italy = "it"
case japan = "ja"
case netherlands = "nl"
case poland = "pl"
case spain = "es"
case sweden = "se"
case switzerland = "ch"
case unitedKingdom = "gb"
case unitedStates = "us"
case australia = "au"
case canada = "ca"
case china = "cn"
case denmark = "dk"
case france = "fr"
case germany = "de"
case italy = "it"
case japan = "jp"
case netherlands = "nl"
case poland = "pl"
case spain = "es"
case sweden = "se"
case switzerland = "ch"
case unitedKingdom = "gb"
case unitedStates = "us"
}

extension Country {
Expand Down
21 changes: 12 additions & 9 deletions Source/iTunes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public final class iTunes {
return task
}

public func lookup(media upc: String, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: upc, tag: "upc")
public func lookup(media upc: String, options: Options? = nil, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: upc, tag: "upc", options: options)
return self.lookupWithParams(params: params, completion: completion)
}

public func lookup(book isbn: String, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: isbn, tag: "isbn")
public func lookup(book isbn: String, options: Options? = nil, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: isbn, tag: "isbn", options: options)
return self.lookupWithParams(params: params, completion: completion)
}

public func lookup(for id: String, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: id, tag: "id")
public func lookup(for id: String, options: Options? = nil, completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {
let params = parameters(forID: id, tag: "id", options: options)
return self.lookupWithParams(params: params, completion: completion)
}

func lookupWithParams(params: [String : String], completion: @escaping (Result<AnyObject, SearchError>) -> Void) -> URLSessionTask? {

guard let url = URLWithParameters(params, path: "/lookup") else {
completion(.failure(.invalidURL))
return nil
Expand Down Expand Up @@ -117,8 +117,11 @@ public final class iTunes {
return parameters
}

private func parameters(forID id: String, tag: String) -> [String : String] {
let parameters = [ tag : id ]
private func parameters(forID id: String, tag: String, options: Options? = nil) -> [String : String] {
var parameters = [ tag : id ]
if let options = options?.parameters {
parameters.unionInPlace(options)
}
return parameters
}

Expand Down