Exception: GreatSchools::Error
- Inherits:
-
StandardError
- Object
- StandardError
- GreatSchools::Error
- Defined in:
- lib/great_schools/error.rb
Overview
GreatSchools Error
Encompass any errors sent back by the GreatSchools API.
GreatSchools sends back XML to all API requests. The error response looks like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<errorCode>3</errorCode>
<faultString>Invalid API key.</faultString>
<date>2013/11/22</date>
<call>/reviews/city/CA/Foster-City</call>
</error>
Examples
The most common error is trying to request data that your API key does not have access to.
GreatSchools::API.key = 'INVALID_KEY'
GreatSchools::Review.for_city('CA', 'Foster City')
# => #<GreatSchools::Error error_code: "3", fault_string: "Invalid API key.", call: "/reviews/city/CA/Foster-City", date: "2013/11/22">
Instance Attribute Summary collapse
-
#call ⇒ Object
readonly
Returns the value of attribute call.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
Instance Method Summary collapse
-
#initialize(response) ⇒ Error
constructor
Creates a new
GreatSchools::Error
from a parsedHTTParty
response. -
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(response) ⇒ Error
Creates a new GreatSchools::Error
from a parsed HTTParty
response. The faultString
is used as the error message
.
Attributes
-
response
- a parsed response object fromHTTParty
– TODO: add error handling - ensure we have a Hash
, use fetch
with defaults ++
39 40 41 42 43 44 45 |
# File 'lib/great_schools/error.rb', line 39 def initialize(response) super(response['error']['faultString']) @call = response['error']['call'] @date = response['error']['date'] @error_code = response['error']['errorCode'] end |
Instance Attribute Details
#call ⇒ Object (readonly)
Returns the value of attribute call.
26 27 28 |
# File 'lib/great_schools/error.rb', line 26 def call @call end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
26 27 28 |
# File 'lib/great_schools/error.rb', line 26 def date @date end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
26 27 28 |
# File 'lib/great_schools/error.rb', line 26 def error_code @error_code end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/great_schools/error.rb', line 47 def inspect # :nodoc: "#<#{self.class} error_code: \"#{error_code}\", fault_string: \"#{}\", call: \"#{call}\", date: \"#{date}\">" end |