Skip to content

Instantly share code, notes, and snippets.

@omochi
Created June 15, 2020 11:48
Show Gist options
  • Save omochi/72f7f71a9c9aed3a7ca481c78f98fe6d to your computer and use it in GitHub Desktop.
Save omochi/72f7f71a9c9aed3a7ca481c78f98fe6d to your computer and use it in GitHub Desktop.
import Foundation
enum HTTPMethod {
case get, post, patch
}
protocol SampleRequest {
var method: HTTPMethod { get }
var path: String { get }
var parameters: Any? { get }
}
struct InstallationPostRequest: SampleRequest {
static var path: String { "/installation" }
var token: String
var method: HTTPMethod { .post }
var path: String { Self.path }
var parameters: Any? {
return ["token": token]
}
init(token: String) {
self.token = token
}
}
struct InstallationPatchRequest: SampleRequest {
var id: String
var token: String
var method: HTTPMethod { .patch }
var path: String { InstallationPostRequest.path }
var parameters: Any? {
return ["id": id,
"token": token]
}
init(id: String, token: String) {
self.id = id
self.token = token
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment