Created
March 15, 2022 19:27
-
-
Save malcommac/77c90acf292a2abe7bf915328915a33f to your computer and use it in GitHub Desktop.
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
public extension Movies { | |
struct Search: APIResourceConvertible { | |
public typealias Result = MoviesPage | |
var query: String | |
var includeAdult: Bool = false | |
var year: Int? | |
public init(_ query: String, year: Int? = nil) { | |
self.query = query | |
self.year = year | |
} | |
func request() -> HTTPRequest { | |
HTTPRequest { | |
$0.method = .get | |
$0.path = "/search/movie" | |
$0.addQueryParameter(name: "query", value: query) | |
$0.addQueryParameter(name: "include_adult", value: String(includeAdult)) | |
if let year = year { | |
$0.addQueryParameter(name: "year", value: String(year)) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment