Class: CartoCSSHelper::NotesDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/cartocss_helper/notes_downloader.rb

Class Method Summary collapse

Class Method Details

.cache_filename(lat, lon, range) ⇒ Object



7
8
9
10
# File 'lib/cartocss_helper/notes_downloader.rb', line 7

def self.cache_filename(lat, lon, range)
  url = NotesDownloader.format_query_into_url(lat, lon, range)
  return CartoCSSHelper::Configuration.get_path_to_folder_for_notes_api_cache + url.delete("/") + ".cache"
end

.cache_timestamp(lat, lon, range) ⇒ Object



20
21
22
23
24
# File 'lib/cartocss_helper/notes_downloader.rb', line 20

def self.cache_timestamp(lat, lon, range)
  downloader = GenericCachedDownloader.new
  file = cache_filename(lat, lon, range)
  return downloader.get_cache_timestamp(file)
end

.format_query_into_url(lat, lon, range) ⇒ Object



30
31
32
33
34
35
# File 'lib/cartocss_helper/notes_downloader.rb', line 30

def self.format_query_into_url(lat, lon, range)
  # documentated at http://wiki.openstreetmap.org/wiki/API_v0.6#Map_Notes_API
  bbox = osm_api_bbox_string(lat, lon, range)
  base_url = "http://api.openstreetmap.org/api/0.6/notes"
  return "#{base_url}?bbox=#{bbox}?closed=0"
end

.get_allowed_timeout_in_secondsObject



26
27
28
# File 'lib/cartocss_helper/notes_downloader.rb', line 26

def self.get_allowed_timeout_in_seconds
  return 10 * 60
end

.osm_api_bbox_string(latitude, longitude, size) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/cartocss_helper/notes_downloader.rb', line 37

def self.osm_api_bbox_string(latitude, longitude, size)
  # bbox=left,bottom,right,top
  min_latitude = latitude - size / 2
  max_latitude = latitude + size / 2
  min_longitude = longitude - size / 2
  max_longitude = longitude + size / 2
  return "#{min_longitude},#{min_latitude},#{max_longitude},#{max_latitude}"
end

.run_note_query(lat, lon, range, invalidate_cache: false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cartocss_helper/notes_downloader.rb', line 12

def self.run_note_query(lat, lon, range, invalidate_cache: false)
  timeout = NotesDownloader.get_allowed_timeout_in_seconds
  downloader = GenericCachedDownloader.new(timeout: timeout, stop_on_timeout: false)
  file = cache_filename(lat, lon, range)
  url = NotesDownloader.format_query_into_url(lat, lon, range)
  return downloader.get_specified_resource(url, file, invalidate_cache: invalidate_cache)
end