radio5 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edd4e5e61372538e86183d4e6171031695c51379482a619eb29c0b94378906e9
4
- data.tar.gz: d25d7a72fdb56988bb4ae585a986671a395da01476fffa24f2ddb25d152fb85d
3
+ metadata.gz: 9cae0f327ab80b79f9d50626a2e59161ce8b0a2b7eb62400a2d36c0ef800b47d
4
+ data.tar.gz: ae74f46091926142fd98de0be436e50a21d6a7a9755ac6d1a533d7e4cee02ad3
5
5
  SHA512:
6
- metadata.gz: 94aeac4d8c3d39c751c22f5104c4f08fffa41c48f74db24f5ac984ee4f10d1f372f2bed4e361230a59f0791884adada50fa690bb8a42b523384a8ab6801f9622
7
- data.tar.gz: 21475735cdf9bfc455c8a8841cdead2ab67b2e6e25503daf04c7fdd71eb32ce62f9cb8161a2c3a2f214a1365149efc4ea0711f58488fc8cdb64f74ebb52aeb3b
6
+ metadata.gz: 551122e49cbabbdc97e8655f10157fd373a29022bab4242267eb6e1bd347045445a3438de9a20c0ff3837dcc9b970c027992c8d15feb3602a4338abe5f748269
7
+ data.tar.gz: 46e0212e7fc3fb608aff1b163ff600b97939a768518c6fabc688ea77b3571d974303a9285ad2f89094b83646b99f8633e69c1891fa3e65e6a6b65bd1d61379e4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ 0.1.2
2
+ ----------
3
+
4
+ - Fixed bug when custom HTTP config was ignored
5
+ - Fixed bug with broken HTTP retries
6
+
7
+ 0.1.1
8
+ ----------
9
+
10
+ - Added `max_retries` config option for `Client`
11
+ - All constants are now frozen
12
+
1
13
  0.1.0
2
14
  ----------
3
15
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Radio5
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/radio5.svg)](https://badge.fury.io/rb/radio5)
3
4
  [![Build](https://github.com/ocvit/radio5/workflows/Build/badge.svg)](https://github.com/ocvit/radio5/actions)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/ocvit/radio5/badge.svg?branch=main)](https://coveralls.io/github/ocvit/radio5?branch=main)
5
6
 
@@ -41,6 +42,7 @@ client = Radio5::Client.new(
41
42
  read_timeout: 30, # default: 10
42
43
  write_timeout: 30, # default: 10
43
44
  proxy_url: "http://user:pass@123.4.56.178:80", # default: nil
45
+ max_retries: 5, # for network errors, default: 3
44
46
  debug_output: $stdout # default: nil
45
47
  )
46
48
  ```
@@ -222,7 +224,7 @@ There is just a couple of features that require login and/or premium account:
222
224
 
223
225
  - history of "listened" tracks - track becomes "listened" when you got it via `#random_track` or `#island_track` (free)
224
226
  - `followed` flag for `#user` - indicates whether or not you follow this user (free)
225
- - `#user_liked_tracks` - list of tracks which user really rock'n'roll'ed to (free)
227
+ - `#user_liked_tracks` - list of tracks which user really vibed to (free)
226
228
  - ability to use multiple countries as a filter in `#random_track` (premium)
227
229
 
228
230
  Currently auth is in a WIP state.
@@ -240,11 +242,11 @@ Currently auth is in a WIP state.
240
242
  ## Development
241
243
 
242
244
  ```sh
243
- bin/setup // install deps
244
- bin/console // interactive prompt to play around
245
- rake spec // test!
246
- rake rubocop // lint!
247
- sudo rm -rf / // relax, just kidding ^^
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 ^^
248
250
  ```
249
251
 
250
252
  ## Contributing
data/lib/radio5/api.rb CHANGED
@@ -58,6 +58,7 @@ module Radio5
58
58
  read_timeout: client.read_timeout,
59
59
  write_timeout: client.write_timeout,
60
60
  proxy_url: client.proxy_url,
61
+ max_retries: client.max_retries,
61
62
  debug_output: client.debug_output
62
63
  )
63
64
  end
data/lib/radio5/client.rb CHANGED
@@ -9,12 +9,20 @@ module Radio5
9
9
  include Islands
10
10
  include Tracks
11
11
 
12
- attr_accessor :open_timeout, :read_timeout, :write_timeout, :proxy_url, :debug_output
12
+ attr_accessor :open_timeout, :read_timeout, :write_timeout, :proxy_url, :max_retries, :debug_output
13
13
 
14
- def initialize(open_timeout: nil, read_timeout: nil, write_timeout: nil, proxy_url: nil, debug_output: nil)
14
+ def initialize(
15
+ open_timeout: nil,
16
+ read_timeout: nil,
17
+ write_timeout: nil,
18
+ proxy_url: nil,
19
+ max_retries: nil,
20
+ debug_output: nil
21
+ )
15
22
  @open_timeout = open_timeout
16
23
  @read_timeout = read_timeout
17
24
  @write_timeout = write_timeout
25
+ @max_retries = max_retries
18
26
  @proxy_url = proxy_url
19
27
  @debug_output = debug_output
20
28
  end
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
- DEFAULT_DEBUG_OUTPUT = File.open(File::NULL, "w")
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,
@@ -23,45 +26,47 @@ module Radio5
23
26
  Net::ReadTimeout,
24
27
  Net::WriteTimeout,
25
28
  OpenSSL::SSL::SSLError
26
- ]
29
+ ].freeze
27
30
 
28
- attr_reader :max_retries
31
+ attr_reader :host, :port, :open_timeout, :read_timeout, :write_timeout, :proxy_url, :max_retries, :debug_output, :http_client
29
32
 
30
33
  # rubocop:disable Layout/ExtraSpacing
31
34
  def initialize(
32
35
  host:,
33
36
  port:,
34
- open_timeout: DEFAULT_OPEN_TIMEOUT,
35
- read_timeout: DEFAULT_READ_TIMEOUT,
36
- write_timeout: DEFAULT_WRITE_TIMEOUT,
37
+ open_timeout: nil,
38
+ read_timeout: nil,
39
+ write_timeout: nil,
37
40
  proxy_url: nil,
38
- max_retries: DEFAULT_MAX_RETRIES,
39
- debug_output: DEFAULT_DEBUG_OUTPUT
41
+ max_retries: nil,
42
+ debug_output: nil
40
43
  )
41
- # @host = host
42
- # @port = port
43
- # @open_timeout = open_timeout
44
- # @read_timeout = read_timeout
45
- # @write_timeout = write_timeout
46
- # @proxy_url = proxy_url
47
- # @debug_output = debug_output
48
-
49
- proxy_uri = parse_proxy_uri(proxy_url)
50
- @max_retries = max_retries
51
-
52
- @http = Net::HTTP.new(host, port, proxy_uri&.host, proxy_uri&.port, proxy_uri&.user, proxy_uri&.pass)
53
-
54
- @http.tap do |c|
55
- c.use_ssl = port == 443
56
- c.open_timeout = open_timeout
57
- c.read_timeout = read_timeout
58
- c.write_timeout = write_timeout
59
-
60
- 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)
61
62
  end
62
63
  end
63
64
  # rubocop:enable Layout/ExtraSpacing
64
65
 
66
+ def proxy_uri
67
+ @proxy_uri ||= parse_proxy_uri
68
+ end
69
+
65
70
  def request(http_method_class, path, query_params, body, headers)
66
71
  request = build_request(http_method_class, path, query_params, body, headers)
67
72
  make_request(request)
@@ -69,16 +74,15 @@ module Radio5
69
74
 
70
75
  private
71
76
 
72
- def parse_proxy_uri(proxy_url)
77
+ def parse_proxy_uri
73
78
  return if proxy_url.nil?
74
79
 
75
- proxy_uri = URI(proxy_url)
76
-
77
- unless @proxy_uri.is_a?(URI::HTTP)
78
- raise ArgumentError, "Invalid proxy URL: #{@proxy_uri}"
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}"
79
85
  end
80
-
81
- proxy_uri
82
86
  end
83
87
 
84
88
  def build_request(http_method_class, path, query_params, body, headers)
@@ -111,7 +115,7 @@ module Radio5
111
115
  end
112
116
 
113
117
  def make_request(request, retries: 0)
114
- @http.request(request)
118
+ http_client.request(request)
115
119
  rescue *RETRIABLE_ERRORS => error
116
120
  if retries < max_retries
117
121
  make_request(request, retries: retries + 1)
@@ -4,12 +4,12 @@ module Radio5
4
4
  module Regexps
5
5
  # rubocop:disable Layout/ExtraSpacing
6
6
 
7
- MONGO_ID = /^[a-f\d]{24}$/
8
- UUID_GENERIC = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
9
- UUID = /^#{UUID_GENERIC}$/
7
+ MONGO_ID = /^[a-f\d]{24}$/.freeze
8
+ UUID_GENERIC = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/.freeze
9
+ UUID = /^#{UUID_GENERIC}$/.freeze
10
10
 
11
- COUNTRY_ISO_CODE_GENERIC = /([A-Z]{3}|KN1)/
12
- COUNTRY_ISO_CODE = /^#{COUNTRY_ISO_CODE_GENERIC}$/
11
+ COUNTRY_ISO_CODE_GENERIC = /([A-Z]{3}|KN1)/.freeze
12
+ COUNTRY_ISO_CODE = /^#{COUNTRY_ISO_CODE_GENERIC}$/.freeze
13
13
 
14
14
  ASSET_URL = lambda do |sub_path, exts|
15
15
  asset_host = Regexp.escape(Utils::ASSET_HOST)
@@ -17,21 +17,21 @@ module Radio5
17
17
  exts = /(#{exts.join("|")})/
18
18
 
19
19
  /#{asset_host}#{sub_path}\/#{UUID_GENERIC}(_\d+)?\.#{exts}/
20
- end
20
+ end.freeze
21
21
 
22
- ISLAND_ICON_URL = ASSET_URL.call("/island/icon", ["png", "svg"])
23
- ISLAND_SPLASH_URL = ASSET_URL.call("/island/splash", ["png", "svg"])
24
- ISLAND_MARKER_URL = ASSET_URL.call("/island/marker", ["png", "svg"])
25
- TRACK_COVER_URL = ASSET_URL.call(/\/cover\/#{COUNTRY_ISO_CODE_GENERIC}\/\d{4}\/large/, ["jpg", "jpeg"])
22
+ ISLAND_ICON_URL = ASSET_URL.call("/island/icon", ["png", "svg"]).freeze
23
+ ISLAND_SPLASH_URL = ASSET_URL.call("/island/splash", ["png", "svg"]).freeze
24
+ ISLAND_MARKER_URL = ASSET_URL.call("/island/marker", ["png", "svg"]).freeze
25
+ TRACK_COVER_URL = ASSET_URL.call(/\/cover\/#{COUNTRY_ISO_CODE_GENERIC}\/\d{4}\/large/, ["jpg", "jpeg"]).freeze
26
26
 
27
27
  AUDIO_URL = lambda do |exts|
28
28
  exts = /(#{exts.join("|")})/
29
29
 
30
30
  /.+\/#{UUID_GENERIC}\.#{exts}\?token=[^&]{22}&expires=\d{10}$/
31
- end
31
+ end.freeze
32
32
 
33
- MPEG_URL = AUDIO_URL.call(["mp3", "m4a"])
34
- OGG_URL = AUDIO_URL.call(["ogg"])
33
+ MPEG_URL = AUDIO_URL.call(["mp3", "m4a"]).freeze
34
+ OGG_URL = AUDIO_URL.call(["ogg"]).freeze
35
35
 
36
36
  # rubocop:enable Layout/ExtraSpacing
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Radio5
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radio5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Horoshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Adapter for Radiooooo.com private API.
13
+ description: Adapter for Radiooooo private API.
14
14
  email:
15
15
  - electric.molfar@gmail.com
16
16
  executables: []
@@ -58,5 +58,5 @@ requirements: []
58
58
  rubygems_version: 3.4.10
59
59
  signing_key:
60
60
  specification_version: 4
61
- summary: Radiooooo.com unlocked!
61
+ summary: Adapter for Radiooooo private API
62
62
  test_files: []