Module: Dcmgr::Endpoints

Defined in:
lib/dcmgr.rb,
lib/dcmgr/endpoints/errors.rb,
lib/dcmgr/endpoints/core_api.rb,
lib/dcmgr/endpoints/metadata.rb

Defined Under Namespace

Classes: APIError, CoreAPI, DeprecatedAPIError, Ec2Metadata, Metadata

Constant Summary collapse

HTTP_X_VDC_REQUESTER_TOKEN =

HTTP Header constants for request credentials.

'HTTP_X_VDC_REQUESTER_TOKEN'.freeze
HTTP_X_VDC_ACCOUNT_UUID =
'HTTP_X_VDC_ACCOUNT_UUID'.freeze
RACK_FRONTEND_SYSTEM_ID =
'dcmgr.frotend_system.id'

Class Method Summary collapse

Class Method Details

.define_error(class_name, status_code, error_code, &blk) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/dcmgr/endpoints/errors.rb', line 5

def self.define_error(class_name, status_code, error_code, &blk)
  c = Class.new(APIError)
  c.status_code(status_code)
  c.error_code(error_code)
  c.instance_eval(&blk) if blk
  self.set_error_code_type(error_code, c)
  self.const_set(class_name.to_sym, c)
end

.deprecated_error(class_name, status_code, error_code, &blk) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/dcmgr/endpoints/errors.rb', line 14

def self.deprecated_error(class_name, status_code, error_code, &blk)
  c = Class.new(DeprecatedAPIError)
  c.status_code(status_code)
  c.error_code(error_code)
  c.instance_eval(&blk) if blk
  self.set_error_code_type(error_code, c)
  self.const_set(class_name.to_sym, c)
end

.set_error_code_type(error_code, klass) ⇒ Object

Raises:

  • (TypeError)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dcmgr/endpoints/errors.rb', line 24

def self.set_error_code_type(error_code, klass)
  raise TypeError unless klass < APIError
  if @error_code_map.has_key?(error_code)
    if @error_code[error_code] == klass
    else
      raise "Duplicate Error Code Registration: #{klass}, code=#{error_code}"
    end
  else
    @error_code_map[error_code]=klass
  end
end