Class: Hyperb::Client

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/hyperb/client.rb

Overview

client class

Constant Summary collapse

REGIONS =
[
  'us-west-1',
  'eu-central-1'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Funcs

#call_func, #create_func, #funcs, #remove_func, #status_func

Methods included from Utils

#camelize, #check_arguments, #downcase_symbolize, #prepare_json, #underscore

Methods included from Compose

#compose_create, #compose_down, #compose_rm, #compose_up

Methods included from Services

#create_service, #inspect_service, #remove_service, #services

Methods included from Snapshots

#create_snapshot

Methods included from Network

#fip_allocate, #fip_attach, #fip_detach, #fip_name, #fip_release, #fips_ls

Methods included from Misc

#info, #version

Methods included from Volumes

#create_volume, #inspect_volume, #remove_volume, #volumes

Methods included from Containers

#container_logs, #container_stats, #containers, #create_container, #inspect_container, #kill_container, #remove_container, #rename_container, #start_container, #stop_container

Methods included from Images

#create_image, #images, #inspect_image, #remove_image

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
# File 'lib/hyperb/client.rb', line 16

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  validate_and_set_region
  yield(self) if block_given?
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



14
15
16
# File 'lib/hyperb/client.rb', line 14

def access_key
  @access_key
end

#regionObject

Returns the value of attribute region.



14
15
16
# File 'lib/hyperb/client.rb', line 14

def region
  @region
end

#secret_keyObject

Returns the value of attribute secret_key.



14
15
16
# File 'lib/hyperb/client.rb', line 14

def secret_key
  @secret_key
end

Instance Method Details

#blank?(val) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/hyperb/client.rb', line 51

def blank?(val)
  val.respond_to?(:empty?) ? val.empty? : !val
end

#credentialsObject



40
41
42
43
44
45
# File 'lib/hyperb/client.rb', line 40

def credentials
  {
    secret_key: secret_key,
    access_key: access_key
  }
end

#credentials?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/hyperb/client.rb', line 47

def credentials?
  credentials.values.none? { |cred| blank?(cred) }
end

#default_regionObject



32
33
34
# File 'lib/hyperb/client.rb', line 32

def default_region
  REGIONS.first
end

#supported_region?(region) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hyperb/client.rb', line 36

def supported_region?(region)
  REGIONS.include?(region.to_s)
end

#validate_and_set_regionObject



24
25
26
27
28
29
30
# File 'lib/hyperb/client.rb', line 24

def validate_and_set_region
  if @region.nil?
    @region = default_region
  else
    raise Hyperb::Error::UnsupportedRegion, @region.to_s unless supported_region?(@region)
  end
end