Sha256: 557d3dc360e7fc1954f308c8ef339fa80a4003df8ce47597f719c2efb70e8455
Contents?: true
Size: 643 Bytes
Versions: 1
Compression:
Stored size: 643 Bytes
Contents
require 'net/http' require 'nokogiri' require 'addressable/uri' require 'correios/address_search_response' class Cep URL = 'http://m.correios.com.br/movel/buscaCepConfirma.do' def search(term) response = query({cepEntrada: term.parameterize(' '), metodo: :buscarCep}) Correios::AddressSearchResponse.new(response.body).addresses end alias_method :address, :search def cep(cep) search(cep)[0] end def url(params = {}) uri = Addressable::URI.new uri.query_values = params url = "#{Cep::URL}?#{uri.query}" end def query(params = {}) uri = URI(URL) Net::HTTP.post_form(uri, params) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cep-0.0.8 | lib/cep.rb |