TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2016 |
SPMSupports SPM | ✗ |
Maintained by Juan Cruz Ghigliani.
Depends on: | |
Ono | >= 0 |
Alamofire | >= 0 |
To run the example project, clone the repo, and run pod install
from the Example directory first.
NLService is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "NLService"
The simplest example
let service = NLRemoteService(baseURL: NSURL(string: "https://api.github.com")!, manager:NLAlamofireManager())
let resource = NLRemoteResource<NSDictionary>("/repos/juancruzmdq/NLService")
service.request(resource).load { (dict) in
switch dict {
case .Success(let dict):
print("API Result: \(dict)")
break
case .Error(let error):
print("API Error: \(error.localizedDescription)")
break
}
}
// Build Main Service
let service = NLRemoteService(baseURL: NSURL(string: "https://api.github.com")!, manager: NLAlamofireManager(headers: ["Header-Global":"value global"])) // optional global headers
// Build resource endpoint with parser
let repoInfo = NLRemoteResource<String>("/repos/juancruzmdq/NLService")
repoInfo.headers = ["Header-Repo":"value for repo"]
repoInfo.parser = = {( result )->ParseResult<String> in
guard let info = result as? NSDictionary else{
return .Error(NSError(domain: "ViewController", code: 0, localizedDescription: "Invalid response???"))
}
return .Success("\(info["id"]!) - \(info["name"]!)")
}
// Use service to create request to resource, and perform call (load) of the remote resource
api.request(repoInfo).load { (result) in
switch result {
case .Success(let string):
print("API Result: \(string)")
break
case .Error(let error):
print("API Error: \(error.localizedDescription)")
break
}
}
Juan Cruz Ghigliani, [email protected]
NLService is available under the MIT license. See the LICENSE file for more info.