Class: OSMN::Search
Instance Method Summary collapse
-
#initialize(params) ⇒ Search
constructor
A new instance of Search.
- #params ⇒ Object
- #params=(value) ⇒ Object
- #search ⇒ Object
Constructor Details
#initialize(params) ⇒ Search
Returns a new instance of Search.
4 5 6 7 |
# File 'lib/osmn/search.rb', line 4 def initialize(params) @params = {} self.params = params end |
Instance Method Details
#params ⇒ Object
32 33 34 |
# File 'lib/osmn/search.rb', line 32 def params @params end |
#params=(value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/osmn/search.rb', line 21 def params=(value) if value.is_a? Hash value.each do |k,v| @params[k.to_sym] = v end end # We override the format because we expect a JSON response @params[:format] = :json end |
#search ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/osmn/search.rb', line 9 def search if @params[:q] query = build_query(@params) uri = URI("http://nominatim.openstreetmap.org/search?#{query}") request = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'}) response = Net::HTTP.start(uri.host, uri.port) {|http| http.request(request)} results = build_results(response.body) if response.code == '200' end end |