Class: Geocoder::Response
- Inherits:
-
Object
- Object
- Geocoder::Response
- Defined in:
- lib/geocoder/response.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
-
#addresses ⇒ Array<Address>
Return an array of addresses that matched the search.
-
#check_status ⇒ Object
Check the status returned by Google and throw exception on results that are not 200.
-
#initialize(json) ⇒ Response
constructor
Initialize the response and check for errors in the Status code.
Constructor Details
#initialize(json) ⇒ Response
Initialize the response and check for errors in the Status code
11 12 13 14 15 |
# File 'lib/geocoder/response.rb', line 11 def initialize(json) @json = json @hash = JSON.parse(json) check_status end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
4 5 6 |
# File 'lib/geocoder/response.rb', line 4 def json @json end |
Instance Method Details
#addresses ⇒ Array<Address>
Return an array of addresses that matched the search
21 22 23 |
# File 'lib/geocoder/response.rb', line 21 def addresses @addresses ||= @hash["Placemark"].map {|place| Address.new(place)} end |
#check_status ⇒ Object
Check the status returned by Google and throw exception on results that are not 200
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/geocoder/response.rb', line 30 def check_status case @hash["Status"]["code"] when 200 then true when 500 raise ServerError, "Unknown server error" when 601 raise MissingAddressError, "Missing address" when 602 raise UnknownAddressError, "Unknown address" when 603 raise UnavailableAddressError, "Unavailable address" when 610 raise InvalidMapKeyError, "Invalid map key" when 620 raise TooManyQueriesError, "Too many queries for map key" else raise UnknownError, "Unknown error: #{@hash['code']}" end end |