53 lines
1.3 KiB
Swift
53 lines
1.3 KiB
Swift
import Foundation
|
|
import Moya
|
|
|
|
enum MainHomeRecommendationApi {
|
|
case getRecommendations
|
|
case followRecommendedCreators(request: FollowRecommendedCreatorsRequest)
|
|
}
|
|
|
|
extension MainHomeRecommendationApi: TargetType {
|
|
var baseURL: URL {
|
|
return URL(string: BASE_URL)!
|
|
}
|
|
|
|
var path: String {
|
|
switch self {
|
|
case .getRecommendations:
|
|
return "/api/v2/home/recommendations"
|
|
|
|
case .followRecommendedCreators:
|
|
return "/api/v2/home/recommendations/creators/follow"
|
|
}
|
|
}
|
|
|
|
var method: Moya.Method {
|
|
switch self {
|
|
case .getRecommendations:
|
|
return .get
|
|
|
|
case .followRecommendedCreators:
|
|
return .post
|
|
}
|
|
}
|
|
|
|
var task: Moya.Task {
|
|
switch self {
|
|
case .getRecommendations:
|
|
return .requestPlain
|
|
|
|
case .followRecommendedCreators(let request):
|
|
return .requestJSONEncodable(request)
|
|
}
|
|
}
|
|
|
|
var headers: [String: String]? {
|
|
let token = UserDefaults.string(forKey: .token)
|
|
if case .getRecommendations = self,
|
|
token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
return nil
|
|
}
|
|
return ["Authorization": "Bearer \(token)"]
|
|
}
|
|
}
|