Latest 1.4.2
Homepage https://github.com/arthurgau0419/Moya-Pretty
License MIT
Platforms ios 9.3
Authors

Moya-Pretty

Build Status
Version
License
Platform
Swift 4.1

Moya-Pretty provides many convenient extensions like generic class-based target, plugins, even RESTful traits. This allows you to declare Moya Target more pretty and without writing those extensions again by yourself.

Inspired by Moya and Retrofit. 👍 👍 👍

Moya-Pretty Overview

Usage

Simply, declare your target class:

struct PetService {  
  class PostPetThenResponsePet: CodableTarget<Pet, Pet>, BaseTargetType {
    var method = Method.post
    var path = "pet/"    
  }
  class PostPetOnly: EncodableTarget<Pet>, BaseTargetType {
    var method = Method.post
    var path = "pet/"    
  }
  class GetPets: DecodableTarget<[Pet]>, BaseTargetType {
    var method = Method.get
    var path = "pet/"    
  }
}

Then, execute it:

let provider = MoyaProvider<PetService.AddPet>() 
let pet = Pet(id: 1, name: "Obi")
let target = PetService.AddPet(body: pet)
provider.requestModel(target, completion: { (result) in
switch result {
  case .success(let pet):
    // Pet model here 🎉 🎉 🎉
    print(pet.name)
  case .failure(let error):
    fail(error.localizedDescription)
  }
)

Documention

Generic Target

Codable – decode, encode Json.

  • CodableTarget<Body, Response>
  • EncodableTarget
  • DecodableTarget

ObjectMapper – json, xml, dictionary mapping.

  • MappableTarget<Body, Response>
  • MappableBodyTarget
  • MappableResponseTarget
  • XMLTargetType

Plugins

Useful plugins

  • AcceptHeaderPlugin
  • FlexibleAccessTokenPlugin
  • InternationalizationPlugin

RESTful

Common RESTful trait

  • FilterableTarget
  • FormPostableTarget

RxSwift

Installation:

pod 'Moya-Pretty/RxSwift'

Execute:

let provider = MoyaProvider<PetService.AddPet>() 
let pet = Pet(id: 1, name: "Obi")
let target = PetService.AddPet(body: pet)
provider.rx.requestModel(target).subscribe { event in
  switch event {
    case let .success(pet):
      // Pet model here 🎉 🎉 🎉
      print(pet.name)
    case let .error(error):
      print(error)
  }
}

PromiseKit

Installation:

pod 'Moya-Pretty/PromiseKit'

Execute:

let provider = MoyaProvider<PetService.AddPet>() 
let pet = Pet(id: 1, name: "Obi")
let target = PetService.AddPet(body: pet)
firstly {
  provider.requestModel(target)
}.done { (pet) in
  // Pet model here 🎉 🎉 🎉
  print(pet.name)
}.catch{ (error) in
  print(error)
}

Example

pod try Moya-Pretty

Installation

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

pod 'Moya-Pretty'

pod 'Moya-Pretty/ObjectMapper'

pod 'Moya-Pretty/RxSwift'

pod 'Moya-Pretty/PromiseKit'

pod 'Moya-Pretty/RESTful'

pod 'Moya-Pretty/Plugins'

Author

[email protected]

License

Moya-Pretty is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Moya-Pretty",
    "version": "1.4.2",
    "summary": "Codable, ObjectMapper, RxSwift, PromiseKit, RESTful extensions for Moya.",
    "description": "*Moya-Pretty* provides many convenient extensions like *generic class-based target*, *plugins*, even *RESTful traits*. This allows you to declare [Moya](https://github.com/Moya/Moya) Target more pretty and without writing those extensions again by yourself.",
    "homepage": "https://github.com/arthurgau0419/Moya-Pretty",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ObiCat": "[email protected]"
    },
    "source": {
        "git": "https://github.com/arthurgau0419/Moya-Pretty.git",
        "tag": "1.4.2"
    },
    "social_media_url": "https://twitter.com/Arthurgau",
    "platforms": {
        "ios": "9.3"
    },
    "default_subspecs": [
        "Core"
    ],
    "swift_version": "4.1",
    "subspecs": [
        {
            "name": "Core",
            "dependencies": {
                "Moya": [
                    "~> 11.0"
                ]
            },
            "source_files": "Moya-Pretty/Classes/**/*"
        },
        {
            "name": "Japx",
            "source_files": "Moya-Pretty/SubSpec/Japx/Sources/*",
            "dependencies": {
                "Moya-Pretty/Core": [],
                "Japx/Codable": []
            }
        },
        {
            "name": "ObjectMapper",
            "source_files": "Moya-Pretty/SubSpec/ObjectMapper/Sources/*",
            "dependencies": {
                "Moya-Pretty/Core": [],
                "ObjectMapper": []
            }
        },
        {
            "name": "XMLDictionary",
            "source_files": "Moya-Pretty/SubSpec/XMLDictionary/Sources/*",
            "dependencies": {
                "Moya-Pretty/ObjectMapper": [],
                "XMLDictionary": []
            }
        },
        {
            "name": "PromiseKit",
            "source_files": "Moya-Pretty/SubSpec/Promise/Sources/*",
            "dependencies": {
                "Moya-Pretty/Core": [],
                "PromiseKit": []
            }
        },
        {
            "name": "RxSwift",
            "source_files": "Moya-Pretty/SubSpec/RxSwift/Sources/*",
            "dependencies": {
                "Moya-Pretty/Core": [],
                "Moya/RxSwift": []
            }
        },
        {
            "name": "RESTful",
            "dependencies": {
                "Moya-Pretty/Core": []
            },
            "source_files": "Moya-Pretty/SubSpec/RESTful/Sources/*"
        },
        {
            "name": "Plugins",
            "dependencies": {
                "Moya-Pretty/Core": []
            },
            "source_files": "Moya-Pretty/SubSpec/Plugins/Sources/*"
        }
    ]
}

Pin It on Pinterest

Share This