http_utilities 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +22 -0
- data/README +15 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/http_utilities.gemspec +78 -0
- data/lib/generators/active_record/http_utilities_generator.rb +21 -0
- data/lib/generators/active_record/templates/migration.rb +34 -0
- data/lib/generators/active_record/templates/proxy.rb +3 -0
- data/lib/generators/helpers/file_helper.rb +35 -0
- data/lib/generators/helpers/orm_helpers.rb +15 -0
- data/lib/generators/http_utilities/http_utilities_generator.rb +25 -0
- data/lib/generators/templates/http_utilities.rb +2 -0
- data/lib/generators/templates/user_agents.yml +3419 -0
- data/lib/http_utilities/http/adapters/curb.rb +107 -0
- data/lib/http_utilities/http/adapters/net_http.rb +130 -0
- data/lib/http_utilities/http/adapters/open_uri.rb +46 -0
- data/lib/http_utilities/http/client.rb +22 -0
- data/lib/http_utilities/http/cookies.rb +49 -0
- data/lib/http_utilities/http/format.rb +26 -0
- data/lib/http_utilities/http/get.rb +67 -0
- data/lib/http_utilities/http/logger.rb +11 -0
- data/lib/http_utilities/http/mechanize/client.rb +197 -0
- data/lib/http_utilities/http/post.rb +32 -0
- data/lib/http_utilities/http/proxy_support.rb +88 -0
- data/lib/http_utilities/http/request.rb +20 -0
- data/lib/http_utilities/http/response.rb +50 -0
- data/lib/http_utilities/http/url.rb +48 -0
- data/lib/http_utilities/http/user_agent.rb +3380 -0
- data/lib/http_utilities/jobs/resque/proxies/check_proxies_job.rb +15 -0
- data/lib/http_utilities/jobs/resque/proxies/check_proxy_job.rb +21 -0
- data/lib/http_utilities/jobs/sidekiq/proxies/check_proxies_job.rb +17 -0
- data/lib/http_utilities/jobs/sidekiq/proxies/check_proxy_job.rb +22 -0
- data/lib/http_utilities/proxies/proxy_checker.rb +122 -0
- data/lib/http_utilities/proxies/proxy_module.rb +70 -0
- data/lib/http_utilities/proxies/proxy_seeder.rb +104 -0
- data/lib/http_utilities/railtie.rb +11 -0
- data/lib/http_utilities.rb +47 -0
- data/lib/tasks/http_utilities_tasks.rake +19 -0
- data/spec/database.yml.example +10 -0
- data/spec/http_utilities/client_spec.rb +145 -0
- data/spec/http_utilities/mechanize_client_spec.rb +35 -0
- data/spec/http_utilities/proxy_checker_spec.rb +11 -0
- data/spec/http_utilities/proxy_seeder_spec.rb +24 -0
- data/spec/http_utilities/proxy_spec.rb +114 -0
- data/spec/models.rb +6 -0
- data/spec/schema.rb +30 -0
- data/spec/spec_helper.rb +50 -0
- metadata +209 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe HttpUtilities::Proxies::ProxySeeder do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
before(:each) do
|
7
|
+
@seeder = HttpUtilities::Proxies::ProxySeeder.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should parse proxies from text files" do
|
11
|
+
proxy_data = @seeder.parse_proxies
|
12
|
+
proxy_data.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
#Can only be tested on mysql, sqlite will fail with ConstraintExceptions (since it does not support on duplicate key update ...)
|
16
|
+
if (ENV['DB'] == 'mysql')
|
17
|
+
it "should import parsed proxies using activerecord-import" do
|
18
|
+
@seeder.seed
|
19
|
+
::Proxy.count.should > 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Proxy do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
before(:each) do
|
7
|
+
clean_database!
|
8
|
+
@proxy = Proxy.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to proxy address module instance method" do
|
12
|
+
@proxy.should respond_to(:proxy_address)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should correctly return a formatted proxy address" do
|
16
|
+
@proxy.host = "127.0.0.1"
|
17
|
+
@proxy.port = 80
|
18
|
+
|
19
|
+
@proxy.proxy_address.should == "127.0.0.1:80"
|
20
|
+
@proxy.proxy_address(include_http = true).should == "http://127.0.0.1:80"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should correctly return formatted proxy credentials" do
|
24
|
+
@proxy.username = "usr"
|
25
|
+
@proxy.password = "passw"
|
26
|
+
|
27
|
+
@proxy.proxy_credentials.should == "usr:passw"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "in a class context" do
|
32
|
+
it "should respond to get random proxy module class method" do
|
33
|
+
Proxy.should respond_to(:get_random_proxy)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should respond to format proxy address module class method" do
|
37
|
+
Proxy.should respond_to(:format_proxy_address)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond to format proxy credentials module class method" do
|
41
|
+
Proxy.should respond_to(:format_proxy_credentials)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should respond to should_be_checked-scope" do
|
45
|
+
Proxy.should respond_to(:should_be_checked)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when fetching proxies" do
|
50
|
+
before(:each) do
|
51
|
+
clean_database!
|
52
|
+
|
53
|
+
data = {:host => "127.0.0.1",
|
54
|
+
:port => 80,
|
55
|
+
:protocol => 'http',
|
56
|
+
:proxy_type => 'public',
|
57
|
+
:category => 'L1',
|
58
|
+
:valid_proxy => true,
|
59
|
+
:last_checked_at => 1.week.ago
|
60
|
+
}
|
61
|
+
|
62
|
+
#Http Proxies
|
63
|
+
Proxy.create(data)
|
64
|
+
Proxy.create(data.merge!({:port => 81, :proxy_type => 'shared'}))
|
65
|
+
Proxy.create(data.merge!({:port => 82, :proxy_type => 'private'}))
|
66
|
+
|
67
|
+
#Socks Proxies
|
68
|
+
Proxy.create(data.merge!({:port => 83, :protocol => 'socks', :proxy_type => 'public'}))
|
69
|
+
Proxy.create(data.merge!({:port => 84, :protocol => 'socks', :proxy_type => 'shared'}))
|
70
|
+
Proxy.create(data.merge!({:port => 85, :protocol => 'socks', :proxy_type => 'private'}))
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return proxies that should be checked (using default parameters)" do
|
74
|
+
proxies = Proxy.should_be_checked
|
75
|
+
proxies.should_not be_nil
|
76
|
+
proxies.size.should == 6
|
77
|
+
end
|
78
|
+
|
79
|
+
[:http, :socks].each do |protocol|
|
80
|
+
it "should return #{protocol.to_s} proxies that should be checked" do
|
81
|
+
proxies = Proxy.should_be_checked(protocol)
|
82
|
+
proxies.should_not be_nil
|
83
|
+
proxies.size.should == 3
|
84
|
+
end
|
85
|
+
|
86
|
+
[:public, :shared, :private].each do |proxy_type|
|
87
|
+
it "should return #{proxy_type.to_s} #{protocol.to_s} proxies that should be checked" do
|
88
|
+
proxies = Proxy.should_be_checked(protocol, proxy_type)
|
89
|
+
proxies.should_not be_nil
|
90
|
+
proxies.size.should == 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
[:http, :socks].each do |protocol|
|
96
|
+
it "should return a random #{protocol.to_s} proxy" do
|
97
|
+
random_proxy = Proxy.get_random_proxy(protocol)
|
98
|
+
random_proxy.should_not be_nil
|
99
|
+
random_proxy.protocol.should == protocol.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
[:public, :shared, :private].each do |proxy_type|
|
103
|
+
it "should return a random #{proxy_type.to_s} #{protocol.to_s} proxy" do
|
104
|
+
random_proxy = Proxy.get_random_proxy(protocol, proxy_type)
|
105
|
+
random_proxy.should_not be_nil
|
106
|
+
random_proxy.protocol.should == protocol.to_s
|
107
|
+
random_proxy.proxy_type.should == proxy_type.to_s
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/spec/models.rb
ADDED
data/spec/schema.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
execute "DROP TABLE IF EXISTS proxies"
|
3
|
+
|
4
|
+
create_table :proxies do |t|
|
5
|
+
|
6
|
+
t.string :host, :null => false
|
7
|
+
t.integer :port, :null => false
|
8
|
+
t.string :username
|
9
|
+
t.string :password
|
10
|
+
|
11
|
+
t.string :protocol, :null => false, :default => 'http'
|
12
|
+
t.string :proxy_type, :null => false, :defaut => 'public'
|
13
|
+
t.string :category
|
14
|
+
|
15
|
+
t.datetime :last_checked_at
|
16
|
+
t.boolean :valid_proxy, :null => false, :default => false
|
17
|
+
t.integer :successful_attempts, :null => false, :default => 0
|
18
|
+
t.integer :failed_attempts, :null => false, :default => 0
|
19
|
+
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index :proxies, [:host, :port], :unique => true, :name => 'index_unique_proxy'
|
24
|
+
add_index :proxies, :protocol, :name => 'index_protocol'
|
25
|
+
add_index :proxies, :proxy_type, :name => 'index_proxy_type'
|
26
|
+
add_index :proxies, :category, :name => 'index_category'
|
27
|
+
add_index :proxies, :valid_proxy, :name => 'index_valid_proxy'
|
28
|
+
add_index :proxies, :successful_attempts, :name => 'index_successful_attempts'
|
29
|
+
add_index :proxies, :failed_attempts, :name => 'index_failed_attempts'
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
|
7
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
8
|
+
raise RuntimeError, "Your bundler version is too old." +
|
9
|
+
"Run `gem install bundler` to upgrade."
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set up load paths for all bundled gems
|
13
|
+
Bundler.setup
|
14
|
+
rescue Bundler::GemNotFound
|
15
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
16
|
+
"Did you run \`bundlee install\`?"
|
17
|
+
end
|
18
|
+
|
19
|
+
require "active_record"
|
20
|
+
require "logger"
|
21
|
+
Bundler.require
|
22
|
+
|
23
|
+
require File.expand_path('../../lib/http_utilities', __FILE__)
|
24
|
+
|
25
|
+
ENV['DB'] ||= 'sqlite3'
|
26
|
+
|
27
|
+
database_yml = File.expand_path('../database.yml', __FILE__)
|
28
|
+
if File.exists?(database_yml)
|
29
|
+
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
30
|
+
|
31
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
32
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
33
|
+
|
34
|
+
ActiveRecord::Base.silence do
|
35
|
+
ActiveRecord::Migration.verbose = false
|
36
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
37
|
+
load(File.dirname(__FILE__) + '/models.rb')
|
38
|
+
end
|
39
|
+
else
|
40
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.example"
|
41
|
+
end
|
42
|
+
|
43
|
+
def clean_database!
|
44
|
+
models = [Proxy]
|
45
|
+
models.each do |model|
|
46
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
clean_database!
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_utilities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Johnsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mechanize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_xml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord-import
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mysql2
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.3.11
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.3.11
|
125
|
+
description: Wrapper for common Http Libraries (Net:HTTP/Open URI/Curl)
|
126
|
+
email:
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- Gemfile
|
132
|
+
- README
|
133
|
+
- Rakefile
|
134
|
+
- VERSION
|
135
|
+
- http_utilities.gemspec
|
136
|
+
- lib/generators/active_record/http_utilities_generator.rb
|
137
|
+
- lib/generators/active_record/templates/migration.rb
|
138
|
+
- lib/generators/active_record/templates/proxy.rb
|
139
|
+
- lib/generators/helpers/file_helper.rb
|
140
|
+
- lib/generators/helpers/orm_helpers.rb
|
141
|
+
- lib/generators/http_utilities/http_utilities_generator.rb
|
142
|
+
- lib/generators/templates/http_utilities.rb
|
143
|
+
- lib/generators/templates/user_agents.yml
|
144
|
+
- lib/http_utilities.rb
|
145
|
+
- lib/http_utilities/http/adapters/curb.rb
|
146
|
+
- lib/http_utilities/http/adapters/net_http.rb
|
147
|
+
- lib/http_utilities/http/adapters/open_uri.rb
|
148
|
+
- lib/http_utilities/http/client.rb
|
149
|
+
- lib/http_utilities/http/cookies.rb
|
150
|
+
- lib/http_utilities/http/format.rb
|
151
|
+
- lib/http_utilities/http/get.rb
|
152
|
+
- lib/http_utilities/http/logger.rb
|
153
|
+
- lib/http_utilities/http/mechanize/client.rb
|
154
|
+
- lib/http_utilities/http/post.rb
|
155
|
+
- lib/http_utilities/http/proxy_support.rb
|
156
|
+
- lib/http_utilities/http/request.rb
|
157
|
+
- lib/http_utilities/http/response.rb
|
158
|
+
- lib/http_utilities/http/url.rb
|
159
|
+
- lib/http_utilities/http/user_agent.rb
|
160
|
+
- lib/http_utilities/jobs/resque/proxies/check_proxies_job.rb
|
161
|
+
- lib/http_utilities/jobs/resque/proxies/check_proxy_job.rb
|
162
|
+
- lib/http_utilities/jobs/sidekiq/proxies/check_proxies_job.rb
|
163
|
+
- lib/http_utilities/jobs/sidekiq/proxies/check_proxy_job.rb
|
164
|
+
- lib/http_utilities/proxies/proxy_checker.rb
|
165
|
+
- lib/http_utilities/proxies/proxy_module.rb
|
166
|
+
- lib/http_utilities/proxies/proxy_seeder.rb
|
167
|
+
- lib/http_utilities/railtie.rb
|
168
|
+
- lib/tasks/http_utilities_tasks.rake
|
169
|
+
- spec/database.yml.example
|
170
|
+
- spec/http_utilities/client_spec.rb
|
171
|
+
- spec/http_utilities/mechanize_client_spec.rb
|
172
|
+
- spec/http_utilities/proxy_checker_spec.rb
|
173
|
+
- spec/http_utilities/proxy_seeder_spec.rb
|
174
|
+
- spec/http_utilities/proxy_spec.rb
|
175
|
+
- spec/models.rb
|
176
|
+
- spec/schema.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
homepage: http://github.com/Agiley/http_utilities
|
179
|
+
licenses: []
|
180
|
+
metadata: {}
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.3.5
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.0.3
|
198
|
+
signing_key:
|
199
|
+
specification_version: 2
|
200
|
+
summary: Wrapper for common Http Libraries (Net:HTTP/Open URI/Curl)
|
201
|
+
test_files:
|
202
|
+
- spec/http_utilities/client_spec.rb
|
203
|
+
- spec/http_utilities/mechanize_client_spec.rb
|
204
|
+
- spec/http_utilities/proxy_checker_spec.rb
|
205
|
+
- spec/http_utilities/proxy_seeder_spec.rb
|
206
|
+
- spec/http_utilities/proxy_spec.rb
|
207
|
+
- spec/models.rb
|
208
|
+
- spec/schema.rb
|
209
|
+
- spec/spec_helper.rb
|