Exception: Echonest::Error
- Inherits:
-
Exception
- Object
- Exception
- Echonest::Error
- Defined in:
- lib/echonest-ruby-api/error.rb
Constant Summary collapse
- ERRORS =
{ '-1' => 'Unknown Error', '0' => 'Success', '1' => 'Invalid/Missing API Key', '2' => 'This API key is not allowed to call that method', '3' => 'Rate limit exceeded', '4' => 'Missing parameter', '5' => 'Invalid parameter', '6' => 'Missing echoprint-codegen binary on $PATH' }
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #description ⇒ Object
- #details ⇒ Object
-
#initialize(error_code, response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(error_code, response = nil) ⇒ Error
Returns a new instance of Error.
16 17 18 19 |
# File 'lib/echonest-ruby-api/error.rb', line 16 def initialize(error_code, response = nil) @error_code = error_code @response = response end |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
4 5 6 |
# File 'lib/echonest-ruby-api/error.rb', line 4 def error_code @error_code end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/echonest-ruby-api/error.rb', line 4 def response @response end |
Instance Method Details
#description ⇒ Object
21 22 23 |
# File 'lib/echonest-ruby-api/error.rb', line 21 def description ERRORS[@error_code.to_s] end |
#details ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/echonest-ruby-api/error.rb', line 25 def details if error_code == 3 # Returns a hash similar to {"remaining"=>0, "limit"=>20, "used"=>29}. Hash[response.headers.select{|k,v| k =~ /x-ratelimit/}. map{ |k,v| [k.sub('x-ratelimit-', ''), v.first.to_i] }] end end |