Sha256: 7af989d0e4f3a98c5a38b7d1ff65d3c596f1461b0f93223bb0cea229c4331596

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

require 'active_support'
require 'active_support/core_ext'

module SEPOMEX_Acrogenesis
  class General < ApiClient
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sepomex_acrogenesis-0.6.0 lib/sepomex_acrogenesis/general.rb
sepomex_acrogenesis-0.5.2 lib/sepomex_acrogenesis/general.rb