Swiftpack.co - Package - gspd-mobi/rage-ios

Rage for iOS

Travis CI Version License Platform

Pragmatic network abstraction layer for iOS applications.

:warning: Warning

Library is NOT production ready yet. Please don't use it before it gets more stable. There may be compatibility issues between newer and older versions of library until version 1.0.0.

Documentation now may differ from real API because it's unstable and improving pretty fast.

Features

  • One liner request making. :dart:
  • Describing API spec in highly readable way. :books:
  • Optional RxSwift out of box. :rocket:
  • Optional JSON support by Codable. :ledger:
  • Manipulating strictly typed objects instead of String dictionaries hell. :package:

Usage

You can check example implementation in RageExample project.

At first you need to create RageClient using builder pattern.

let client = Rage.builderWithBaseUrl("https://api.github.com")
    .withContentType(.json)
    .withHeaderDictionary([
            "Api-Version": "1.1",
            "Platform": "iOS"
    ])
    .withPlugin(LoggingPlugin(logLevel: .full))
    .withAuthenticator(MyAuthenticator())
    .withErrorsHandlersClosure {
        [AuthErrorHandler()]
    }
    .build()

Then describe your API requests like these. It is a generic way to declare requests and their background execution.

func getUser(username: String, completion: @escaping Result<RageResponse, RageError> -> ()) {
    client.get("/users/{user}")
        .path("user", username)
        .enqueue(completion)
}

// Async
func getRepositoriesForOrganization(organizationTitle: String, completion: @escaping Result<RageResponse, RageError> -> ()) {
    client.get("/orgs/{org}/repos")
        .path("org", organizationTitle)
        .enqueue(completion)
}

// Sync
func getRepositoriesForOrganizationSync(organizationTitle: String) -> Result<RageResponse, RageError> {
    return client.get("/orgs/{org}/repos")
        .path("org", organizationTitle)
        .execute()
}

Using both RxSwift and RageCodableExtensions you can declare API in such awesome way.

func getUser(username: String) -> Observable<GithubUser> {
    return client.get("/users/{user}")
        .path("user", username)
        .executeObjectObservable()
}

func getRepositoriesForOrganization(organizationTitle: String) -> Observable<[GithubRepository]> {
    return client.get("/orgs/{org}/repos")
        .path("org", organizationTitle)
        .executeArrayObservable()
}

That's it. Compact but powerful.

Installation (CocoaPods)

Add this dependency to Podfile and pod install

# Core subspec of Rage
pod 'Rage', '~> 0.14.0'

Or if you want to use RxSwift features you should use these Rage subspec

# RxSwift only
pod "Rage/RxSwift", "~> 0.14.0"

License

The MIT License (MIT)

Copyright (c) 2016-2018 gspd.mobi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Github

link
Stars: 8
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

0.9.0 - Feb 16, 2017

  • Arrays of Mappable objects now can be used as request body, multipart request part and stub object.

0.8.1 - Jan 7, 2017

  • Libraries versions updated
  • Plugins directory now included to core subspec
  • Example project improved

0.6.1 - Oct 9, 2016

  • Moving to Swift 3
  • ErrorHandler protocol created.
  • Encoding posibility added to field parameters.

0.5.0 - Sep 11, 2016

  • Multipart requests added.
  • Body requests / Form Url Encoded requests moved to separate classes so it will be harder to add parameter which is not supported for given request type.
  • Optional response stubbing added.
  • Url requests added. Basically now base url can be changed for each request, not for client.
  • Parameter passing nil behavior fixed. If nil passed - this parameter won't be added to request.
  • Plugin protocol updated.
  • Logging plugin improvements.

0.4.2 - Aug 29, 2016

  • Basic plugin system. Logging now made as a plugin.
  • Requests authorization.
  • Error handling improvement.