Balblair is an api client library written in Swift.
To run the example project, clone the repo, and run pod install
from the Example directory first.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Balblair.defaultConfiguration = Balblair.Configuration(baseUrl: "https://qiita.com/", header: [:])
return true
}
Balblair().get("api/v2/items", success: { (result) in
print(result)
})
struct QiitaResult: Mappable {
var title = ""
init?(_ map: Map) {
mapping(map)
}
mutating func mapping(map: Map) {
title <- map["title"]
}
}
struct QiitaRequest: ApiRequest {
typealias ResultType = [Result]
let method = Balblair.Method.GET
let path = "api/v2/items"
let parameters = NoParamsModel.instance
}
QiitaRequest().request(progress: { print($0) }, success: { print($0) }, failure: { print($0, $1) })
QiitaRequest().createTask().success { print($0) }
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Balblair.defaultConfiguration = Configuration()
return true
}
class Configuration: BalblairConfiguration {
let baseUrl = "https://qiita.com/"
var headerBuilder: BalblairHeaderBuilder = HeaderBuilder()
func apiClientShouldBeginRequest(apiClient: Balblair, method: Balblair.Method, path: String, parameters: [String: AnyObject]?) -> Bool { return true }
func apiClientShouldProgress(apiClient: Balblair, method: Balblair.Method, path: String, parameters: [String: AnyObject]?, progress: NSProgress) -> Bool { return true }
func apiClientShouldSuccess(apiClient: Balblair, method: Balblair.Method, path: String, parameters: [String: AnyObject]?, result: AnyObject?) -> ErrorType? { return nil }
func apiClientShouldFailure(apiClient: Balblair, method: Balblair.Method, path: String, parameters: [String: AnyObject]?, result: AnyObject?, error: ErrorType) -> Bool { return true }
}
class HeaderBuilder: BalblairHeaderBuilder {
func build() -> [String : String] {
return [:]
}
}
Balblair is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Balblair"
Koji Murata, [email protected]
Balblair is available under the MIT license. See the LICENSE file for more info.