active_proxy 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +113 -11
- data/lib/active_proxy/fetcher.rb +2 -2
- data/lib/active_proxy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0a6e260e23509c1d4eb0c346e781921fa925a191bf7bb3dad43a42454f2672
|
4
|
+
data.tar.gz: 77296c9f3fbd121ef0acb8d60f1651b1f9c0c346981eeeea8d4aab00728f216f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2369db3eef5589a354124afd144322fc8adfb85b51fc61c6072575911e5abdf5d533f1ba690c9c7c99bf7835faa9c1319f9abd503997c4d8a24de57881189f63
|
7
|
+
data.tar.gz: ba4dfcc0c92549713a5f4a3d2ca3f44f7b2c5ed2bce8ab1778e1c9f29f0b6ae9d61d934402310ec7489e2e658a2e1dcfe958763cb7def43e0f3ec627c261c7c1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,130 @@
|
|
1
1
|
# ActiveProxy
|
2
2
|
|
3
|
-
|
3
|
+
![Alt text](https://travis-ci.com/sebyx07/active_proxy.svg?branch=master)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/active_proxy.svg)](https://badge.fury.io/rb/active_proxy)
|
4
5
|
|
5
|
-
|
6
|
+
### Easy to use ruby proxy fetcher with support for multiple http clients. Has auto retry🚀, fetch 🤖user agent
|
6
7
|
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
10
|
gem 'active_proxy'
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
### Examples
|
14
|
+
|
15
|
+
#### HTTParty
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)
|
19
|
+
|
20
|
+
ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
|
21
|
+
|
22
|
+
options = proxy.format_proxy_httparty
|
23
|
+
options[:timeout] = 2
|
24
|
+
options[:headers] = {
|
25
|
+
"Accept" => "application/json",
|
26
|
+
"User-Agent" => proxy.user_agent
|
27
|
+
}
|
28
|
+
|
29
|
+
result = HTTParty.get("https://api.ipify.org?format=json", options).body
|
30
|
+
p JSON.parse(result)
|
31
|
+
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Http.rb
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)
|
39
|
+
|
40
|
+
ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
|
41
|
+
|
42
|
+
proxy_arguments = proxy.format_proxy_http
|
43
|
+
headers = {
|
44
|
+
"Accept" => "application/json",
|
45
|
+
"User-Agent" => proxy.user_agent
|
46
|
+
}
|
47
|
+
|
48
|
+
result = HTTP.via(*proxy_arguments)
|
49
|
+
.headers(headers)
|
50
|
+
.timeout(write: 2, connect: 1, read: 1)
|
51
|
+
.get("https://api.ipify.org?format=json")
|
52
|
+
.body
|
53
|
+
|
54
|
+
p JSON.parse(result)
|
55
|
+
|
56
|
+
end
|
57
|
+
```
|
16
58
|
|
17
|
-
|
59
|
+
#### Typhoeus
|
18
60
|
|
19
|
-
Or install it yourself as:
|
20
61
|
|
21
|
-
|
62
|
+
```ruby
|
63
|
+
cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)
|
64
|
+
|
65
|
+
ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
|
66
|
+
|
67
|
+
options = proxy.format_proxy_typhoeus
|
68
|
+
options[:timeout] = 2
|
69
|
+
options[:followlocation] = true
|
70
|
+
options[:headers] = {
|
71
|
+
"Accept" => "application/json",
|
72
|
+
"User-Agent" => proxy.user_agent
|
73
|
+
}
|
74
|
+
options[:method] = :get
|
75
|
+
|
76
|
+
result = Typhoeus::Request.new("https://api.ipify.org?format=json", options).run.body
|
77
|
+
|
78
|
+
p JSON.parse(result)
|
79
|
+
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
#### custom client
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)
|
88
|
+
|
89
|
+
ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
|
90
|
+
|
91
|
+
options = proxy.current_proxy
|
92
|
+
# then you access the options[:address] and options[:port]
|
93
|
+
end
|
94
|
+
```
|
22
95
|
|
23
|
-
## Usage
|
24
96
|
|
25
|
-
|
97
|
+
### Custom options
|
98
|
+
|
99
|
+
#### User agent
|
100
|
+
|
101
|
+
When calling `.user_agent` you can pass params, check https://github.com/asconix/user-agent-randomizer
|
102
|
+
|
103
|
+
#### Limit retries
|
104
|
+
|
105
|
+
Current limit is 10.
|
106
|
+
|
107
|
+
Because proxies are unreliable, set a higher number
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
ActiveProxy.call("ipify", cache, {max_retries: 100}) do
|
111
|
+
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
#### Proxy list
|
117
|
+
|
118
|
+
Current configuration is `{ filters: { maxtime: "200" } }`
|
119
|
+
|
120
|
+
You can check what configuration you can pass https://github.com/nbulaj/proxy_fetcher
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
ActiveProxy.call("ipify", cache, {proxy_manager_options: { filters: { maxtime: "100" } }}) do
|
124
|
+
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
26
128
|
|
27
129
|
## Development
|
28
130
|
|
data/lib/active_proxy/fetcher.rb
CHANGED
data/lib/active_proxy/version.rb
CHANGED