Class: Grobi::Places
- Inherits:
-
Object
- Object
- Grobi::Places
- Defined in:
- lib/grobi/places.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
Returns the value of attribute html.
Instance Method Summary collapse
- #google ⇒ Object
-
#initialize(client) ⇒ Places
constructor
A new instance of Places.
- #parse(s) ⇒ Object
- #retrieve(string_or_place, options = {}) ⇒ Object
- #search(latitude_or_placemark, longitude = nil, options = {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Places
Returns a new instance of Places.
4 5 6 |
# File 'lib/grobi/places.rb', line 4 def initialize(client) @client = client end |
Instance Attribute Details
#html ⇒ Object
Returns the value of attribute html.
3 4 5 |
# File 'lib/grobi/places.rb', line 3 def html @html end |
Instance Method Details
#google ⇒ Object
64 65 66 |
# File 'lib/grobi/places.rb', line 64 def google return @client end |
#parse(s) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/grobi/places.rb', line 53 def parse(s) j = JSON.parse(s) @html = j['html_attributions'] if (j['status'] == "OK") places = j['results'] places.collect { |p| Place.new(p) } if places else nil end end |
#retrieve(string_or_place, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/grobi/places.rb', line 27 def retrieve(string_or_place, ={}) if string_or_place.is_a?(String) reference = string_or_place place = Place.new elsif string_or_place.is_a?(Place) reference = string_or_place.reference place = string_or_place else return nil end href='https://maps.googleapis.com/maps/api/place/details/json?' conn = Faraday.new response = conn.get href do |req| req.params['key'] = @client.simple_api_key req.params['sensor'] = 'false' req.params['reference'] = reference req.params['language'] = [:language] if [:language] end j = JSON.parse(response.body) @html = j['html_attributions'] if (j['status'] == 'OK') place.update(j['result']) place end end |
#search(latitude_or_placemark, longitude = nil, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/grobi/places.rb', line 8 def search(latitude_or_placemark, longitude = nil, ={}) if latitude_or_placemark.is_a?(Placemark) latitude = latitude_or_placemark.latitude longitude = latitude_or_placemark.longitude else latitude = latitude_or_placemark longitude = longitude end href='https://maps.googleapis.com/maps/api/place/search/json?' conn = Faraday.new response = conn.get href do |req| req.params['key'] = @client.simple_api_key req.params['location'] = "#{latitude},#{longitude}" req.params['radius'] = 100 # in memter req.params['sensor'] = 'false' end parse(response.body) end |