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 is a simple APIClient using Alamofire and ReactKit/SwiftTask.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Bluebonnet
.BluebonnetRequest
.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)
}
}
}
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
}
Bluebonnet is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Bluebonnet"
Bluebonnet refers to APIKit.
KITAGAWA Tatsuya, [email protected]
Bluebonnet is available under the MIT license. See the LICENSE file for more info.