Class: UnitHosting::Api::Base
- Inherits:
-
Object
- Object
- UnitHosting::Api::Base
- Defined in:
- lib/unit-hosting/api/base.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#server ⇒ Object
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(instance_id = nil, api_key = nil) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #load(instance_id) ⇒ Object
- #load_key(file) ⇒ Object
- #server_call(method, param = {}) ⇒ Object
Constructor Details
#initialize(instance_id = nil, api_key = nil) {|_self| ... } ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/unit-hosting/api/base.rb', line 13 def initialize(instance_id=nil,api_key=nil) @instance_id = instance_id @api_key = api_key @server = XMLRPC::Client. new_from_uri("https://cloud.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) yield self if block_given? self end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/unit-hosting/api/base.rb', line 11 def api_key @api_key end |
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
11 12 13 |
# File 'lib/unit-hosting/api/base.rb', line 11 def instance_id @instance_id end |
#server ⇒ Object
Returns the value of attribute server.
12 13 14 |
# File 'lib/unit-hosting/api/base.rb', line 12 def server @server end |
Class Method Details
.load(instance_id) {|obj| ... } ⇒ Object
24 25 26 27 28 |
# File 'lib/unit-hosting/api/base.rb', line 24 def self.load(instance_id) obj = self.new.load(instance_id) yield obj if block_given? obj end |
Instance Method Details
#load(instance_id) ⇒ Object
29 30 31 |
# File 'lib/unit-hosting/api/base.rb', line 29 def load(instance_id) load_key(UnitHosting::Api::keypath(instance_id)) end |
#load_key(file) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/unit-hosting/api/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 46 47 |
# File 'lib/unit-hosting/api/base.rb', line 41 def server_call(method,param = {}) param["instance_id"] = @instance_id param["api_key"] = @api_key result = @server.call(method,param) # puts @server.http_last_response.body return result end |