Class: Botch::Client::MechanizeClient

Inherits:
AbstractClient show all
Defined in:
lib/botch/clients/mechanize_client.rb

Instance Attribute Summary

Attributes inherited from AbstractClient

#client

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MechanizeClient

Returns a new instance of MechanizeClient.



17
18
19
20
# File 'lib/botch/clients/mechanize_client.rb', line 17

def initialize(options = {})
  @client  = :mechanize
  @handler = Mechanize.new
end

Instance Method Details

#get(url, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/botch/clients/mechanize_client.rb', line 22

def get(url, options = {})
  @handler.user_agent = options[:user_agent] if options[:user_agent]
  mechanize_page = @handler.get(url) rescue MechanizeResponseError.new($!)
  parse_response(mechanize_page)
end

#post(url, options = {}) ⇒ Object



28
29
30
31
32
33
# File 'lib/botch/clients/mechanize_client.rb', line 28

def post(url, options = {})
  @handler.user_agent = options[:user_agent] if options[:user_agent]
  url, query = serialize_url(url)
  mechanize_page = @handler.post(url, query) rescue MechanizeResponseError.new($!)
  parse_response(mechanize_page)
end