require 'janis/version' require 'janis/parsing' require 'yaml' module Janis IP_PORT_SEPARATOR = ':' def self.find(amount, path_to_list = './proxy_server_list.yml') 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