Releases: teepsllc/BuckoNetworking
Promises - Updated responses
Bucko now supports Promises.
struct User: Decodable {
var name: String
var phoneNumber: String
enum CodingKeys: String, CodingKey {
case name
case phoneNumber = "phone_number"
}
}
struct UserService: DecodableEndpoint {
typealias ResponseType = User
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// You can now use:
Bucko.shared.request(UserService()).then { user in
// Do something with user
}.catch { error in
// Do something with error
}
// or
UserService().request().then { user in
// Do something with user
}.catch { error in
// Do something with error
}
Enums still work as well:
enum UserService: Endpoint {
case index
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// Use your Endpoint
UserService.index.request(responseType: [User].self).then { users in
// Do something with users
}.catch { error in
// Do something with error
}
Promises
Bucko now supports Promises.
struct User: Decodable {
var name: String
var phoneNumber: String
enum CodingKeys: String, CodingKey {
case name
case phoneNumber = "phone_number"
}
}
struct UserService: DecodableEndpoint {
typealias ResponseType = User
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// You can now use:
Bucko.shared.request(UserService()).then { user in
// Do something with user
}.catch { error in
// Do something with error
}
// or
UserService().request().then { user in
// Do something with user
}.catch { error in
// Do something with error
}
Enums still work as well:
enum UserService: Endpoint {
case index
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// Use your Endpoint
UserService.index.request(responseType: [User].self).then { users in
// Do something with users
}.catch { error in
// Do something with error
}
Updated Responses
2.0.1
Bucko now supports Codable with Swift 4
Updates Bucko to Swift 4 and promotes Codable to be used. SwiftyJSON has been removed and is not required by Bucko. JSONDecodable and JSONDecodableEndpoint have been removed and DecodableEndpoint has been introduced.
Example on how to use DecodableEndpoint:
struct User: Decodable {
var name: String
var phoneNumber: String
enum CodingKeys: String, CodingKey {
case name
case phoneNumber = "phone_number"
}
}
struct UserService: DecodableEndpoint {
typealias ResponseType = User
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
UserService().request { (user, error) in
guard let user = user else {
// Do Error
return
}
// Do something with user
}
Using an enum and DecodableEndpoint is possible, however, DecodableEndpoint will require that each case return the same type.
If you want each case to respond with a separate Codable type, you can use Endpoint and its request(responseType:, completion:) method.
enum UserService: Endpoint {
case index
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
UserService.index.request(responseType: [User].self) { (users, error) in
guard let users = users else {
// Do Error
return
}
// Do something with users
}
Allow access to serverError
This release allows public access to serverError as defined in release 1.1.2
1.1.2
This release adds a new serverError
variable on DataRequest
to easily access any errors that the server may have thrown.
Bucko.shared.request(endpoint: MyEndpoint) { response in
if response.result.isSuccess {
} else {
// You can now access the error
let error: JSON? = response.serverError
}
}
Status Code Validation
1.1.1
Deprecations
This version will now auto import Alamofire
and SwiftyJSON
for you. The typealias
that were created are now deprecated and will be removed entirely in a new update.
There is also a new method, request(endpoint:)
that will return the DataRequest
so that you can use any of the provided response closures to handle the response. request(endpoint:completion:)
expects the response to be JSON.
Public Init
1.0.12 Public init
Bug Fix
1.0.11 Fix retain cycle