Class: SEPOMEX_Acrogenesis::General

Inherits:
ApiClient
  • Object
show all
Defined in:
lib/sepomex_acrogenesis/general.rb

Class Method Summary collapse

Methods inherited from ApiClient

api_base, api_base=, config

Methods included from JsonApi

included

Class Method Details

.info_zip_code(zip_code:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sepomex_acrogenesis/general.rb', line 6

def self.info_zip_code(zip_code:)
  url = "v2/codigo_postal/#{zip_code}"
  response = api_get(url: url)
  raise SEPOMEX_Acrogenesis::RequestError.new if response[:municipio].blank?
  data = {
    zip_code: response[:codigo_postal].present? ? response[:codigo_postal] : nil,
    settlement: response[:colonias][0].present? ? response[:colonias][0] : nil,
    municipality: response[:municipio].present? ? response[:municipio] : nil,
    state: response[:estado].present? ? response[:estado] : nil
  }
  SEPOMEX_Acrogenesis::ZipCode.new(*data.values_at(*SEPOMEX_Acrogenesis::ZipCode.members))
end