Sha256: 1bbfe6c402d9fc2241263c9145d54e70125bb049d58636d2e1bbd265efbbe9be

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
require 'capybara'

require 'proxy_rb/drivers/basic_driver'
require 'proxy_rb/errors'

begin
  require 'capybara/poltergeist'
rescue LoadError => e
  ProxyRb.logger.error %(Error loading `poltergeist`-gem: #{e.message}. Please add `gem poltergeist` to your `Gemfile`)
  exit 1
end

# ProxyRb
module ProxyRb
  # Drivers
  module Drivers
    # Driver for Poltergeist
    class PoltergeistDriver < BasicDriver
      # Register proxy
      #
      # @param [HttpProxy] proxy
      #   The HTTP proxy which should be used for fetching content
      def register(proxy)
        if proxy.empty?
          ::Capybara.current_driver = :poltergeist
          return
        end

        cli_parameters = []
        cli_parameters << "--proxy=#{proxy.url}" unless proxy.url.empty?
        cli_parameters << "--proxy-auth=#{proxy.credentials}" unless proxy.credentials.empty?

        options = {
          phantomjs_options: cli_parameters,
          js_errors: false,
          phantomjs_logger: $stderr
        }

        unless ::Capybara.drivers.key? proxy.to_ref
          ::Capybara.register_driver proxy.to_ref do |app|
            ::Capybara::Poltergeist::Driver.new(app, options)
          end
        end

        ::Capybara.current_driver = proxy.to_ref
      end

      def timeout_errors
        [::Capybara::Poltergeist::TimeoutError]
      end

      def failure_errors
        [::Capybara::Poltergeist::StatusFailError]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
proxy_rb-1.0.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.6 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.5 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.4 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.3 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.2 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.1 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.10.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.9.3 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.9.2 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.9.1 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.9.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.8.3 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.8.2 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.8.1 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.8.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.7.1 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.7.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.6.0 lib/proxy_rb/drivers/poltergeist_driver.rb
proxy_rb-0.5.0 lib/proxy_rb/drivers/poltergeist_driver.rb