Class: MapQuest::Response
- Inherits:
-
Object
- Object
- MapQuest::Response
- Defined in:
- lib/mapquest/response.rb
Direct Known Subclasses
Services::Directions::Response, Services::Geocoding::Response
Defined Under Namespace
Classes: InvalidRequest
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #copyright ⇒ Object
- #info ⇒ Object
-
#initialize(response_string, params = {}) ⇒ Response
constructor
A new instance of Response.
- #options ⇒ Object
-
#status ⇒ Object
Returns information about the response.
-
#valid_request? ⇒ Boolean
Check whether the request made to the API call is valid.
Constructor Details
#initialize(response_string, params = {}) ⇒ Response
8 9 10 11 12 |
# File 'lib/mapquest/response.rb', line 8 def initialize(response_string, params = {}) @params = params @response = JSON.parse(response_string, :symbolize_names => true) valid_request? end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/mapquest/response.rb', line 4 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/mapquest/response.rb', line 4 def response @response end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
4 5 6 |
# File 'lib/mapquest/response.rb', line 4 def valid @valid end |
Instance Method Details
#copyright ⇒ Object
34 35 36 |
# File 'lib/mapquest/response.rb', line 34 def copyright info[:copyright] end |
#info ⇒ Object
30 31 32 |
# File 'lib/mapquest/response.rb', line 30 def info response[:info] end |
#options ⇒ Object
38 39 40 |
# File 'lib/mapquest/response.rb', line 38 def response[:options] end |
#status ⇒ Object
Returns information about the response. :code is an integer return value. See www.mapquestapi.com/geocoding/status_codes.html :messages subfield is an array of error messages which describe the status.
45 46 47 |
# File 'lib/mapquest/response.rb', line 45 def status return :code => info[:statuscode].to_i, :messages => info[:messages] end |
#valid_request? ⇒ Boolean
Check whether the request made to the API call is valid. Raises an error if the response code is 500
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mapquest/response.rb', line 15 def valid_request? # 400 - Error with input # 403 - Key related error # 500 -Unknown error # Check http://www.mapquestapi.com/geocoding/status_codes.html for more details @valid = case status[:code] when 500 raise InvalidRequest when 400, 403 false else true end end |