proxy_rotator 0.1.1 → 0.1.2
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/Gemfile.lock +2 -2
- data/README.md +40 -0
- data/lib/proxy_rotator/rotator.rb +24 -7
- data/lib/proxy_rotator/version.rb +1 -1
- 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: 407f7b7ae00be49b2f73d019a696a208db168cf0
|
4
|
+
data.tar.gz: c23be0f0fd5937edbe6d4cf2f9c3c3d5fb72e8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f24dce1666c1fbb436c348a2082f5a0c5ae0c03d9ae50a65b99c336a65aa5626b71c3dcd487c1e6eda73b21b814fbf33878e42a29f8e3c8acbf1106289551f
|
7
|
+
data.tar.gz: c8ce3213d0e542c23854d5f6c06acf99ffe2a90f7acad80175acf5207c3b92b871a5d8c2859c5c30e2450a8497847bb8bf27eb10a3f58728411bc1c01889618e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
proxy_rotator (0.1.
|
4
|
+
proxy_rotator (0.1.2)
|
5
5
|
json
|
6
6
|
rest-client
|
7
7
|
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
unf (>= 0.0.5, < 1.0.0)
|
14
14
|
http-cookie (1.0.3)
|
15
15
|
domain_name (~> 0.5)
|
16
|
-
json (1.
|
16
|
+
json (2.1.0)
|
17
17
|
mime-types (3.1)
|
18
18
|
mime-types-data (~> 3.2015)
|
19
19
|
mime-types-data (3.2016.0521)
|
data/README.md
CHANGED
@@ -42,8 +42,48 @@ end
|
|
42
42
|
my_proxy = ProxyRotator.rotate_remote
|
43
43
|
```
|
44
44
|
|
45
|
+
Passing API parameters
|
46
|
+
```ruby
|
47
|
+
get: true/false Proxy supports GET requests
|
48
|
+
post true/false Proxy supports POST requests
|
49
|
+
cookies true/false Proxy supports cookies
|
50
|
+
referer true/false Proxy supports referer header
|
51
|
+
userAgent true/false Proxy supports user-agent header
|
52
|
+
port integer Return only proxies with specified port
|
53
|
+
city string Return only proxies with specified city
|
54
|
+
state string Return only proxies with specified state
|
55
|
+
country string Return only proxies with specified country
|
56
|
+
xml true/false Response will be in XML instead of jSON
|
57
|
+
```
|
58
|
+
|
59
|
+
Example
|
60
|
+
```ruby
|
61
|
+
config = {
|
62
|
+
:get => true,
|
63
|
+
:port => 8080,
|
64
|
+
:city => 'New York',
|
65
|
+
:state => 'NY',
|
66
|
+
:country => 'US'
|
67
|
+
}
|
68
|
+
|
69
|
+
my_proxy = ProxyRotator.rotate_remote(config)
|
70
|
+
```
|
71
|
+
|
72
|
+
Get proxy information
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
proxy_info = ProxyRotator.describe_remote(config)
|
76
|
+
```
|
77
|
+
|
45
78
|
### Load proxy list from a file
|
46
79
|
|
80
|
+
Example :
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
http://username:password@1.2.3.4:5678
|
84
|
+
http://1.2.3.4:5678
|
85
|
+
```
|
86
|
+
|
47
87
|
```ruby
|
48
88
|
ProxyRotator.load_file('/your/proxy-list.txt')
|
49
89
|
my_proxy = ProxyRotator.rotate
|
@@ -48,25 +48,42 @@ module ProxyRotator
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def self.
|
51
|
+
def self.base_url(config={})
|
52
52
|
url = ProxyRotator.configuration.base_url + "?apiKey=" + ProxyRotator.configuration.api_key
|
53
|
-
|
54
|
-
|
53
|
+
url = url + "&" + config.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&") unless config.empty?
|
54
|
+
|
55
|
+
return url
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.rotate_remote(config={})
|
59
|
+
url = self.base_url(config)
|
60
|
+
|
61
|
+
json = self.get_proxyrotator_proxy(url)
|
55
62
|
proxy = json["proxy"]
|
56
63
|
return "http://#{proxy}" unless proxy.nil?
|
57
64
|
|
58
65
|
return nil
|
59
66
|
end
|
60
67
|
|
61
|
-
def self.
|
68
|
+
def self.describe_remote(config={})
|
69
|
+
url = self.base_url(config)
|
70
|
+
self.get_proxyrotator_proxy(url)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.get_proxyrotator_proxy(url)
|
74
|
+
response = RestClient.get(url)
|
75
|
+
JSON.parse(response.body)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.rotate_first_then_remote(check_first=false, config={})
|
62
79
|
result = self.rotate(check_first)
|
63
|
-
result = self.rotate_remote unless !result.nil?
|
80
|
+
result = self.rotate_remote(config) unless !result.nil?
|
64
81
|
|
65
82
|
result
|
66
83
|
end
|
67
84
|
|
68
|
-
def self.remote_first_then_rotate(check_first=false)
|
69
|
-
result = self.rotate_remote
|
85
|
+
def self.remote_first_then_rotate(check_first=false, config={})
|
86
|
+
result = self.rotate_remote(config)
|
70
87
|
result = self.rotate(check_first) unless !result.nil?
|
71
88
|
|
72
89
|
result
|