Class: Rmega::APIResponse
- Inherits:
-
Object
- Object
- Rmega::APIResponse
- Defined in:
- lib/rmega/api_response.rb
Constant Summary collapse
- ERRORS =
Check out the error codes list at mega.nz/#doc (section 11)
{ -1 => 'An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred.', -2 => 'You have passed invalid arguments to this command.', -3 => 'A temporary congestion or server malfunction prevented your request from being processed. No data was altered. Retry. Retries must be spaced with exponential backoff.', -4 => 'You have exceeded your command weight per time quota. Please wait a few seconds, then try again (this should never happen in sane real-life applications).', -5 => 'The upload failed. Please restart it from scratch.', -6 => 'Too many concurrent IP addresses are accessing this upload target URL.', -7 => 'The upload file packet is out of range or not starting and ending on a chunk boundary.', -8 => 'The upload target URL you are trying to access has expired. Please request a fresh one.', -9 => 'Object (typically, node or user) not found', -10 => 'Circular linkage attempted', -11 => 'Access violation (e.g., trying to write to a read-only share)', -12 => 'Trying to create an object that already exists', -13 => 'Trying to access an incomplete resource', -14 => 'A decryption operation failed (never returned by the API)', -15 => 'Invalid or expired user session, please relogin', -16 => 'User blocked', -17 => 'Request over quota', -18 => 'Resource temporarily not available, please try again later', -19 => 'Too many connections on this resource', -20 => 'Write failed', -21 => 'Read failed', -22 => 'Invalid application key; request not processed', }.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
- #as_error ⇒ Object
- #as_json ⇒ Object
- #error? ⇒ Boolean
-
#initialize(http_response) ⇒ APIResponse
constructor
A new instance of APIResponse.
- #ok? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ APIResponse
Returns a new instance of APIResponse.
31 32 33 34 |
# File 'lib/rmega/api_response.rb', line 31 def initialize(http_response) @code = http_response.code.to_i @body = http_response.body ? http_response.body : "" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/rmega/api_response.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/rmega/api_response.rb', line 3 def code @code end |
Instance Method Details
#as_error ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/rmega/api_response.rb', line 44 def as_error if unknown_error? return TemporaryServerError.new elsif temporary_error? return TemporaryServerError.new() else return ServerError.new() end end |
#as_json ⇒ Object
54 55 56 |
# File 'lib/rmega/api_response.rb', line 54 def as_json @as_body ||= JSON.parse(body).first end |
#error? ⇒ Boolean
36 37 38 |
# File 'lib/rmega/api_response.rb', line 36 def error? unknown_error? or known_error? or temporary_error? end |
#ok? ⇒ Boolean
40 41 42 |
# File 'lib/rmega/api_response.rb', line 40 def ok? !error? end |