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.



15
16
17
18
# File 'lib/botch/clients/mechanize_client.rb', line 15

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

Instance Method Details

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



20
21
22
23
24
# File 'lib/botch/clients/mechanize_client.rb', line 20

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



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

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