Sha256: b7078bf19c579f053acdad444d50df6b9f280b2e750af8563dc43fea2bf48c93

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

require 'janis/version'
require 'janis/parsing'
require 'yaml'

module Janis
  
  IP_PORT_SEPARATOR = ':'
  PROXY_LIST_PATH = File.dirname(__FILE__) + '/../proxy_server_list.yml'
  
  def self.find(amount, path_to_list = PROXY_LIST_PATH)

		proxy_list = YAML.load_file("#{path_to_list}").split(' ')
		results = []

    proxy_list.each do |url| 
      if results.size < amount
        parsed_from_url = Parsing.parse(url) unless url.include?('#') # Elements should look like ["1.1.1.1:8080", "2.2.2.2:9090"]
        results_from_this_url = parsed_from_url.map { |entry| convert_to_hash(entry) }
        # Result should look like [ { ip: "1.1.1.1", port: "8080" }, { ip: "2.2.2.2", port: "9090" } ]
        results += results_from_this_url
      end
		end

    results[0..amount - 1]
    
	end
  
  private

  def self.convert_to_hash(proxy_string)
    { 
      ip: proxy_string.split(IP_PORT_SEPARATOR).first,
      port: proxy_string.split(IP_PORT_SEPARATOR).last 
    }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
janis-0.1.2 lib/janis.rb