Class: Api::Area
Class Method Summary collapse
- .area_full_name(area_id) ⇒ Object
- .areas(*fields) ⇒ Object
- .areas_for_select ⇒ Object
- .by_rest_api(path, version = :v1) ⇒ Object
- .find(id) ⇒ Object
- .find_by_title(part_title) ⇒ Object
- .full_areas(*fields) ⇒ Object
Methods included from AreaData
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_select ⇒ Object
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 |