Latest 1.0.5
Homepage https://github.com/michaelhenry/RxRetroSwift
License MIT
Platforms ios 8.0
Dependencies RxSwift, RxCocoa, ObjectMapper, Alamofire
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

Features

  • Easy to use and simple
  • Clean and Neat implementation
  • Support different Networking library (Alamofire, NSURLSession)
  • Flexible response error handling
  • Simplify your rest client.

TODO

  • Unit and integration test (done)
  • Add Example (done)
  • Support different authentication method for your URLRequest.

Installation

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

pod 'RxRetroSwift'

Sample implementation

Using JSONPlaceholder API.
You can also check the Sample Project

class DefaultAPIClient:APIClient {

  static var shared = DefaultAPIClient()
  var caller = DefaultRequestCaller.shared

  private init() {

    RequestModel.defaults.baseUrl = "https://jsonplaceholder.typicode.com"
  }

  func getPosts() -> Observable<Result<[Post], ErrorModel>> {
    let request = RequestModel(
      httpMethod: .get,
      path: "posts")
      .asURLRequest()

    return caller.call(request)
  }

  func insertPost(post:Post) -> Observable<Result<Post, ErrorModel>> {
    let request = RequestModel(
      httpMethod: .post,
      path: "posts",
      payload: post.toJSON())
      .asURLRequest()

    return caller.call(request)
  }

  func getComments() -> Observable<Result<[Comment], ErrorModel>> {
    let request = RequestModel(
      httpMethod: .get,
      path: "comments")
      .asURLRequest()

    return caller.call(request)
  }

  func getAlbums() -> Observable<Result<[Album], ErrorModel>> {
    let request = RequestModel(
      httpMethod: .get,
      path: "albums")
      .asURLRequest()

    return caller.call(request)
  }

  func getPhotos() -> Observable<Result<[Photo], ErrorModel>> {
    let request = RequestModel(
      httpMethod: .get,
      path: "photos")
      .asURLRequest()

    return caller.call(request)
  }

  func getTodos() -> Observable<Result<[Todo], ErrorModel>> {
    let request = RequestModel(
      httpMethod: .get,
      path: "todos")
      .asURLRequest()

    return caller.call(request)
  }

  func getUsers() -> Observable<Result<[User],ErrorModel>> {

    let request = RequestModel(
      httpMethod: .get,
      path: "users")
      .asURLRequest()

    return caller.call(request)
  }
}

Testing


class TestAPIClient:QuickSpec {

  override func spec() {

    describe("Using JSONPlaceholder API") {

      let apiClient = DefaultAPIClient.shared

      it("Check Posts result count"){
        let observable = apiClient.getPosts()
        expect(observable.map { $0.value!.count }).first == 100
      }

      it("Can insert post"){
        var post = Post()
        let title = "This is my post"
        let userId = 101
        let body = "This is a message body"

        post.title = title
        post.userId = userId
        post.body = body
        let observable = apiClient.insertPost(post: post)
        expect(observable.map { $0.value?.title ?? "" }).first == title
        expect(observable.map { $0.value?.userId ?? 0 }).first == userId
        expect(observable.map { $0.value?.body ?? "" }).first == body
      }

      it("Check Comments result count"){
        let observable = apiClient.getComments()
        expect(observable.map { $0.value!.count }).first == 500
      }

      it("Check Albums result count"){
        let observable = apiClient.getAlbums()
        expect(observable.map { $0.value!.count }).first == 100
      }

      it("Check Photos result count"){
        let observable = apiClient.getPhotos()
        expect(observable.map { $0.value!.count }).first == 5000
      }

      it("Check Todos result count"){
        let observable = apiClient.getTodos()
        expect(observable.map { $0.value!.count }).first == 200
      }

      it("Check Users result count"){
        let observable = apiClient.getUsers()
        expect(observable.map { $0.value!.count }).first == 10
      }
    }
  }
}

Contributions

Just feel free to submit pull request or suggest anything that would be useful.

Credits

This uses RxSwift, Alamofire, ObjectMapper and Other 3rd party libraries.

Author

Michael Henry Pantaleon, [email protected]

License

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

Latest podspec

{
    "name": "RxRetroSwift",
    "version": "1.0.5",
    "summary": "A Simple, Neat and Clean, Easy to use Reactive RetroFit inspired implementation in swift.",
    "description": "A Simple, Neat and Clean, Easy to use Reactive RetroFit inspired implementation in swift. nAll you have to do is create models( and viewModels) and let the RxRetroSwift handle the difference response objects for you.",
    "homepage": "https://github.com/michaelhenry/RxRetroSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Michael Henry Pantaleon": "[email protected]"
    },
    "source": {
        "git": "https://github.com/michaelhenry/RxRetroSwift.git",
        "tag": "1.0.5"
    },
    "social_media_url": "https://twitter.com/michaelhenry119",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "RxRetroSwift/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            "~> 4.0"
        ],
        "RxCocoa": [
            "~> 4.0"
        ],
        "ObjectMapper": [
            "~> 3.1"
        ],
        "Alamofire": [
            "~> 4.5.1"
        ]
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This