http_utilities 1.0.6 → 1.0.7
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 +4 -4
- data/http_utilities.gemspec +1 -1
- data/lib/http_utilities.rb +1 -1
- data/lib/http_utilities/http/proxy_support.rb +1 -1
- data/lib/http_utilities/proxies/proxy_checker.rb +13 -4
- data/lib/http_utilities/proxies/proxy_module.rb +27 -20
- data/lib/tasks/http_utilities_tasks.rake +8 -5
- data/spec/http_utilities/proxy_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1c0b02b5b8356187e86ff1e3f45e5899247ee4c
|
4
|
+
data.tar.gz: 124fb89e7a57864d5ec402838bd41002e8fe3470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e26b5382bedec9b718580c74e5f74a7c3ab9f6ee7a25c4724f9e19a2953ba8a0062462dcee452f833673a8eda2af18d2a20ac9abb31f9b7d86be2198d52b31d0
|
7
|
+
data.tar.gz: 2b6fe44dc2398763d0de8c107755ce24344fda557ec3a88080934fda0d141445440e60b4658a9fdf1cc5807007d6385a076722f9faad43119aad8acf55ff8a50
|
data/http_utilities.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = "http_utilities"
|
6
|
-
s.version = "1.0.
|
6
|
+
s.version = "1.0.7"
|
7
7
|
|
8
8
|
s.authors = ["Sebastian Johnsson"]
|
9
9
|
s.description = "Wrapper for common Http Libraries (Net:HTTP/Open URI/Curl)"
|
data/lib/http_utilities.rb
CHANGED
@@ -35,7 +35,7 @@ module HttpUtilities
|
|
35
35
|
self.proxy = specific_proxy
|
36
36
|
|
37
37
|
elsif (proxy_model_defined?)
|
38
|
-
proxy_object = Proxy.get_random_proxy(self.proxy[:protocol], self.proxy[:type])
|
38
|
+
proxy_object = Proxy.get_random_proxy(protocol: self.proxy[:protocol], proxy_type: self.proxy[:type])
|
39
39
|
|
40
40
|
#log(:info, "[HttpUtilities::Http::ProxySupport] - Randomized Proxy object: #{proxy_object.inspect}")
|
41
41
|
|
@@ -19,13 +19,19 @@ module HttpUtilities
|
|
19
19
|
self.maximum_failed_attempts = 10
|
20
20
|
end
|
21
21
|
|
22
|
-
def check_and_update_proxies(protocol
|
23
|
-
check_proxies(protocol, proxy_type, mode)
|
22
|
+
def check_and_update_proxies(protocol: :all, proxy_type: :all, mode: :synchronous, maximum_failed_attempts: self.maximum_failed_attempts)
|
23
|
+
check_proxies(protocol: protocol, proxy_type: proxy_type, mode: mode, maximum_failed_attempts: maximum_failed_attempts)
|
24
24
|
update_proxies
|
25
25
|
end
|
26
26
|
|
27
|
-
def check_proxies(protocol
|
28
|
-
proxies
|
27
|
+
def check_proxies(protocol: :all, proxy_type: :all, mode: :synchronous, maximum_failed_attempts: self.maximum_failed_attempts)
|
28
|
+
proxies = Proxy.should_be_checked(
|
29
|
+
protocol: protocol,
|
30
|
+
proxy_type: proxy_type,
|
31
|
+
date: Time.now,
|
32
|
+
limit: self.limit,
|
33
|
+
maximum_failed_attempts: maximum_failed_attempts
|
34
|
+
)
|
29
35
|
|
30
36
|
if (proxies && proxies.any?)
|
31
37
|
Rails.logger.info "Found #{proxies.size} #{proxy_type} proxies to check."
|
@@ -62,6 +68,9 @@ module HttpUtilities
|
|
62
68
|
client.write("#{test_query}\r\n")
|
63
69
|
response = client.read
|
64
70
|
|
71
|
+
puts "SOCKS RESPONSE:\n"
|
72
|
+
puts response
|
73
|
+
|
65
74
|
valid_proxy = (response && response.present?)
|
66
75
|
|
67
76
|
rescue StandardError => e
|
@@ -8,40 +8,47 @@ module HttpUtilities
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def should_be_checked(protocol
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def should_be_checked(protocol: :all, proxy_type: :all, date: Time.now, limit: 10, maximum_failed_attempts: 10)
|
12
|
+
proxies = get_proxies_for_protocol_and_proxy_type(protocol, proxy_type)
|
13
|
+
proxies = proxies.where(["(last_checked_at IS NULL OR last_checked_at < ?)", date])
|
14
|
+
proxies = proxies.where(["failed_attempts <= ?", maximum_failed_attempts])
|
15
|
+
proxies = proxies.order("valid_proxy ASC, failed_attempts ASC, last_checked_at ASC")
|
16
|
+
proxies = proxies.limit(limit)
|
16
17
|
|
17
|
-
|
18
|
+
return proxies
|
18
19
|
end
|
19
20
|
|
20
|
-
def get_random_proxy(protocol
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
query = conditions.join(" AND ")
|
21
|
+
def get_random_proxy(protocol: :all, proxy_type: :all, maximum_failed_attempts: nil)
|
22
|
+
proxies = get_proxies_for_protocol_and_proxy_type(protocol, proxy_type)
|
23
|
+
proxies = proxies.where(["valid_proxy = ? AND last_checked_at IS NOT NULL", true])
|
24
|
+
proxies = proxies.where(["failed_attempts <= ?", maximum_failed_attempts]) if maximum_failed_attempts
|
25
25
|
|
26
26
|
order_clause = case ActiveRecord::Base.connection.class.name
|
27
|
-
when "ActiveRecord::ConnectionAdapters::MysqlAdapter", "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
|
28
|
-
|
27
|
+
when "ActiveRecord::ConnectionAdapters::MysqlAdapter", "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
|
28
|
+
"RAND() DESC"
|
29
|
+
when "ActiveRecord::ConnectionAdapters::SQLite3Adapter"
|
30
|
+
"RANDOM() DESC"
|
31
|
+
else
|
32
|
+
"RAND() DESC"
|
29
33
|
end
|
30
34
|
|
31
|
-
|
35
|
+
proxies = proxies.order(order_clause)
|
36
|
+
|
37
|
+
proxy = nil
|
32
38
|
|
33
39
|
uncached do
|
34
|
-
proxy
|
40
|
+
proxy = proxies.limit(1).first
|
35
41
|
end
|
36
42
|
|
37
43
|
return proxy
|
38
44
|
end
|
39
45
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
def get_proxies_for_protocol_and_proxy_type(protocol, proxy_type)
|
47
|
+
proxies = ::Proxy.where(nil)
|
48
|
+
proxies = proxies.where(protocol: protocol) if (protocol && !protocol.downcase.to_sym.eql?(:all))
|
49
|
+
proxies = proxies.where(proxy_type: proxy_type) if (proxy_type && !proxy_type.downcase.to_sym.eql?(:all))
|
50
|
+
|
51
|
+
return proxies
|
45
52
|
end
|
46
53
|
|
47
54
|
def format_proxy_address(proxy_host, proxy_port = 80, include_http = false)
|
@@ -7,13 +7,16 @@ namespace :http_utilities do
|
|
7
7
|
seeder.seed
|
8
8
|
end
|
9
9
|
|
10
|
-
task :check_proxies, [:protocol, :proxy_type, :
|
11
|
-
|
12
|
-
proxy_type = (args.proxy_type) ? args.proxy_type.to_sym : :public
|
13
|
-
processing_method = (args.processing_method) ? args.processing_method.to_sym : :synchronous
|
10
|
+
task :check_proxies, [:protocol, :proxy_type, :mode, :maximum_failed_attempts] => [:environment] do |task, args|
|
11
|
+
args.with_defaults(protocol: :http, proxy_type: :public, mode: :synchronous, maximum_failed_attempts: 10)
|
14
12
|
|
15
13
|
proxy_checker = HttpUtilities::Proxies::ProxyChecker.new
|
16
|
-
proxy_checker.check_and_update_proxies(
|
14
|
+
proxy_checker.check_and_update_proxies(
|
15
|
+
protocol: args.protocol.to_sym,
|
16
|
+
proxy_type: args.proxy_type.to_sym,
|
17
|
+
mode: args.mode.to_sym,
|
18
|
+
maximum_failed_attempts: args.maximum_failed_attempts.to_i
|
19
|
+
)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -78,14 +78,14 @@ describe Proxy do
|
|
78
78
|
|
79
79
|
[:http, :socks].each do |protocol|
|
80
80
|
it "should return #{protocol.to_s} proxies that should be checked" do
|
81
|
-
proxies = Proxy.should_be_checked(protocol)
|
81
|
+
proxies = Proxy.should_be_checked(protocol: protocol)
|
82
82
|
proxies.should_not be_nil
|
83
83
|
proxies.size.should == 3
|
84
84
|
end
|
85
85
|
|
86
86
|
[:public, :shared, :private].each do |proxy_type|
|
87
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)
|
88
|
+
proxies = Proxy.should_be_checked(protocol: protocol, proxy_type: proxy_type)
|
89
89
|
proxies.should_not be_nil
|
90
90
|
proxies.size.should == 1
|
91
91
|
end
|
@@ -94,14 +94,14 @@ describe Proxy do
|
|
94
94
|
|
95
95
|
[:http, :socks].each do |protocol|
|
96
96
|
it "should return a random #{protocol.to_s} proxy" do
|
97
|
-
random_proxy = Proxy.get_random_proxy(protocol)
|
97
|
+
random_proxy = Proxy.get_random_proxy(protocol: protocol)
|
98
98
|
random_proxy.should_not be_nil
|
99
99
|
random_proxy.protocol.should == protocol.to_s
|
100
100
|
end
|
101
101
|
|
102
102
|
[:public, :shared, :private].each do |proxy_type|
|
103
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)
|
104
|
+
random_proxy = Proxy.get_random_proxy(protocol: protocol, proxy_type: proxy_type)
|
105
105
|
random_proxy.should_not be_nil
|
106
106
|
random_proxy.protocol.should == protocol.to_s
|
107
107
|
random_proxy.proxy_type.should == proxy_type.to_s
|