Class: Watchman::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/watchman/client.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/watchman/client.rb', line 4

def host
  @host
end

.passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/watchman/client.rb', line 4

def password
  @password
end

.usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/watchman/client.rb', line 4

def username
  @username
end

Instance Method Details



23
24
25
26
27
28
29
30
31
# File 'lib/watchman/client.rb', line 23

def add_cookie(cookie,key)
  cookie.secure = false
  cookie.domain = Client.host
  if agent.cookie_jar.jar[Client.host].nil?
    agent.cookie_jar.jar[Client.host] = {"/"=>{key=>cookie}}
  else
    agent.cookie_jar.jar[Client.host]["/"][key] = cookie
  end
end

#agentObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/watchman/client.rb', line 11

def agent
  if @_agent.nil?
    @_agent = Mechanize.new
    page = @_agent.get("http://#{Client.host}/")
    form = page.form("UserForm")
    form.UserName = Client.username
    form.Password = Client.password
    @_agent.submit(form, form.buttons.first)
  end
  @_agent
end

#get(path) ⇒ Object



7
8
9
# File 'lib/watchman/client.rb', line 7

def get(path)
  agent.get("https://#{Client.host}/#{path}")
end