Skip to content

Commit

Permalink
fix bug with list
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Platonov committed Mar 31, 2014
1 parent 7fdf91b commit 271bad5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
proxy_manager (0.0.7)
proxy_manager (0.0.8)
net-ping (~> 1.7, >= 1.7.2)

GEM
Expand Down
17 changes: 15 additions & 2 deletions lib/proxy_manager/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize(proxies, bad_proxies)
@list_file, @bad_list_file = proxies, bad_proxies

load_list_from_file(proxies)
load_bad_list_from_file(bad_proxies)
end
end

Expand All @@ -28,12 +29,13 @@ def get(count = 1)
raise 'List is empty' if @list.empty?

items = []
new_list = @list.clone

@list.each_with_index do |proxy, key|
@list.delete_at(key)
new_list.shift

if connectable? proxy
@list << proxy
new_list << proxy

if count == 1
items = proxy
Expand All @@ -47,6 +49,8 @@ def get(count = 1)
end
end

@list = new_list

raise 'There are no available proxy' if items.empty?

if @list_file && @bad_list_file
Expand Down Expand Up @@ -90,5 +94,14 @@ def load_list_from_file(proxies)
end
end
end

def load_bad_list_from_file(bad_proxies)
File.open(bad_proxies, "r").each do |line|
line = line.chomp.split(':')
if line[0].is_a? String and line[1].is_a? String
@bad_list << [line[0], line[1].to_i]
end
end
end
end
end
2 changes: 1 addition & 1 deletion proxy_manager.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "proxy_manager"
s.version = '0.0.8'
s.version = '0.0.9'
s.authors = ["Kirill Platonov"]
s.licenses = ['MIT']
s.email = ["[email protected]"]
Expand Down

0 comments on commit 271bad5

Please sign in to comment.