Module: Api::AreaData

Included in:
Area
Defined in:
lib/api/area_data.rb

Instance Method Summary collapse

Instance Method Details

#area_data(path) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/api/area_data.rb', line 5

def area_data(path)
  res = retrieve_data(path)
  begin
    JSON.parse(res.body)
  rescue StandardError
    { data: { areas: [] } }
  end
end

#area_json(query) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/api/area_data.rb', line 14

def area_json(query)
  # if Rails.env.production?
  Rails.cache.fetch(query, expires_in: 2.minutes) do
    area_data("https://map-ms.herokuapp.com/graphql?query=#{CGI.escape(query)}")
  end
  # else
  # area_data("http://localhost:3000/graphql?query=#{URI.escape(query)}")
  # end
end