Skip to content

Instantly share code, notes, and snippets.

@malcommac
Created March 15, 2022 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcommac/77c90acf292a2abe7bf915328915a33f to your computer and use it in GitHub Desktop.
Save malcommac/77c90acf292a2abe7bf915328915a33f to your computer and use it in GitHub Desktop.
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