Class: OverpassAPI
- Inherits:
-
Object
- Object
- OverpassAPI
- Defined in:
- lib/overpass_api_ruby.rb
Constant Summary collapse
- VERSION =
'0.1.1'- DEFAULT_ENDPOINT =
'http://overpass-api.de/api/interpreter?data='
Instance Method Summary collapse
- #bbox(s, n, w, e) ⇒ Object
-
#initialize(args = {}) ⇒ OverpassAPI
constructor
A new instance of OverpassAPI.
- #query(query) ⇒ Object
- #raw_query(query) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ OverpassAPI
Returns a new instance of OverpassAPI.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/overpass_api_ruby.rb', line 11 def initialize(args={}) bbox = args[:bbox] bbox(bbox[:s],bbox[:n],bbox[:w],bbox[:e]) if bbox cache_expiration_time = args[:cache_expiration_time] || 7200 @cache = Diskcached.new('/tmp/cache',cache_expiration_time,true) @endpoint = args[:endpoint] || DEFAULT_ENDPOINT @json = args[:json] ? "output='json'" : '' @timeout = args[:timeout] ? "timeout='#{args[:timeout]}'" : '' @element_limit = args[:element_limit] ? "element-limit='#{args[:element_limit]}'" : '' end |
Instance Method Details
#bbox(s, n, w, e) ⇒ Object
24 25 26 |
# File 'lib/overpass_api_ruby.rb', line 24 def bbox(s,n,w,e) @bbox = "bbox='#{s},#{w},#{n},#{e}'" end |
#query(query) ⇒ Object
28 29 30 31 32 |
# File 'lib/overpass_api_ruby.rb', line 28 def query(query) return unless query perform "<osm-script #{@bbox} #{@timeout} #{@element_limit} #{@json}>" << "#{query}<print/></osm-script>" end |
#raw_query(query) ⇒ Object
34 35 36 37 |
# File 'lib/overpass_api_ruby.rb', line 34 def raw_query(query) return unless query perform query end |