CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

Bluebonnet 0.4.0

Bluebonnet 0.4.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2015
SPMSupports SPM

Maintained by KITAGAWA Tatsuya.



 
Depends on:
Alamofire= 1.3.1
SwiftTask~> 3.3.0
 

Bluebonnet

Circle CI

Bluebonnet is a simple APIClient using Alamofire and ReactKit/SwiftTask.

Feature

  • typed response
  • handle as SwiftTask
  • Swift 1.2

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Set up client

  • First, create a API class inherited Bluebonnet.
  • Then, create a struct implemented BluebonnetRequest.
  • Define request in the struct. (e.g. method, parameters)
public class GitHubAPI: Bluebonnet {

    // baseURL for all api
    static let baseURL: NSURL = NSURL(string: "https://api.github.com")!

    /**
    for respective API
    */
    struct GetUserProfile: BluebonnetRequest {
        typealias Response = User
        typealias ErrorResponse = GitHubError
        let userName: String
        let method: HTTPMethod = .GET
        var parameters: [String: AnyObject] = [:]
        var path: String {
            return "users/\(userName.URLEscapedString)"
        }

        init(userName: String) {
            self.userName = userName
        }

        /// it is requred property for converting to request
        var URLRequest: NSURLRequest {
            return Bluebonnet.build(baseURL, path: path, method: method, parameters: parameters)
        }
    }
}

Use the client

  • You can get task like this.
  • Both responses in .success/.failure are typed.
let task = GitHubAPI.requestTask(GitHubAPI.GetUserProfile(userName: userName))
task
    .progress { (oldProgress, newProgress) in
        print(newProgress.bytesWritten)
        print(newProgress.totalBytesWritten)
        return
    }
    .success { user in // type inference
        print(user.name)
        return
    }
    .failure { (errorResult, isCancelled) -> Void in
        print(errorResult?.error.description)
        print(errorResult?.response?.message
        return
    }

Requirements

  • Swift 1.2

Installation

Bluebonnet is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Bluebonnet"

Acknowledgement

Bluebonnet refers to APIKit.

Author

KITAGAWA Tatsuya, [email protected]

License

Bluebonnet is available under the MIT license. See the LICENSE file for more info.