Class: Sunzi::Vps::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/sunzi/vps/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ Api

Returns a new instance of Api.



18
19
20
21
# File 'lib/sunzi/vps/api.rb', line 18

def initialize(provider)
  @provider = provider
  Sunzi::Dependency.load(mapping[:gem])
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



16
17
18
# File 'lib/sunzi/vps/api.rb', line 16

def provider
  @provider
end

Instance Method Details

#clientObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sunzi/vps/api.rb', line 23

def client
  @client ||= begin
    case provider
    when 'linode'
      ::Linode.new(api_key: config.api_key)
    when 'digital_ocean'
      DropletKit::Client.new(access_token: config.api_key)
    when 'vultr'
      Vultr.api_key = config.api_key
      Vultr
    end
  end
end

#computeObject



41
42
43
# File 'lib/sunzi/vps/api.rb', line 41

def compute
  @compute ||= Object.const_get("Sunzi::Vps::Compute::#{mapping[:klass]}").new(self)
end

#configObject



37
38
39
# File 'lib/sunzi/vps/api.rb', line 37

def config
  @config ||= YAML.load(File.read("#{provider}/#{provider}.yml")).to_hashugar
end

#dnsObject



45
46
47
# File 'lib/sunzi/vps/api.rb', line 45

def dns
  @dns ||= Object.const_get("Sunzi::Vps::DNS::#{mapping[:klass]}").new(self)
end