Sha256: 221ada304b0f0b5233d87b59c9112a23624c497c3e002f4bd32f64836ce2fc09

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

require 'tap/mechanize/agent'

module Tap
  module Mechanize
    class Request < Tap::Task
      nest :mechanize, Agent        # the mechanize agent
      
      # Returns the mechanize agent.
      #--
      # Overrides the default reader to ensure the agent log is set.
      def mechanize
        @mechanize ||= begin
          agent = Agent.new
          agent.log = app.logger
          agent
        end
      end
      
      # Submits each request in order and returns the final Page.
      # Returns nil if no requests are specified.
      def process(requests)
        unless requests.kind_of?(Array)
          requests = [requests]
        end
        
        requests.inject(nil) do |last_page, request|
          mechanize.fetch(request)
        end
      end
      
    end 
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tap-mechanize-0.5.0 lib/tap/mechanize/request.rb
tap-mechanize-0.5.1 lib/tap/mechanize/request.rb