Class: UnitHosting::Agent

Inherits:
Mechanize
  • Object
show all
Defined in:
lib/unit-hosting/agent.rb

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



8
9
10
11
# File 'lib/unit-hosting/agent.rb', line 8

def initialize
  super
  max_history = 0
end

Instance Method Details

#getr(path) ⇒ Object



13
14
15
# File 'lib/unit-hosting/agent.rb', line 13

def getr path
  get(UHURL + path)
end

#group(id) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/unit-hosting/agent.rb', line 40

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

#groupsObject



48
49
50
51
52
53
# File 'lib/unit-hosting/agent.rb', line 48

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) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/unit-hosting/agent.rb', line 17

def  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?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/unit-hosting/agent.rb', line 31

def login?
  getr("/dashboard")
  /ログアウト/ =~ page_body # => OK
end

#logoutObject



36
37
38
# File 'lib/unit-hosting/agent.rb', line 36

def logout
  getr("/logout")
end

#page_body(enc = 'utf-8') ⇒ Object



25
26
27
28
29
# File 'lib/unit-hosting/agent.rb', line 25

def page_body enc='utf-8'
  body = page.body
  body.force_encoding(enc) if body.respond_to?(:force_encoding)
  body
end