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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bd1368da1b34144f5d7878a5937a56cea5cc1664cc485f4f90a66c10d2d1e95
4
- data.tar.gz: b48f92261b395ff5d367c1171e200b705d515f0923c9ed4218db8e9384462d24
3
+ metadata.gz: fd0a6e260e23509c1d4eb0c346e781921fa925a191bf7bb3dad43a42454f2672
4
+ data.tar.gz: 77296c9f3fbd121ef0acb8d60f1651b1f9c0c346981eeeea8d4aab00728f216f
5
5
  SHA512:
6
- metadata.gz: 5ffbd1994514e253d65a1524ca3f0fa145a0d57e614884668994b3df7a3fa1af0a191583967fa3f2b7f2ec58fbfa11423b2d0077145aa6669fb6477434571441
7
- data.tar.gz: 722b26f35ecf28a9bfc457adba21fe8528e375775ffc309612599f676f8a89d3cb06ee0efda900c7f0e29cf1e5563ad5a8ada07db945bb523fd02f0b6fe8f8a2
6
+ metadata.gz: 2369db3eef5589a354124afd144322fc8adfb85b51fc61c6072575911e5abdf5d533f1ba690c9c7c99bf7835faa9c1319f9abd503997c4d8a24de57881189f63
7
+ data.tar.gz: ba4dfcc0c92549713a5f4a3d2ca3f44f7b2c5ed2bce8ab1778e1c9f29f0b6ae9d61d934402310ec7489e2e658a2e1dcfe958763cb7def43e0f3ec627c261c7c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_proxy (1.0.0)
4
+ active_proxy (1.0.1)
5
5
  nokogiri (>= 1.6.8)
6
6
  proxy_fetcher (>= 0.9.0)
7
7
  retries (>= 0.0.5)
data/README.md CHANGED
@@ -1,28 +1,130 @@
1
1
  # ActiveProxy
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_proxy`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- And then execute:
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
- $ bundle
59
+ #### Typhoeus
18
60
 
19
- Or install it yourself as:
20
61
 
21
- $ gem install active_proxy
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
- TODO: Write usage instructions here
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
 
@@ -41,8 +41,8 @@ module ActiveProxy
41
41
  current_proxy
42
42
  end
43
43
 
44
- def user_agent
45
- UserAgentRandomizer::UserAgent.fetch.string
44
+ def user_agent(options = {})
45
+ UserAgentRandomizer::UserAgent.fetch(options).string
46
46
  end
47
47
 
48
48
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveProxy
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sebi