Class: Roart::ConnectionAdapters::MechanizeAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/roart/connection_adapters/mechanize_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ MechanizeAdapter

Returns a new instance of MechanizeAdapter.



7
8
9
# File 'lib/roart/connection_adapters/mechanize_adapter.rb', line 7

def initialize(config)
  @conf = config
end

Instance Method Details

#get(uri) ⇒ Object



22
23
24
# File 'lib/roart/connection_adapters/mechanize_adapter.rb', line 22

def get(uri)
  @agent.get(uri).body
end

#login(config) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/roart/connection_adapters/mechanize_adapter.rb', line 11

def (config)
  @conf.merge!(config)
  agent = Mechanize.new
  page = agent.get(@conf[:server])
  form = page.form('login')
  form.user = @conf[:user]
  form.pass = @conf[:pass]
  page = agent.submit form
  @agent = agent
end

#post(uri, payload) ⇒ Object



26
27
28
# File 'lib/roart/connection_adapters/mechanize_adapter.rb', line 26

def post(uri, payload)
  @agent.post(uri, payload).body
end