BEENetwork 1.0.0

BEENetwork 1.0.0

Maintained by liuxc.



  • By
  • liuxc123

BEENetwork

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9.0
  • Swift 5.0
  • Xcode 11

Installation

BEENetwork is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BEENetwork'

Usage

Do not use cache

NetworkManager.default.provider
    .rx
    .request(MultiTarget(Api.category))
    .asObservable().distinctUntilChanged()
    .map(BaseModel<ListData>.self)
    .map {$0.data.list}
    .subscribe(onNext: { (list) in
        self.items = list
        self.tableView.reloadData()
    }, onError: { (e) in
        print(e.localizedDescription)
    }).disposed(by: dispose)

Or you can use TargetType to request directly

Api.category.request()
    .map(BaseModel<ListData>.self)
    .map { $0.data.list }
    .subscribe(onSuccess: { (list) in
        self.items = list
        self.tableView.reloadData()
    }) { (e) in
        print(e.localizedDescription)
}.disposed(by: dispose)

Use cache

NetworkManager.default.provider
    .rx
    .onCache(MultiTarget(Api.category))
    .distinctUntilChanged()
    .map(BaseModel<ListData>.self)
    .map {$0.data.list}
    .subscribe(onNext: { (list) in
        self.items = list
        self.tableView.reloadData()
    }, onError: { (e) in
        print(e.localizedDescription)
    }).disposed(by: dispose)
    
/// or

Api.category.cache()
    .distinctUntilChanged()
    .map(BaseModel<ListData>.self)
    .map { $0.data.list }
    .subscribe(onNext: { (model) in
        print(model.first?.name ?? "")
        self.items = model
        self.tableView.reloadData()
    }, onError: { (e) in
        print(e.localizedDescription)
    }).disposed(by: dispose)

You can also customize the use of the plugin

let configuration = Configuration()
configuration.plugins.append(LoggingPlugin())
let manager = NetworkManager(configuration: configuration)
manager.provider
    .rx
    .request(MultiTarget(Api.category))
    .asObservable().distinctUntilChanged()
    .map(BaseModel<ListData>.self)
    .map {$0.data.list}
    .subscribe(onNext: { (list) in
        self.items = list
        self.tableView.reloadData()
    }, onError: { (e) in
        print(e.localizedDescription)
    }).disposed(by: dispose)

Author

liuxc123, [email protected]

License

BEENetwork is available under the MIT license. See the LICENSE file for more info.