Class: Botch::Client::MechanizeClient
- Inherits:
-
AbstractClient
- Object
- AbstractClient
- Botch::Client::MechanizeClient
- Defined in:
- lib/botch/clients/mechanize_client.rb
Instance Attribute Summary
Attributes inherited from AbstractClient
Instance Method Summary collapse
- #get(url, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MechanizeClient
constructor
A new instance of MechanizeClient.
- #post(url, options = {}) ⇒ Object
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( = {}) @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, = {}) @handler.user_agent = [:user_agent] if [: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, = {}) @handler.user_agent = [:user_agent] if [:user_agent] url, query = serialize_url(url) mechanize_page = @handler.post(url, query) rescue MechanizeResponseError.new($!) parse_response(mechanize_page) end |