Sha256: dfc9910919d295ec6187002c11de2186b7f22298f937163ae6e1a59d5dce2ab8
Contents?: true
Size: 812 Bytes
Versions: 1
Compression:
Stored size: 812 Bytes
Contents
module OpenStreetMap class Client # Search objects by query module Search def search(args = {}) response = RestClient.get("#{BASE_URI}search?#{search_arg(args[:q])}&#{search_args_to_url(args)}") args[:format] == 'xml' ? response.body : JSON.parse(response.body) rescue { 'errors' => 'Bad request' } end private def search_arg(arg) "q=#{arg.gsub(/\s+/, '+')}" end def search_args_to_url(args, result = []) valid_search_args(args).each do |key, value| result << "#{key}=#{value}" end result.join('&') end def valid_search_args(args) args.slice(:format, :addressdetails, :extratags, :namedetails, :viewbox, :bounded, :exclude_place_ids, :limit) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
open_street_map-1.0 | lib/open_street_map/client/search.rb |