Exception: Pandora::APIError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pandora/util/errors.rb

Overview

Raised on errors from the Tuner API

Constant Summary collapse

ERROR_CODE_TO_REASON =

API error code to reason mapping. From pan-do-ra-api.wikia.com/wiki/Json/5#Error_codes

{
  0 => 'INTERNAL',
  1 => 'MAINTENANCE_MODE',
  2 => 'URL_PARAM_MISSING_METHOD',
  3 => 'URL_PARAM_MISSING_AUTH_TOKEN',
  4 => 'URL_PARAM_MISSING_PARTNER_ID',
  5 => 'URL_PARAM_MISSING_USER_ID',
  6 => 'SECURE_PROTOCOL_REQUIRED',
  7 => 'CERTIFICATE_REQUIRED',
  8 => 'PARAMETER_TYPE_MISMATCH',
  9 => 'PARAMETER_MISSING',
  10 => 'PARAMETER_VALUE_INVALID',
  11 => 'API_VERSION_NOT_SUPPORTED',
  12 => 'Pandora not available in this country',
  13 => 'INSUFFICIENT_CONNECTIVITY. Bad sync time?',
  14 => 'Unknown method name?',
  15 => 'Wrong protocol (http/https)?',
  1000 => 'READ_ONLY_MODE',
  1001 => 'INVALID_AUTH_TOKEN',
  1002 => 'INVALID_PARTNER_LOGIN',
  1003 => 'LISTENER_NOT_AUTHORIZED. Account suspended, or Pandora One Subscription or Trial expired.',
  1004 => 'USER_NOT_AUTHORIZED',
  1005 => 'Station limit reached',
  1006 => 'STATION_DOES_NOT_EXIST',
  1007 => 'COMPLIMENTARY_PERIOD_ALREADY_IN_USE',
  1008 => 'CALL_NOT_ALLOWED. Trying to add feedback to a shared station?',
  1009 => 'DEVICE_NOT_FOUND',
  1010 => 'PARTNER_NOT_AUTHORIZED',
  1011 => 'INVALID_USERNAME',
  1012 => 'INVALID_PASSWORD',
  1013 => 'USERNAME_ALREADY_EXISTS',
  1014 => 'DEVICE_ALREADY_ASSOCIATED_TO_ACCOUNT',
  1015 => 'UPGRADE_DEVICE_MODEL_INVALID',
  1018 => 'EXPLICIT_PIN_INCORRECT',
  1020 => 'EXPLICIT_PIN_MALFORMED',
  1023 => 'DEVICE_MODEL_INVALID',
  1024 => 'ZIP_CODE_INVALID',
  1025 => 'BIRTH_YEAR_INVALID',
  1026 => 'BIRTH_YEAR_TOO_YOUNG',
  1027 => 'INVALID_COUNTRY_CODE',
  1027 => 'INVALID_GENDER',
  1034 => 'DEVICE_DISABLED',
  1035 => 'DAILY_TRIAL_LIMIT_REACHED',
  1036 => 'INVALID_SPONSOR',
  1037 => 'USER_ALREADY_USED_TRIAL'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_message, code) ⇒ APIError

Returns a new instance of APIError.



56
57
58
59
# File 'lib/pandora/util/errors.rb', line 56

def initialize(api_message, code)
  @api_message = api_message
  @code = code.to_i
end

Instance Attribute Details

#api_messageObject (readonly)

Returns the value of attribute api_message.



54
55
56
# File 'lib/pandora/util/errors.rb', line 54

def api_message
  @api_message
end

#codeObject (readonly)

Returns the value of attribute code.



54
55
56
# File 'lib/pandora/util/errors.rb', line 54

def code
  @code
end

Instance Method Details

#messageObject



61
62
63
64
65
66
# File 'lib/pandora/util/errors.rb', line 61

def message
  msg = "#{@api_message} (Code: #{@code}"
  reason = ERROR_CODE_TO_REASON[@code]
  msg += " - #{reason}" if reason
  msg + ')'
end