Class: Tap::Mechanize::Agent

Inherits:
WWW::Mechanize
  • Object
show all
Includes:
Configurable
Defined in:
lib/tap/mechanize/agent.rb

Overview

A Configurable version of the WWW::Mechanize class.

Defined Under Namespace

Classes: FormNode

Constant Summary collapse

DEFAULT_ATTRIBUTES =
DEFAULT_ATTRIBUTES.dup

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Agent

Returns a new instance of Agent.



29
30
31
32
# File 'lib/tap/mechanize/agent.rb', line 29

def initialize(config={})
  super()
  initialize_config(config)
end

Instance Method Details

#fetch(request) ⇒ Object

Fetches the specified request. Request must be a hash at least specifying a url; these are the allowed keys and defaults:

url

nil, must be specified

request_method

get

params

{}

headers

{}



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tap/mechanize/agent.rb', line 42

def fetch(request)
  request = symbolize(request)
     
  # note get handles nil request methods (ie '') and has to
  # reassign uri to url to make mechanize happy
  case request[:request_method].to_s
  when /get/i, '' then get(request.merge(:url => request[:uri]))
  when /post/i    then submit(prepare_form(request), nil)
  when /head/i    then head(nil, nil, request)
  when /put/i     then put(nil, nil, request)
  when /delete/i  then delete(nil, nil, request)
  else raise "unsupported request method: #{request.inspect}" 
  end
end