Skip to content

Releases: teepsllc/BuckoNetworking

Promises - Updated responses

21 Feb 21:48
Compare
Choose a tag to compare

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

21 Feb 00:18
214b903
Compare
Choose a tag to compare

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

21 Feb 21:49
Compare
Choose a tag to compare

Bucko now supports Codable with Swift 4

03 Jan 18:24
8db99fd
Compare
Choose a tag to compare

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

18 Oct 20:25
Compare
Choose a tag to compare

This release allows public access to serverError as defined in release 1.1.2

1.1.2

25 May 20:26
Compare
Choose a tag to compare

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

18 May 16:41
Compare
Choose a tag to compare

Deprecations

26 Apr 19:42
Compare
Choose a tag to compare

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

26 Apr 13:03
Compare
Choose a tag to compare
1.0.12

Public init

Bug Fix

07 Apr 19:53
Compare
Choose a tag to compare
1.0.11

Fix retain cycle