Skip to content

Instantly share code, notes, and snippets.

@JeremyXue77
Created May 10, 2019 10:15
Show Gist options
  • Save JeremyXue77/3dae25e32dc7ae703313f68396bcfb10 to your computer and use it in GitHub Desktop.
Save JeremyXue77/3dae25e32dc7ae703313f68396bcfb10 to your computer and use it in GitHub Desktop.
extension MovieApi: EndPointType {
var environmentBaseURL : String {
switch NetworkManager.environment {
case .production: return "https://api.themoviedb.org/3/movie/"
case .qa: return "https://qa.themoviedb.org/3/movie/"
case .staging: return "https://staging.themoviedb.org/3/movie/"
}
}
var baseURL: URL {
guard let url = URL(string: environmentBaseURL) else { fatalError("baseURL could not be configured.")}
return url
}
var path: String {
switch self {
case .recommended(let id):
return "\(id)/recommendations"
case .popular:
return "popular"
case .newMovies:
return "now_playing"
case .video(let id):
return "\(id)/videos"
}
}
var httpMethod: HTTPMethod {
return .get
}
var task: HTTPTask {
switch self {
case .newMovies(let page):
return .requestWithParameters(bodyParameters: nil,
urlParameters: ["page":page,
"api_key":NetworkManager.MovieAPIKey])
default:
return .request
}
}
var headers: HTTPHeaders? {
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment