Class: GCoder::GeocodingAPI::Response
- Inherits:
-
Object
- Object
- GCoder::GeocodingAPI::Response
- Defined in:
- lib/gcoder/geocoding_api.rb
Instance Method Summary collapse
- #accuracy ⇒ Object
- #administrative_area_name ⇒ Object
- #box ⇒ Object
- #country_code ⇒ Object
- #country_name ⇒ Object
-
#initialize(request) ⇒ Response
constructor
A new instance of Response.
- #latitude ⇒ Object
- #longitude ⇒ Object
- #status ⇒ Object
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(request) ⇒ Response
Returns a new instance of Response.
90 91 92 93 |
# File 'lib/gcoder/geocoding_api.rb', line 90 def initialize(request) @request = request @response = JSON.parse(@request.http_get) end |
Instance Method Details
#accuracy ⇒ Object
131 132 133 |
# File 'lib/gcoder/geocoding_api.rb', line 131 def accuracy address_details['Accuracy'] end |
#administrative_area_name ⇒ Object
151 152 153 |
# File 'lib/gcoder/geocoding_api.rb', line 151 def administrative_area_name administrative_area['AdministrativeAreaName'] end |
#box ⇒ Object
124 125 126 127 128 129 |
# File 'lib/gcoder/geocoding_api.rb', line 124 def box { :north => latlon_box['north'], :south => latlon_box['south'], :east => latlon_box['east'], :west => latlon_box['west'] } end |
#country_code ⇒ Object
147 148 149 |
# File 'lib/gcoder/geocoding_api.rb', line 147 def country_code country['CountryNameCode'] end |
#country_name ⇒ Object
143 144 145 |
# File 'lib/gcoder/geocoding_api.rb', line 143 def country_name country['CountryName'] end |
#latitude ⇒ Object
135 136 137 |
# File 'lib/gcoder/geocoding_api.rb', line 135 def latitude coordinates[1] end |
#longitude ⇒ Object
139 140 141 |
# File 'lib/gcoder/geocoding_api.rb', line 139 def longitude coordinates[0] end |
#status ⇒ Object
95 96 97 |
# File 'lib/gcoder/geocoding_api.rb', line 95 def status @response['Status']['code'] end |
#to_h ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gcoder/geocoding_api.rb', line 112 def to_h { :accuracy => accuracy, :country => { :name => country_name, :code => country_code, :administrative_area => administrative_area_name }, :point => { :longitude => longitude, :latitude => latitude }, :box => box } end |
#validate! ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gcoder/geocoding_api.rb', line 99 def validate! case status when 400 raise Errors::APIMalformedRequestError, 'The GMaps Geo API has ' \ 'indicated that the request is not formed correctly: ' \ "(#{@request.uri})\n\n#{@request.inspect}" when 602 raise Errors::APIGeocodingError, 'The GMaps Geo API has indicated ' \ "that it is not able to geocode the request: (#{@request.uri})" \ "\n\n#{@request.inspect}" end end |