Class: Cosgrove::Agent

Inherits:
Mechanize
  • Object
show all
Defined in:
lib/cosgrove/agent.rb

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cosgrove/agent.rb', line 7

def initialize
  super('cosgrove')
  
  @agent.user_agent = 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405'
  @agent.keep_alive = false
  @agent.open_timeout = 10
  @agent.read_timeout = 10
  
  # Cookie management, see: https://gist.github.com/makevoid/4282237
  @agent.pre_connect_hooks << Proc.new do 
    @agent.cookie_jar.load COOKIE_FILE if ::File.exist?(COOKIE_FILE)
  end
  
  @agent.post_connect_hooks << Proc.new do
    @agent.cookie_jar.save COOKIE_FILE
  end
end