Class: BrDb::LoadStatesJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/br_db/load_states_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'app/jobs/br_db/load_states_job.rb', line 8

def perform(*args)
  resp = HTTParty.get("https://servicodados.ibge.gov.br/api/v1/localidades/estados")
  states = JSON.parse(resp.body).map do |entry|
    {
      id: entry["id"],
      name: entry["nome"],
      code: entry["sigla"]
    }
  end
  State.insert_all(states)
end