Class: Eclaircir::Status

Inherits:
BaseModel show all
Defined in:
lib/eclaircir/api_models/status.rb

Constant Summary collapse

SUCCESS =

statuses

10_000
FAILURE =
10_020
INVALID_AUTH_TOKEN =
11_001
API_KEY_NOT_FOUND =
11_009
BAD_REQUEST_FORMAT =
11_100
INVALID_REQUEST =
11_102
DUPLICATE_URL =
30_100
IMAGE_DECODING_FAILED =
30_300
ERRORS_MAPPINGS =
{
  INVALID_AUTH_TOKEN    => InvalidAuthTokenError,
  API_KEY_NOT_FOUND     => ApiKeyNotFoundError,
  BAD_REQUEST_FORMAT    => BadRequestFormatError,
  INVALID_REQUEST       => InvalidRequestError,
  DUPLICATE_URL         => DuplicateURLError,
  IMAGE_DECODING_FAILED => ImageDecodingError,
}.freeze

Instance Method Summary collapse

Methods inherited from BaseModel

#to_api_hash

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/eclaircir/api_models/status.rb', line 10

def success?
  code == SUCCESS
end

#validate!Object



14
15
16
17
18
19
20
21
# File 'lib/eclaircir/api_models/status.rb', line 14

def validate!
  unless success?
    error_class = ERRORS_MAPPINGS.fetch(code, APIError)
    raise error_class, description
  end

  true
end