-
Notifications
You must be signed in to change notification settings - Fork 0
/
Endpoint.swift
81 lines (66 loc) · 3.14 KB
/
Endpoint.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Foundation
import Alamofire
protocol Endpoint {
static var endpoint: String { get }
static func endpointWithId(id: String) -> String
}
extension Endpoint {
static func endpointWithId(id: String) -> String {
return "\(endpoint)\(id)"
}
}
protocol EndpointWithById : Endpoint {
static func byId(id: String, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
static func byId(id: String, parameters: [String : AnyObject]?, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
}
extension EndpointWithById {
static func byId(id: String, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
byId(id, parameters: nil, completionHandler)
}
static func byId(id: String, parameters: [String : AnyObject]?, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
sphereGetRequest(endpointWithId(id), parameters: parameters, completionHandler: completionHandler)
}
}
protocol EndpointWithQuery : Endpoint {
static func query(completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
static func query(parameters: [String : AnyObject]?, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
}
extension EndpointWithQuery {
static func query(completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
query(nil, completionHandler)
}
static func query(parameters: [String : AnyObject]?, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
sphereGetRequest(endpoint, parameters: parameters, completionHandler: completionHandler)
}
}
protocol EndpointWithCreate : Endpoint {
static func create(json: [String: AnyObject], _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
}
extension EndpointWithCreate {
static func create(json: [String: AnyObject], _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
spherePostRequest(endpoint, parameters: json, completionHandler: completionHandler)
}
}
protocol EndpointWithUpdate : Endpoint {
static func update(id: String, version: Int, actions: [[String: AnyObject]], _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
}
extension EndpointWithUpdate {
static func update(id: String, version: Int, actions: [[String: AnyObject]], _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
let json: [String : AnyObject] = [
"version": version,
"actions": actions
]
spherePostRequest(endpointWithId(id), parameters: json, completionHandler: completionHandler)
}
}
protocol EndpointWithDelete : Endpoint {
static func delete(id: String, version: Int, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void)
}
extension EndpointWithDelete {
static func delete(id: String, version: Int, _ completionHandler: Alamofire.Response<AnyObject, NSError> -> Void) {
let parameters: [String : AnyObject] = [
"version": version
]
sphereDeleteRequest(endpointWithId(id), parameters: parameters, completionHandler: completionHandler)
}
}