radio5 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/CHANGELOG.md +6 -0
- data/README.md +5 -5
- data/lib/radio5/http.rb +41 -35
- data/lib/radio5/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: 9cae0f327ab80b79f9d50626a2e59161ce8b0a2b7eb62400a2d36c0ef800b47d
|
|
4
|
+
data.tar.gz: ae74f46091926142fd98de0be436e50a21d6a7a9755ac6d1a533d7e4cee02ad3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 551122e49cbabbdc97e8655f10157fd373a29022bab4242267eb6e1bd347045445a3438de9a20c0ff3837dcc9b970c027992c8d15feb3602a4338abe5f748269
|
|
7
|
+
data.tar.gz: 46e0212e7fc3fb608aff1b163ff600b97939a768518c6fabc688ea77b3571d974303a9285ad2f89094b83646b99f8633e69c1891fa3e65e6a6b65bd1d61379e4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -242,11 +242,11 @@ Currently auth is in a WIP state.
|
|
|
242
242
|
## Development
|
|
243
243
|
|
|
244
244
|
```sh
|
|
245
|
-
bin/setup
|
|
246
|
-
bin/console
|
|
247
|
-
rake spec
|
|
248
|
-
rake rubocop
|
|
249
|
-
sudo rm -rf /
|
|
245
|
+
bin/setup // install deps
|
|
246
|
+
bin/console // interactive prompt to play around
|
|
247
|
+
rake spec // test!
|
|
248
|
+
rake rubocop // lint!
|
|
249
|
+
sudo rm -rf / // just kidding ^^
|
|
250
250
|
```
|
|
251
251
|
|
|
252
252
|
## Contributing
|
data/lib/radio5/http.rb
CHANGED
|
@@ -9,12 +9,15 @@ module Radio5
|
|
|
9
9
|
DEFAULT_OPEN_TIMEOUT = 10 # seconds
|
|
10
10
|
DEFAULT_READ_TIMEOUT = 10 # seconds
|
|
11
11
|
DEFAULT_WRITE_TIMEOUT = 10 # seconds
|
|
12
|
-
|
|
12
|
+
DEFAULT_PROXY_URL = nil
|
|
13
13
|
DEFAULT_MAX_RETRIES = 3
|
|
14
|
+
DEFAULT_DEBUG_OUTPUT = nil
|
|
15
|
+
|
|
14
16
|
DEFAULT_HEADERS = {
|
|
15
17
|
"Content-Type" => "application/json; charset=utf-8",
|
|
16
18
|
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
17
19
|
}.freeze
|
|
20
|
+
|
|
18
21
|
RETRIABLE_ERRORS = [
|
|
19
22
|
Errno::ECONNREFUSED,
|
|
20
23
|
Errno::ECONNRESET,
|
|
@@ -25,41 +28,45 @@ module Radio5
|
|
|
25
28
|
OpenSSL::SSL::SSLError
|
|
26
29
|
].freeze
|
|
27
30
|
|
|
31
|
+
attr_reader :host, :port, :open_timeout, :read_timeout, :write_timeout, :proxy_url, :max_retries, :debug_output, :http_client
|
|
32
|
+
|
|
28
33
|
# rubocop:disable Layout/ExtraSpacing
|
|
29
34
|
def initialize(
|
|
30
35
|
host:,
|
|
31
36
|
port:,
|
|
32
|
-
open_timeout:
|
|
33
|
-
read_timeout:
|
|
34
|
-
write_timeout:
|
|
37
|
+
open_timeout: nil,
|
|
38
|
+
read_timeout: nil,
|
|
39
|
+
write_timeout: nil,
|
|
35
40
|
proxy_url: nil,
|
|
36
|
-
max_retries:
|
|
37
|
-
debug_output:
|
|
41
|
+
max_retries: nil,
|
|
42
|
+
debug_output: nil
|
|
38
43
|
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@
|
|
49
|
-
|
|
50
|
-
@
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
c.
|
|
54
|
-
c.
|
|
55
|
-
|
|
56
|
-
c.
|
|
57
|
-
|
|
58
|
-
c.set_debug_output(debug_output)
|
|
44
|
+
@host = host
|
|
45
|
+
@port = port
|
|
46
|
+
@open_timeout = open_timeout || DEFAULT_OPEN_TIMEOUT
|
|
47
|
+
@read_timeout = read_timeout || DEFAULT_READ_TIMEOUT
|
|
48
|
+
@write_timeout = write_timeout || DEFAULT_WRITE_TIMEOUT
|
|
49
|
+
@proxy_url = proxy_url || DEFAULT_PROXY_URL
|
|
50
|
+
@max_retries = max_retries || DEFAULT_MAX_RETRIES
|
|
51
|
+
@debug_output = debug_output || DEFAULT_DEBUG_OUTPUT
|
|
52
|
+
|
|
53
|
+
@http_client = Net::HTTP.new(@host, @port, proxy_uri&.host, proxy_uri&.port, proxy_uri&.user, proxy_uri&.password)
|
|
54
|
+
|
|
55
|
+
@http_client.tap do |c|
|
|
56
|
+
c.use_ssl = @port == 443
|
|
57
|
+
c.open_timeout = @open_timeout
|
|
58
|
+
c.read_timeout = @read_timeout
|
|
59
|
+
c.write_timeout = @write_timeout
|
|
60
|
+
|
|
61
|
+
c.set_debug_output(@debug_output)
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
64
|
# rubocop:enable Layout/ExtraSpacing
|
|
62
65
|
|
|
66
|
+
def proxy_uri
|
|
67
|
+
@proxy_uri ||= parse_proxy_uri
|
|
68
|
+
end
|
|
69
|
+
|
|
63
70
|
def request(http_method_class, path, query_params, body, headers)
|
|
64
71
|
request = build_request(http_method_class, path, query_params, body, headers)
|
|
65
72
|
make_request(request)
|
|
@@ -67,16 +74,15 @@ module Radio5
|
|
|
67
74
|
|
|
68
75
|
private
|
|
69
76
|
|
|
70
|
-
def parse_proxy_uri
|
|
77
|
+
def parse_proxy_uri
|
|
71
78
|
return if proxy_url.nil?
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
case uri = URI(proxy_url)
|
|
81
|
+
when URI::HTTP
|
|
82
|
+
uri
|
|
83
|
+
else
|
|
84
|
+
raise ArgumentError, "Invalid proxy URL: #{proxy_url.inspect}, parsed URI: #{uri.inspect}"
|
|
77
85
|
end
|
|
78
|
-
|
|
79
|
-
proxy_uri
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
def build_request(http_method_class, path, query_params, body, headers)
|
|
@@ -109,9 +115,9 @@ module Radio5
|
|
|
109
115
|
end
|
|
110
116
|
|
|
111
117
|
def make_request(request, retries: 0)
|
|
112
|
-
|
|
118
|
+
http_client.request(request)
|
|
113
119
|
rescue *RETRIABLE_ERRORS => error
|
|
114
|
-
if retries <
|
|
120
|
+
if retries < max_retries
|
|
115
121
|
make_request(request, retries: retries + 1)
|
|
116
122
|
else
|
|
117
123
|
raise error
|
data/lib/radio5/version.rb
CHANGED