Buya
Network abstraction framework
Features
- Interfaces are same as Moya
- Without Alamofire abstraction layer
- Included: AccessTokenPlugin, RefreshTokenPlugin, AccessRecoveryPlugin
Installation
CocoaPods
For Buya, use the following entry in your Podfile:
pod 'RxSwift', '~> 4.5'
pod 'RxCocoa', '~> 4.5'
pod 'Buya', '~> 1.0'
Then run pod install
.
In any file you'd like to use Buya in, don't forget to
import the framework with import Buya
.
Usage
Using Buya is really simple. You can access an API like this:
authorizationProvider
.request(Authorization.getData)
.map(YourCodableStruct.self)
.subscribe(
onSuccess: { (data) in
/// Doing something with data
},
onError: { (error) in
print(error.localizedDescription)
}
)
.disposed(by: self.disposeBag)
To do this, you must implement the following:
typealias AuthorizationProvider = Buya.Provider<Authorization>
enum Authorization {
/// Authorization
case authorize
/// Return data
case getData
}
extension Authorization: EndpointType, Buya.RefreshTokenApply {
var path: String {
switch self {
case Authorization.authorize:
return "/authorize"
case Authorization.getData:
return "/getData"
}
}
var requestType: RequestType {
switch self {
case Authorization.authorize:
return RequestType.post
case Authorization.getData:
return RequestType.get
}
}
var requestInfo: RequestInfo {
switch self {
case let Authorization.authorize(login, password):
let query = [
"login" : login,
"password": password
]
return RequestInfo.query(parameters: query)
case Authorization.getData:
return RequestInfo.none
}
}
var headers: [String : String]? {
return [
"Content-Type": "application/json",
"Accept": "application/json"
]
}
var refreshTokenApply: Bool {
switch self {
case Authorization.getData: return true
default:
return false
}
}
}
License
RStorage is released under an MIT license. See LICENSE for more information.