https://github.com/malt03/balblair
https://github.com/malt03/balblair
api apikit swift
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/malt03/balblair
- Owner: malt03
- License: mit
- Created: 2016-08-24T15:37:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T21:59:16.000Z (almost 4 years ago)
- Last Synced: 2026-02-05T08:53:56.159Z (4 months ago)
- Topics: api, apikit, swift
- Language: Swift
- Size: 6.61 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Balblair
[](http://cocoapods.org/pods/Balblair)

[](http://cocoapods.org/pods/Balblair)
[](https://github.com/Carthage/Carthage)

Balblair is an api client library written in Swift.
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Usage
### Initialize
```swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Balblair.defaultConfiguration = Balblair.Configuration(baseUrl: "https://qiita.com/", header: [:])
return true
}
```
### Usage
#### Create Response Model
```swift
struct QiitaResult: Mappable {
var title = ""
init?(_ map: Map) {
mapping(map)
}
mutating func mapping(map: Map) {
title <- map["title"]
}
}
```
#### Create Request Model
```swift
struct QiitaRequest: ApiRequest {
typealias ResultType = [Result]
let method = Balblair.Method.GET
let path = "api/v2/items"
let parameters = NoParamsModel.instance
}
```
#### Request
```swift
QiitaRequest().response.subscribe(onNext: { print($0) } )
```
### Create customize configuration
```swift
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 [:]
}
}
```
## Installation
Balblair is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod "Balblair"
```
## Author
Koji Murata, malt.koji@gmail.com
## License
Balblair is available under the MIT license. See the LICENSE file for more info.