cubesmart 0.5.0 → 0.7.0
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/README.md +1 -0
- data/lib/cubesmart/config.rb +39 -0
- data/lib/cubesmart/crawler.rb +5 -3
- data/lib/cubesmart/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf820da6f1fc7571b5558fe7bc2fea1471f180485cfa1d6433aa5163ae0f613
|
4
|
+
data.tar.gz: 41b35c9acf309ee0439794ba50322c4e7bca51efcf1827dd6cc6bb4a68fc235d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69bc03009bd047ed9e46e5b9747e214b7955b91bbcde1cb208b6a52c035769888376143abcd333c478bdb1b1a80594e3eabb1b3bcabd317f06cd037c24886127
|
7
|
+
data.tar.gz: 73b9a9ffa0e8aabf140a4be5f1ffcdbe8b7dae833ee2f39ed835cdb2b72239813c83232607c3db376d05ddd88df7b7ea2ad795ce18ac8b50f43054e656d412d6
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ require 'cubesmart'
|
|
20
20
|
CubeSmart.configure do |config|
|
21
21
|
config.user_agent = '../..' # ENV['CUBESMART_USER_AGENT']
|
22
22
|
config.timeout = 30 # ENV['CUBESMART_TIMEOUT']
|
23
|
+
config.proxy_url = 'http://user:pass@superproxy.zenrows.com:1337' # ENV['CUBESMART_PROXY_URL']
|
23
24
|
end
|
24
25
|
```
|
25
26
|
|
data/lib/cubesmart/config.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
module CubeSmart
|
4
4
|
# The core configuration.
|
5
5
|
class Config
|
6
|
+
# @attribute [rw] accept_language
|
7
|
+
# @return [String]
|
8
|
+
attr_accessor :accept_language
|
9
|
+
|
6
10
|
# @attribute [rw] user_agent
|
7
11
|
# @return [String]
|
8
12
|
attr_accessor :user_agent
|
@@ -11,9 +15,44 @@ module CubeSmart
|
|
11
15
|
# @return [Integer]
|
12
16
|
attr_accessor :timeout
|
13
17
|
|
18
|
+
# @attribute [rw] proxy_url
|
19
|
+
# @return [String]
|
20
|
+
attr_accessor :proxy_url
|
21
|
+
|
14
22
|
def initialize
|
23
|
+
@accept_language = ENV.fetch('CUBESMART_ACCEPT_LANGUAGE', 'en-US,en;q=0.9')
|
15
24
|
@user_agent = ENV.fetch('CUBESMART_USER_AGENT', "cubesmart.rb/#{VERSION}")
|
16
25
|
@timeout = Integer(ENV.fetch('CUBESMART_TIMEOUT', 60))
|
26
|
+
@proxy_url = ENV.fetch('CUBESMART_PROXY_URL', nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean]
|
30
|
+
def headers?
|
31
|
+
!@user_agent.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Boolean]
|
35
|
+
def timeout?
|
36
|
+
!@timeout.zero?
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Boolean]
|
40
|
+
def proxy?
|
41
|
+
!@proxy_url.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Hash<String, String>] e.g { 'User-Agent' => 'cubesmart.rb/1.0.0' }
|
45
|
+
def headers
|
46
|
+
{
|
47
|
+
'Accept-Language' => @accept_language,
|
48
|
+
'User-Agent' => @user_agent
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Array] e.g. ['proxy.example.com', 8080, 'user', 'pass']
|
53
|
+
def via
|
54
|
+
proxy_uri = URI.parse(@proxy_url)
|
55
|
+
[proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password]
|
17
56
|
end
|
18
57
|
end
|
19
58
|
end
|
data/lib/cubesmart/crawler.rb
CHANGED
@@ -24,9 +24,11 @@ module CubeSmart
|
|
24
24
|
@connection ||= begin
|
25
25
|
config = CubeSmart.config
|
26
26
|
|
27
|
-
connection = HTTP.persistent(HOST)
|
28
|
-
connection = connection.headers(
|
29
|
-
connection = connection.timeout(config.timeout) if config.timeout
|
27
|
+
connection = HTTP.use(:auto_deflate).use(:auto_inflate).persistent(HOST)
|
28
|
+
connection = connection.headers(config.headers) if config.headers?
|
29
|
+
connection = connection.timeout(config.timeout) if config.timeout?
|
30
|
+
connection = connection.via(*config.via) if config.proxy?
|
31
|
+
|
30
32
|
connection
|
31
33
|
end
|
32
34
|
end
|
data/lib/cubesmart/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cubesmart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|