Class: BrZipCode::ZipCodeAttempt

Inherits:
Object
  • Object
show all
Defined in:
lib/br_zip_code.rb

Instance Method Summary collapse

Instance Method Details

#zip_code_attempt_2(zip_code) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/br_zip_code.rb', line 61

def zip_code_attempt_2 zip_code
  r = HTTParty.get("http://cep.correiocontrol.com.br/#{zip_code}.json")
  hash = { street_type: r["logradouro"].split(' ').first, street: r["logradouro"], state: r["uf"], city: r["localidade"], neighborhood: r["bairro"] }
  if hash[:street].blank?
    raise Exception
  else
    hash
  end
end

#zip_code_attempt_3(zip_code) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/br_zip_code.rb', line 51

def zip_code_attempt_3 zip_code
  r = HTTParty.get("http://cep.republicavirtual.com.br/web_cep.php?cep=#{zip_code}&formato=json")
  hash = { street_type: r["tipo_logradouro"], street: r["tipo_logradouro"] + " " + r["logradouro"], state: r["uf"], city: r["cidade"], neighborhood: r["bairro"] }
  if hash[:street].blank?
    raise Exception
  else
    hash
  end
end