Class: Underpass::QL::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/underpass/ql/request.rb

Overview

Deals with performing the Overpass API request

Constant Summary collapse

API_URI =
'https://overpass-api.de/api/interpreter'.freeze
QUERY_TEMPLATE =
"  [out:json][timeout:25]BBOX;\n  (\n    QUERY\n  );\n  out body;\n  >;\n  out skel qt;\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(query, bbox) ⇒ Request



18
19
20
21
# File 'lib/underpass/ql/request.rb', line 18

def initialize(query, bbox)
  @overpass_query = query
  @global_bbox ||= "[#{bbox}]"
end

Instance Method Details

#runObject

Performs the API request



24
25
26
27
28
# File 'lib/underpass/ql/request.rb', line 24

def run
  query = QUERY_TEMPLATE.sub('BBOX', @global_bbox)
                        .sub('QUERY', @overpass_query)
  Net::HTTP.post_form(URI(API_URI), data: query)
end