class TransfGov::State

Attributes

id[R]
nome[R]
regiao[R]
sigla[R]

Public Class Methods

all() click to toggle source
# File lib/transf_gov/state.rb, line 24
def self.all
  response = Faraday.get("#{STATE_ENDPOINT}")
  estados = JSON.parse(response.body)
  estados.map { |attributes| new(attributes) }
end
find(id) click to toggle source
# File lib/transf_gov/state.rb, line 17
def self.find(id)
  sigla = id.is_a?(Symbol) ? id.to_s.upcase : id.upcase
  response = Faraday.get("#{STATE_ENDPOINT}/#{sigla}")
  attributes = JSON.parse(response.body)
  new(attributes)
end
new(attributes) click to toggle source
# File lib/transf_gov/state.rb, line 10
def initialize(attributes)
  @id = attributes["id"] 
  @sigla = attributes["sigla"]
  @regiao = attributes["regiao"]
  @nome = attributes["nome"]
end

Public Instance Methods

cities() click to toggle source
# File lib/transf_gov/state.rb, line 30
def cities
  response = Faraday.get("#{STATE_ENDPOINT}/#{sigla}/municipios")
  municipios = JSON.parse(response.body)
  municipios.map { |attributes| TransfGov::City.new(attributes) }
end