Class: UnitHosting::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/unit_hosting/base.rb

Direct Known Subclasses

Vm, VmGroup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_id = nil, api_key = nil) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
22
23
24
25
# File 'lib/unit_hosting/base.rb', line 17

def initialize(instance_id=nil,api_key=nil)
  @instance_id = instance_id
  @api_key = api_key
  @server = XMLRPC::Client.
    new_from_uri("https://www.unit-hosting.com/xmlrpc",nil,1000)
  @server.instance_variable_get(:@http).
    instance_variable_get(:@ssl_context).
    instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
end

Instance Attribute Details

#instance_idObject (readonly)

Returns the value of attribute instance_id.



16
17
18
# File 'lib/unit_hosting/base.rb', line 16

def instance_id
  @instance_id
end

Class Method Details

.load(instance_id) ⇒ Object



26
27
28
# File 'lib/unit_hosting/base.rb', line 26

def self.load(instance_id)
  self.new.load(instance_id)
end

Instance Method Details

#load(instance_id) ⇒ Object



29
30
31
# File 'lib/unit_hosting/base.rb', line 29

def load(instance_id)
  load_key(UnitHosting::keypath(instance_id))
end

#load_key(file) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/unit_hosting/base.rb', line 32

def load_key(file)
  File::open(file) do |f|
    xml = f.read
    doc = REXML::Document.new(xml)
    @instance_id = doc.elements[@instance_id_elm].text
    @api_key = doc.elements[@api_key_elm].text
  end
  self
end

#server_call(method, param = {}) ⇒ Object



41
42
43
44
45
# File 'lib/unit_hosting/base.rb', line 41

def server_call(method,param = {})
  param["instance_id"] = @instance_id
  param["api_key"] = @api_key
  return @server.call(method,param)
end