Sha256: 49ee9eed7e481079a736d5038d39ec2768d9212ccde88e8802f45795fc119b3c

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true
require 'shellwords'

require 'proxy_rb/credentials'
require 'proxy_rb/proxy_url_parser'

# ProxyRb
module ProxyRb
  # Represent proxy
  class HttpProxy
    attr_reader :url, :credentials

    def initialize(parser)
      @url         = parser.proxy_url
      @credentials = parser.credentials
    end

    def host
      url.host
    end

    def port
      url.port
    end

    def user
      credentials.user_name
    end

    def password
      credentials.password
    end

    def empty?
      host.nil? || host.empty?
    end

    # Convert to symbol to reference the proxy
    #
    # @return [Symbol]
    #   <host>_<port>_<credentials>
    def to_ref
      Shellwords.escape(*[host, port, user].compact.join('_')).to_sym
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxy_rb-0.4.0 lib/proxy_rb/http_proxy.rb
proxy_rb-0.3.0 lib/proxy_rb/http_proxy.rb