Navigation Menu

Skip to content

pogist/Cocoarreios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cocoarreios

CI Status Version License Platform

📬 A pure Swift implementation of some services for brazilian state post office: Correios.

Example

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

Requirements

  • Swift 4 or higher

Usage

Request information about an address based on the given cep.

...

override func viewDidLoad() {
  super.viewDidLoad()
  
  Cocoarreios.request(.address(cep: "01001000")) { result in
    switch result {
    case .success(let address):
      print(address.cep)          // => "01001-000"
      print(address.publicPlace)  // => "Praça da Sé"
      print(address.complement)   // => "lado ímpar"
      print(address.neighborhood) // => "Sé"
      print(address.city)         // => "São Paulo"
      print(address.state)        // => "SP"
      print(address.unity)        // => ""
      print(address.ibge)         // => "3550308"
      print(address.gia)          // => "1004"

    case .failure(let error):
      //Do something with error...  
    }
  }
}

...

It's also possible to use the delegate pattern.

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    let cocoarreios = Cocoarreios()
    cocoarreios.delegate = self

    cocoarreios.request(.address(cep: "01001000"))
  }
}

extension ViewController: CocoarreiosDelegate {
  func receivedAddress(with result: Result<Address, MoyaError>) {
    switch result {
    case .success(let address):
      // Use address here...
      
    case .failure(let error):
      // Do something with error  
    }
  }
}

Installation

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

pod 'Cocoarreios'

Author

pogist, murilo.paixao.2@gmail.com

License

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

About

📬 A pure Swift implementation of some services for brazilian state post office: Correios.

Resources

License

Stars

Watchers

Forks

Packages

No packages published