Sha256: 109ffc3ee8eae7a4c19eb3dbc1918bfcb6928563f7bf36dad49ced3eb7e34c18

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8
module ProxyTester
  class CapybaraProxy

    attr_accessor :host, :user
    attr_reader :port, :type

    def port=(value)
      @port = value.to_i
    end

    def type=(value)
      case value
      when :none
        @type = 'none'
      when :socks5
        @type = 'socks5'
      when :http
        @type = 'http'
      else
        raise Exceptions::ProxyTypeInvalid, JSON.dump(type: value)
      end
    end

    def to_sym
      return :no_proxy if host.blank? or port.blank?

      result = []

      result << host
      result << port
      result << user.name unless user.blank?

      result.join('_').to_sym
    end

    def as_phantomjs_arguments
      result = []
      result << "--proxy=#{to_connect}" if host || port
      result << "--proxy-type=#{type}" if type
      result << "--proxy-auth=#{user.to_login(cleartext: true)}" if user

      result
    end

    def blank?
      host.blank? and port.blank?
    end

    def to_connect
      "#{host}:#{port}".shellescape
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proxy_tester-0.1.10 lib/proxy_tester/capybara_proxy.rb
proxy_tester-0.1.8 lib/proxy_tester/capybara_proxy.rb
proxy_tester-0.1.6 lib/proxy_tester/capybara_proxy.rb
proxy_tester-0.1.5 lib/proxy_tester/capybara_proxy.rb
proxy_tester-0.1.4 lib/proxy_tester/capybara_proxy.rb
proxy_tester-0.1.3 lib/proxy_tester/capybara_proxy.rb