Created
January 2, 2018 14:07
-
-
Save joelmarquez90/012fa0f652349a3f080441ae587ebd63 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
enum Service { | |
case version(version: String) | |
} | |
extension Service: TargetType { | |
var baseURL: URL { return API.BaseURL } | |
var path: String { | |
switch self { | |
case .version(_): return "/version" | |
} | |
} | |
var method: Moya.Method { | |
switch self { | |
case .version: return .get | |
} | |
} | |
var sampleData: Data { | |
switch self { | |
case .version: return """ | |
{ | |
"force": true, | |
"update": true | |
} | |
""".utf8Encoded | |
} | |
} | |
var task: Task { | |
switch self { | |
case .version(let version): return .requestParameters(parameters: ["os": "IOS", "version": version], | |
encoding: URLEncoding.queryString) | |
} | |
var headers: [String : String]? { | |
return [ | |
"X-App-Version": AppInfo.version(), | |
"X-Platform": "IOS" | |
] | |
} | |
} | |
// MARK: - Helpers | |
private extension String { | |
var utf8Encoded: Data { | |
return data(using: .utf8)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment