Exception: GreatSchools::Error

Inherits:
StandardError
  • Object
show all
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

Instance Method Summary collapse

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 from HTTParty

– 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

#callObject (readonly)

Returns the value of attribute call.



26
27
28
# File 'lib/great_schools/error.rb', line 26

def call
  @call
end

#dateObject (readonly)

Returns the value of attribute date.



26
27
28
# File 'lib/great_schools/error.rb', line 26

def date
  @date
end

#error_codeObject (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

#inspectObject

:nodoc:



47
48
49
# File 'lib/great_schools/error.rb', line 47

def inspect # :nodoc:
  "#<#{self.class} error_code: \"#{error_code}\", fault_string: \"#{message}\", call: \"#{call}\", date: \"#{date}\">"
end