Class: Sunzi::Vps::Api
- Inherits:
-
Object
- Object
- Sunzi::Vps::Api
- Defined in:
- lib/sunzi/vps/api.rb
Instance Attribute Summary collapse
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #client ⇒ Object
- #compute ⇒ Object
- #config ⇒ Object
- #dns ⇒ Object
-
#initialize(provider) ⇒ Api
constructor
A new instance of Api.
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
#provider ⇒ Object (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
#client ⇒ Object
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 |
#compute ⇒ Object
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 |
#config ⇒ Object
37 38 39 |
# File 'lib/sunzi/vps/api.rb', line 37 def config @config ||= YAML.load(File.read("#{provider}/#{provider}.yml")).to_hashugar end |
#dns ⇒ Object
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 |