http_utilities 1.2.4.1 → 1.2.5
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/http/proxy_support.rb +28 -36
- data/lib/http_utilities.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6efa30cb4d03d4a1c9e1bc4b5b435d35ff9370fb
|
4
|
+
data.tar.gz: 6be0c257aaaebf17933c32792e87d108ad6c8a0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582d778e3db97ac1355a9c1f381092edf088d80256513118e8d367268d8c989ff6bcb79344b2fcad4aea967a6c72fd20120177ac7db32a7606243e3c4eb9a0ee
|
7
|
+
data.tar.gz: 421890d806ae8d36de8e78c5cd774d7a350a53c539c7f10c7c7266ffa86527d9d811d6a877167fd2ca14343d9def042ac947f8606f48da3592fc06f8b9c8f6a6
|
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.2.
|
6
|
+
s.version = "1.2.5"
|
7
7
|
|
8
8
|
s.authors = ["Sebastian Johnsson"]
|
9
9
|
s.description = "Wrapper for Faraday with additional functionality"
|
@@ -5,38 +5,36 @@ module HttpUtilities
|
|
5
5
|
def set_proxy_options(options = {})
|
6
6
|
use_proxy = options.fetch(:use_proxy, false)
|
7
7
|
specific_proxy = options.fetch(:proxy, nil)
|
8
|
+
proxy_host = options.fetch(:proxy_host, nil)
|
9
|
+
proxy_port = options.fetch(:proxy_port, nil)
|
8
10
|
proxy_username = options.fetch(:proxy_username, nil)
|
9
11
|
proxy_password = options.fetch(:proxy_password, nil)
|
10
12
|
proxy_credentials = options.fetch(:proxy_credentials, nil)
|
11
|
-
reset_proxy = options.fetch(:reset_proxy, true)
|
12
|
-
|
13
|
-
if reset_proxy
|
14
|
-
self.proxy = {}
|
15
|
-
self.proxy[:host] = options.fetch(:proxy_host, nil)
|
16
|
-
self.proxy[:port] = options.fetch(:proxy_port, nil)
|
17
|
-
self.proxy[:protocol] = options.fetch(:proxy_protocol, :http)
|
18
|
-
self.proxy[:type] = options.fetch(:proxy_type, :all)
|
19
|
-
end
|
20
13
|
|
21
|
-
if
|
22
|
-
if
|
14
|
+
if use_proxy || specific_proxy
|
15
|
+
if specific_proxy && specific_proxy.is_a?(String)
|
23
16
|
specific_proxy = specific_proxy.gsub(/^http(s)?:\/\//i, "")
|
24
17
|
parts = specific_proxy.split(":")
|
25
18
|
|
26
|
-
if
|
19
|
+
if parts.size.eql?(2)
|
27
20
|
self.proxy[:host] = parts.first
|
28
21
|
self.proxy[:port] = parts.second.to_i
|
29
22
|
end
|
30
23
|
|
31
|
-
elsif
|
32
|
-
self.proxy
|
24
|
+
elsif proxy_host && proxy_port
|
25
|
+
self.proxy[:host] = proxy_host
|
26
|
+
self.proxy[:port] = proxy_port
|
33
27
|
|
34
|
-
elsif
|
35
|
-
|
28
|
+
elsif proxy_model_defined?
|
29
|
+
if specific_proxy && specific_proxy.is_a?(::Proxy)
|
30
|
+
proxy_object = specific_proxy
|
31
|
+
else
|
32
|
+
proxy_object = ::Proxy.get_random_proxy(protocol: self.proxy[:protocol], proxy_type: self.proxy[:type])
|
33
|
+
end
|
36
34
|
|
37
35
|
#log(:info, "[HttpUtilities::Http::ProxySupport] - Randomized Proxy object: #{proxy_object.inspect}")
|
38
36
|
|
39
|
-
if
|
37
|
+
if proxy_object
|
40
38
|
self.proxy[:host] = proxy_object.host
|
41
39
|
self.proxy[:port] = proxy_object.port
|
42
40
|
proxy_username = proxy_object.username.present? ? proxy_object.username : nil
|
@@ -49,23 +47,21 @@ module HttpUtilities
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def set_proxy_credentials(proxy_username, proxy_password, proxy_credentials)
|
52
|
-
if
|
53
|
-
|
54
|
-
|
55
|
-
self.proxy[:password] = proxy_password
|
50
|
+
if proxy_username && proxy_password
|
51
|
+
self.proxy[:username] = proxy_username
|
52
|
+
self.proxy[:password] = proxy_password
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
elsif proxy_credentials
|
55
|
+
if proxy_credentials.is_a?(Hash)
|
56
|
+
self.proxy[:username] = proxy_credentials[:username]
|
57
|
+
self.proxy[:password] = proxy_credentials[:password]
|
61
58
|
|
62
|
-
|
63
|
-
|
59
|
+
elsif (proxy_credentials.is_a?(String))
|
60
|
+
parts = proxy_credentials.split(":")
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
62
|
+
if parts && parts.any? && parts.size == 2
|
63
|
+
self.proxy[:username] = parts.first
|
64
|
+
self.proxy[:password] = parts.second
|
69
65
|
end
|
70
66
|
end
|
71
67
|
end
|
@@ -73,15 +69,11 @@ module HttpUtilities
|
|
73
69
|
|
74
70
|
def proxy_model_defined?
|
75
71
|
defined = Module.const_get("Proxy").is_a?(Class) rescue false
|
76
|
-
defined = (defined && Proxy.respond_to?(:get_random_proxy))
|
72
|
+
defined = (defined && ::Proxy.respond_to?(:get_random_proxy))
|
77
73
|
|
78
74
|
return defined
|
79
75
|
end
|
80
76
|
|
81
|
-
def using_proxy?
|
82
|
-
return (self.proxy[:host] && self.proxy[:port] && self.proxy[:port] > 0)
|
83
|
-
end
|
84
|
-
|
85
77
|
def generate_proxy_options
|
86
78
|
proxy_options = {}
|
87
79
|
|
data/lib/http_utilities.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Johnsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|