Skip to content

Commit b9d84d2

Browse files
author
Kirill Platonov
committed
Merge branch 'gem'
2 parents 7598c3e + 71d3a76 commit b9d84d2

19 files changed

+393
-107
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bundle/
2+
log/*.log
3+
pkg/

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--drb
2+
--format Fuubar
3+
--color

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source "https://rubygems.org"
2+
3+
gemspec
4+
5+
gem 'turn'
6+
gem 'rspec'
7+
gem 'guard-rspec'
8+
gem 'growl'
9+
gem 'net-ping'
10+
gem 'fuubar'

Gemfile.lock

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
PATH
2+
remote: .
3+
specs:
4+
proxy_manager (0.0.1)
5+
net-ping
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
ansi (1.4.3)
11+
celluloid (0.15.2)
12+
timers (~> 1.1.0)
13+
celluloid-io (0.15.0)
14+
celluloid (>= 0.15.0)
15+
nio4r (>= 0.5.0)
16+
coderay (1.1.0)
17+
diff-lcs (1.2.5)
18+
ffi (1.9.3)
19+
formatador (0.2.4)
20+
fuubar (1.3.2)
21+
rspec (>= 2.14.0, < 3.1.0)
22+
ruby-progressbar (~> 1.3)
23+
growl (1.0.3)
24+
guard (2.6.0)
25+
formatador (>= 0.2.4)
26+
listen (~> 2.7)
27+
lumberjack (~> 1.0)
28+
pry (>= 0.9.12)
29+
thor (>= 0.18.1)
30+
guard-rspec (4.2.8)
31+
guard (~> 2.1)
32+
rspec (>= 2.14, < 4.0)
33+
listen (2.7.1)
34+
celluloid (>= 0.15.2)
35+
celluloid-io (>= 0.15.0)
36+
rb-fsevent (>= 0.9.3)
37+
rb-inotify (>= 0.9)
38+
lumberjack (1.0.5)
39+
method_source (0.8.2)
40+
minitest (4.7.5)
41+
net-ping (1.7.2)
42+
nio4r (1.0.0)
43+
pry (0.9.12.6)
44+
coderay (~> 1.0)
45+
method_source (~> 0.8)
46+
slop (~> 3.4)
47+
rb-fsevent (0.9.4)
48+
rb-inotify (0.9.3)
49+
ffi (>= 0.5.0)
50+
rspec (2.14.1)
51+
rspec-core (~> 2.14.0)
52+
rspec-expectations (~> 2.14.0)
53+
rspec-mocks (~> 2.14.0)
54+
rspec-core (2.14.7)
55+
rspec-expectations (2.14.5)
56+
diff-lcs (>= 1.1.3, < 2.0)
57+
rspec-mocks (2.14.6)
58+
ruby-progressbar (1.4.2)
59+
slop (3.5.0)
60+
thor (0.19.1)
61+
timers (1.1.0)
62+
turn (0.9.7)
63+
ansi
64+
minitest (~> 4)
65+
66+
PLATFORMS
67+
ruby
68+
69+
DEPENDENCIES
70+
fuubar
71+
growl
72+
guard-rspec
73+
net-ping
74+
proxy_manager!
75+
rspec
76+
turn

Guardfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
guard :rspec do
5+
watch(%r{^spec/.+_spec\.rb$})
6+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7+
watch('spec/spec_helper.rb') { "spec" }
8+
9+
# Rails example
10+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14+
watch('config/routes.rb') { "spec/routing" }
15+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
16+
17+
# Capybara features specs
18+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19+
20+
# Turnip features and steps
21+
watch(%r{^spec/acceptance/(.+)\.feature$})
22+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23+
end
24+
25+
notification :growl

LICENSE

Lines changed: 0 additions & 20 deletions
This file was deleted.

MIT-LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Kirill Platonov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

README.rdoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= ProxyManager
2+
3+
This project rocks and uses MIT-LICENSE.

Rakefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
begin
2+
require 'bundler/setup'
3+
rescue LoadError
4+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5+
end
6+
7+
require 'rdoc/task'
8+
9+
RDoc::Task.new(:rdoc) do |rdoc|
10+
rdoc.rdoc_dir = 'rdoc'
11+
rdoc.title = 'ProxyManager'
12+
rdoc.options << '--line-numbers'
13+
rdoc.rdoc_files.include('README.rdoc')
14+
rdoc.rdoc_files.include('lib/**/*.rb')
15+
end
16+
17+
require 'rspec/core/rake_task'
18+
19+
RSpec::Core::RakeTask.new
20+
task default: :spec

lib/proxy_manager.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'proxy_manager/main'
2+
3+
module ProxyManager
4+
def self.root
5+
File.expand_path '../..', __FILE__
6+
end
7+
8+
def self.load(proxies, bad_proxies = nil)
9+
Main.new(proxies, bad_proxies)
10+
end
11+
end

lib/proxy_manager/main.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
module ProxyManager
2+
class Main
3+
attr_reader :list, :bad_list, :list_file, :bad_list_file
4+
5+
def initialize(proxies, bad_proxies)
6+
@list = []
7+
@bad_list = []
8+
9+
if proxies.is_a? Array
10+
load_list_from_array(proxies)
11+
else
12+
if proxies.empty? or bad_proxies.empty?
13+
raise 'Both arguments "proxies" and "bad_proxies" required'
14+
end
15+
16+
@list_file, @bad_list_file = proxies, bad_proxies
17+
18+
load_list_from_file(proxies)
19+
end
20+
end
21+
22+
def connectable?(proxy)
23+
proxy = proxy.chomp.split(':') if proxy.is_a? String
24+
Net::Ping::TCP.new(proxy[0], proxy[1].to_i).ping
25+
end
26+
27+
def get(count = 1)
28+
raise 'List is empty' if @list.empty?
29+
30+
items = []
31+
32+
@list.each_with_index do |proxy, key|
33+
@list.delete_at(key)
34+
35+
if connectable? proxy
36+
@list << proxy
37+
38+
if count == 1
39+
items = proxy
40+
break
41+
else
42+
items << proxy
43+
break if items.size == count
44+
end
45+
else
46+
@bad_list << proxy
47+
end
48+
end
49+
50+
raise 'There are no available proxy' if items.empty?
51+
52+
if @list_file && @bad_list_file
53+
File.open(@list_file, "w+") do |f|
54+
source = ''
55+
56+
@list.each_with_index do |p, index|
57+
source << "#{p[0]}:#{p[1]}"
58+
source << "\n" if @list[index + 1]
59+
end
60+
61+
f.write(source)
62+
end
63+
64+
File.open(@bad_list_file, "w+") do |f|
65+
source = ''
66+
67+
@bad_list.each_with_index do |p, index|
68+
source << "#{p[0]}:#{p[1]}"
69+
source << "\n" if @bad_list[index + 1]
70+
end
71+
72+
f.write(source)
73+
end
74+
end
75+
76+
items
77+
end
78+
79+
private
80+
81+
def load_list_from_array(proxies)
82+
@list = proxies.map { |arg| [arg.split(':')[0], arg.split(':')[1].to_i] }
83+
end
84+
85+
def load_list_from_file(proxies)
86+
File.open(proxies, "r").each do |line|
87+
line = line.chomp.split(':')
88+
if line[0].is_a? String and line[1].is_a? String
89+
@list << [line[0], line[1].to_i]
90+
end
91+
end
92+
end
93+
end
94+
end

lib/tasks/proxy_manager_tasks.rake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# desc "Explaining what the task does"
2+
# task :proxy_manager do
3+
# # Task goes here
4+
# end

proxy_manager.gemspec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
$:.push File.expand_path("../lib", __FILE__)
2+
3+
# Describe your gem and declare its dependencies:
4+
Gem::Specification.new do |s|
5+
s.name = "proxy_manager"
6+
s.version = '0.0.1'
7+
s.authors = ["Kirill Platonov"]
8+
s.email = ["[email protected]"]
9+
s.homepage = "https://github.com/bloodyhistory/proxy_manager"
10+
s.summary = "Ruby proxy manager. Gem for easy usage proxy in parser/web bots."
11+
s.description = <<-DESCRIPTION
12+
This gem is for easy usage proxy in your parsers/web-bots. It will manage your proxy
13+
list and check availability.
14+
DESCRIPTION
15+
16+
s.files = Dir["{lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc", ".rspec"]
17+
s.test_files = Dir["spec/**/*"]
18+
19+
s.add_dependency 'net-ping'
20+
21+
s.add_development_dependency 'turn'
22+
s.add_development_dependency 'rspec'
23+
s.add_development_dependency 'guard-rspec'
24+
s.add_development_dependency 'growl'
25+
s.add_development_dependency 'fuubar'
26+
end

0 commit comments

Comments
 (0)