Class: Api::Area

Inherits:
Object
  • Object
show all
Extended by:
AreaData
Defined in:
lib/api/area.rb

Class Method Summary collapse

Methods included from AreaData

area_data, area_json

Class Method Details

.area_full_name(area_id) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/api/area.rb', line 31

def area_full_name(area_id)
  return if area_id.blank?
  res = Rails.cache.fetch("area_full_name/#{area_id}", expires_in: 1.day) do
    retrieve_full_name(area_id)
  end
  res.blank? ? retrieve_full_name(area_id) : res
end

.areas(*fields) ⇒ Object



12
13
14
15
# File 'lib/api/area.rb', line 12

def areas(*fields)
  query_fields = default_fields + fields.join(',')
  filter_areas(area_json("{areas{#{query_fields}}}").dig('data', 'areas'))
end

.areas_for_selectObject



39
40
41
# File 'lib/api/area.rb', line 39

def areas_for_select
  areas.map { |area| [area['title'], area['id']] }
end

.by_rest_api(path, version = :v1) ⇒ Object



8
9
10
# File 'lib/api/area.rb', line 8

def by_rest_api(path, version = :v1)
  area_data("https://map-ms.herokuapp.com/api/#{version}/#{path}")
end

.find(id) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/api/area.rb', line 22

def find(id)
  query_fields = default_fields + ['description',
                                   'reform_office',
                                   'borders{geometry_type, coordinates}',
                                   'center_coords{geometry_type, coordinates}',
                                   'decentralisation_id'].join(',')
  area_json("{full_area(area_id: \"#{id}\") { #{query_fields} } }").dig('data', 'full_area')
end

.find_by_title(part_title) ⇒ Object



43
44
45
# File 'lib/api/area.rb', line 43

def find_by_title(part_title)
  area_json("{ all_areas_by_title(title: \"#{part_title}\") { full_name, mongo_id } }")
end

.full_areas(*fields) ⇒ Object



17
18
19
20
# File 'lib/api/area.rb', line 17

def full_areas(*fields)
  query_fields = default_fields + fields.join(',')
  filter_areas area_json("{full_areas{#{query_fields}}}").dig('data', 'full_areas')
end