class UnitHosting::Agent

Attributes

endpoint[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/unit-hosting/agent.rb, line 8
def initialize
  super
  @endpoint = "https://cloud.unit-hosting.com"
  max_history = 0
end

Public Instance Methods

getr(path) click to toggle source
# File lib/unit-hosting/agent.rb, line 14
def getr path
  get(@endpoint + path)
end
group(id) click to toggle source
# File lib/unit-hosting/agent.rb, line 41
def group(id)
  getr("/my/group/#{id}/info")
  group = Group.new(id)
  group.key  = page.at("span.api-key").text.to_s
  group.name = page.at("span.group-name").text.to_s
  group
end
groups() click to toggle source
# File lib/unit-hosting/agent.rb, line 49
def groups
  getr("/my/group")
  page.search("#server-groups .instance_id a").collect { |a|
    group(a.text.to_s)
  }.extend(Groups)
end
login(id,password) click to toggle source
# File lib/unit-hosting/agent.rb, line 18
def login id,password
  getr("/login")
  form = page.forms[0]
  form.fields.find{|f| f.name == "username" }.value = id
  form.fields.find{|f| f.name == "password" }.value = password
  submit(form)
end
login?() click to toggle source
# File lib/unit-hosting/agent.rb, line 32
def login?
  getr("/dashboard")
  /ログアウト/ =~ page_body # => OK
end
logout() click to toggle source
# File lib/unit-hosting/agent.rb, line 37
def logout
  getr("/logout")
end
page_body(enc='utf-8') click to toggle source
# File lib/unit-hosting/agent.rb, line 26
def page_body enc='utf-8'
  body = page.body
  body.force_encoding(enc) if body.respond_to?(:force_encoding)
  body
end