viacep 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/exceptions.rb +4 -0
- data/lib/service.rb +20 -0
- data/lib/viacep.rb +24 -0
- metadata +75 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 975b270e25133dc39b46c6139c707879d34b52cf4d264335e20bfc29099d5e26
         | 
| 4 | 
            +
              data.tar.gz: f16ffb518a74e69b62f1fbba4c08b17e8c81487a8475365d13dc680dcf8b1a7a
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 2cc2dcf8bd8ef9ad4ed68be18ab89ea0c01c7bb8784f1f9475243123d3d588d2a7c336b55431285a52a41b3104bed62acd6536268ec0fe8c6501ba6a6ced6b29
         | 
| 7 | 
            +
              data.tar.gz: c7991ce8de2e218187524ac6cebbaded33991d5db420649e1044c3f1f13d8e0a21e817feb80be36f72940731bf3adbf7a21497645ddeb351e07633f83ab31908
         | 
    
        data/lib/exceptions.rb
    ADDED
    
    
    
        data/lib/service.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'httparty'
         | 
| 2 | 
            +
            require 'timeout'
         | 
| 3 | 
            +
            require 'exceptions'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module ViaCep
         | 
| 6 | 
            +
              class Service
         | 
| 7 | 
            +
                BASE_URI = 'https://viacep.com.br/ws'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def self.fetch(cep, timeout = nil)
         | 
| 10 | 
            +
                  Timeout::timeout(timeout) do
         | 
| 11 | 
            +
                    response = HTTParty.get("#{BASE_URI}/#{cep}/json")
         | 
| 12 | 
            +
                    if response.code == 404 || response.parsed_response['erro']
         | 
| 13 | 
            +
                      raise AddressNotFound, 'the API responded with HTTP 404'
         | 
| 14 | 
            +
                    else
         | 
| 15 | 
            +
                      response.parsed_response
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
    
        data/lib/viacep.rb
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            require 'service'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ViaCep
         | 
| 4 | 
            +
              class Address
         | 
| 5 | 
            +
                attr_reader :cep, :address, :neighborhood, :city, :state, :ibge, :gia
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(cep, options = {})
         | 
| 8 | 
            +
                  cep = cep.delete('^0-9')
         | 
| 9 | 
            +
                  fill_from_response(Service.fetch(cep, options[:timeout]))
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                private
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def fill_from_response(response)
         | 
| 15 | 
            +
                  @cep          = response['cep']
         | 
| 16 | 
            +
                  @address      = response['logradouro']
         | 
| 17 | 
            +
                  @neighborhood = response['bairro']
         | 
| 18 | 
            +
                  @city         = response['localidade']
         | 
| 19 | 
            +
                  @state        = response['uf']
         | 
| 20 | 
            +
                  @ibge         = response['ibge']
         | 
| 21 | 
            +
                  @gia          = response['gia']
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: viacep
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Vinicius Brasil (@vnbrs)
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2011-09-29 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rspec
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '3.7'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '3.7'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: httparty
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 0.13.7
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 0.13.7
         | 
| 41 | 
            +
            description: 
         | 
| 42 | 
            +
            email: vnbrs@icloud.com
         | 
| 43 | 
            +
            executables: []
         | 
| 44 | 
            +
            extensions: []
         | 
| 45 | 
            +
            extra_rdoc_files: []
         | 
| 46 | 
            +
            files:
         | 
| 47 | 
            +
            - lib/exceptions.rb
         | 
| 48 | 
            +
            - lib/service.rb
         | 
| 49 | 
            +
            - lib/viacep.rb
         | 
| 50 | 
            +
            homepage: 
         | 
| 51 | 
            +
            licenses:
         | 
| 52 | 
            +
            - MIT
         | 
| 53 | 
            +
            metadata: {}
         | 
| 54 | 
            +
            post_install_message: 
         | 
| 55 | 
            +
            rdoc_options: []
         | 
| 56 | 
            +
            require_paths:
         | 
| 57 | 
            +
            - lib
         | 
| 58 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 59 | 
            +
              requirements:
         | 
| 60 | 
            +
              - - ">="
         | 
| 61 | 
            +
                - !ruby/object:Gem::Version
         | 
| 62 | 
            +
                  version: '0'
         | 
| 63 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 64 | 
            +
              requirements:
         | 
| 65 | 
            +
              - - ">="
         | 
| 66 | 
            +
                - !ruby/object:Gem::Version
         | 
| 67 | 
            +
                  version: '0'
         | 
| 68 | 
            +
            requirements: []
         | 
| 69 | 
            +
            rubyforge_project: 
         | 
| 70 | 
            +
            rubygems_version: 2.7.3
         | 
| 71 | 
            +
            signing_key: 
         | 
| 72 | 
            +
            specification_version: 4
         | 
| 73 | 
            +
            summary: Gem responsável por buscar endereços a partir do CEP utilizando a API do
         | 
| 74 | 
            +
              ViaCEP com features úteis como timeout.
         | 
| 75 | 
            +
            test_files: []
         |