Skip to content

Commit 4e1a59a

Browse files
committed
Add promise request methods to Endpoint and DecodeableEndpoint
1 parent 64a8add commit 4e1a59a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

BuckoNetworking/Protocols/DecodableEndpoint.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright © 2017 Teeps. All rights reserved.
77
//
88

9-
import Alamofire
10-
119
public protocol DecodableEndpoint: Endpoint {
1210
associatedtype ResponseType: Decodable
1311
}
@@ -34,4 +32,13 @@ public extension DecodableEndpoint {
3432

3533
return request
3634
}
35+
36+
public func request() -> Promise<ResponseType> {
37+
return Bucko.shared.requestData(endpoint: self).then { data in
38+
return Promise { fullfill, _ in
39+
let result = try JSONDecoder().decode(ResponseType.self, from: data)
40+
fullfill(result)
41+
}
42+
}
43+
}
3744
}

BuckoNetworking/Protocols/Endpoint.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,13 @@ public extension Endpoint {
8484

8585
return request
8686
}
87+
88+
public func request<T: Decodable>(responseType: T.Type) -> Promise<T> {
89+
return Bucko.shared.requestData(endpoint: self).then { data in
90+
return Promise { fullfill, _ in
91+
let result = try JSONDecoder().decode(T.self, from: data)
92+
fullfill(result)
93+
}
94+
}
95+
}
8796
}

0 commit comments

Comments
 (0)