Sha256: cc4d40fe96e2869e89b9dfd242060f1bec16b447d4c09ebf6634382d2e3a4db7

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

module CMSScanner
  # Options available in the Browser
  class Browser
    OPTIONS = [
      :cache_ttl,
      :cookie_jar,
      :cookie_string,
      :connect_timeout,
      :http_auth,
      :max_threads,
      :user_agent,
      :user_agents_list,
      :proxy,
      :proxy_auth,
      :random_user_agent,
      :request_timeout
    ]

    attr_accessor(*OPTIONS)

    # @param [ Hash ] options
    def load_options(options = {})
      OPTIONS.each do |sym|
        send("#{sym}=", options[sym]) if options.key?(sym)
      end
    end

    def hydra
      @hydra ||= Typhoeus::Hydra.new(max_concurrency: max_threads || 1)
    end

    # Set the threads attribute and update
    # the max_concurrency of Typhoeus::Hydra
    #
    # @param [ Integer ] number
    def max_threads=(number)
      @max_threads = number.to_i > 0 ? number.to_i : 1
      hydra.max_concurrency = @max_threads
    end

    # @return [ String ] The path to the user agents list
    def user_agents_list
      @user_agents_list ||= File.join(APP_DIR, 'user_agents.txt')
    end

    # @return [ Array<String> ]
    def user_agents
      return @user_agents if @user_agents

      @user_agents = []

      File.open(user_agents_list).each do |line|
        next if line == "\n" || line[0, 1] == '#'
        @user_agents << line.chomp
      end

      @user_agents
    end

    # @return [ String ]
    def default_user_agent
      "CMSScanner v#{VERSION}"
    end

    # @return [ String ] The user agent
    def user_agent
      @user_agent ||= random_user_agent ? user_agents.sample : default_user_agent
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cms_scanner-0.0.31 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.30 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.29 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.28 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.27 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.26 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.25 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.24 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.23 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.22 lib/cms_scanner/browser/options.rb
cms_scanner-0.0.21 lib/cms_scanner/browser/options.rb