Latest0.8.4
Homepagehttps://github.com/Pircate/RxNetwork
LicenseMIT
Platformsios 9.0, requires ARC
Authors

CI Status
Version
License
Platform

Example

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

Requirements

Installation

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

pod 'RxNetwork'

# or

pod 'RxNetwork/Cache'

Usage

Import

import RxNetwork

Configuration

Network.Configuration.default.timeoutInterval = 20
Network.Configuration.default.plugins = [NetworkIndicatorPlugin()]
Network.Configuration.default.taskClosure = { target in
    // configure common parameters etc.
    switch target.task {
    case let .requestParameters(parameters, encoding):
        let params: [String: Any] = ["token": "", "sign": "", "body": parameters]
        return .requestParameters(parameters: params, encoding: encoding)
    default:
        return target.task
    }
}

// or

let configuration = Network.Configuration()
configuration.timeoutInterval = 20
configuration.plugins = [NetworkIndicatorPlugin()]
Network.Configuration.default = configuration

Request without cache

StoryAPI.latest
    .request()
    .map(StoryListModel.self)
    .subscribe(onSuccess: { (model) in

    }).disposed(by: disposeBag)

Request with cache

normal

/*
 {
    "top_stories": []
 }
 */StoryAPI.latest
    .onCache(StoryListModel.self, { (model) in

    })
    .request()
    .subscribe(onSuccess: { (model) in

    })
    .disposed(by: disposeBag)

StoryAPI.latest
    .cache
    .request()
    .map(StoryListModel.self)
    .subscribe(onNext: { (model) in

    }).disposed(by: disposeBag)

other

/*
 {
    "code": 2000,
    "message": "Ok",
    "result": []
 }
 */TestTarget.test(count: 10)
    .onCache([TestModel].self, { (models) in

    })
    .requestObject()
    .subscribe(onSuccess: { (models) in

    })
    .disposed(by: disposeBag)

TestTarget.test(count: 10)
    .cache
    .request()
    .mapObject([TestModel].self)
    .subscribe(onNext: { (models) in

    })
    .disposed(by: disposeBag)

Notice

// You may need configure storage policy when use cache response
Network.Cache.shared.storagePolicyClosure = { response in
    guard let code = try? response.map(Int.self, atKeyPath: "code") else { return false }
    return code == 200
}

Author

gaoX, [email protected]

License

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

Latest podspec

{
    "name": "RxNetwork",
    "version": "0.8.4",
    "summary": "A swift network library.",
    "homepage": "https://github.com/Pircate/RxNetwork",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Pircate": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Pircate/RxNetwork.git",
        "tag": "0.8.4"
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "swift_version": "4.0",
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "RxNetwork/Classes/Core",
            "dependencies": {
                "Moya/RxSwift": []
            }
        },
        {
            "name": "Cache",
            "source_files": "RxNetwork/Classes/Cache",
            "dependencies": {
                "RxNetwork/Core": [],
                "Cache": []
            }
        }
    ]
}

Pin It on Pinterest

Share This