plex_ruby_sdk 0.7.7 → 0.8.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/plex_ruby_sdk/activities.rb +115 -12
  3. data/lib/plex_ruby_sdk/authentication.rb +233 -29
  4. data/lib/plex_ruby_sdk/butler.rb +283 -30
  5. data/lib/plex_ruby_sdk/hubs.rb +174 -21
  6. data/lib/plex_ruby_sdk/library.rb +1307 -110
  7. data/lib/plex_ruby_sdk/log.rb +179 -24
  8. data/lib/plex_ruby_sdk/media.rb +288 -35
  9. data/lib/plex_ruby_sdk/models/operations/get_media_arts_mediacontainer.rb +36 -0
  10. data/lib/plex_ruby_sdk/models/operations/get_media_arts_metadata.rb +36 -0
  11. data/lib/plex_ruby_sdk/models/operations/get_media_arts_request.rb +24 -0
  12. data/lib/plex_ruby_sdk/models/operations/get_media_arts_response.rb +33 -0
  13. data/lib/plex_ruby_sdk/models/operations/get_media_arts_responsebody.rb +24 -0
  14. data/lib/plex_ruby_sdk/models/operations/get_media_posters_mediacontainer.rb +36 -0
  15. data/lib/plex_ruby_sdk/models/operations/get_media_posters_metadata.rb +36 -0
  16. data/lib/plex_ruby_sdk/models/operations/get_media_posters_request.rb +24 -0
  17. data/lib/plex_ruby_sdk/models/operations/get_media_posters_response.rb +33 -0
  18. data/lib/plex_ruby_sdk/models/operations/get_media_posters_responsebody.rb +24 -0
  19. data/lib/plex_ruby_sdk/models/operations/post_media_arts_request.rb +30 -0
  20. data/lib/plex_ruby_sdk/models/operations/post_media_arts_response.rb +30 -0
  21. data/lib/plex_ruby_sdk/models/operations/post_media_poster_request.rb +30 -0
  22. data/lib/plex_ruby_sdk/models/operations/post_media_poster_response.rb +30 -0
  23. data/lib/plex_ruby_sdk/models/operations.rb +14 -0
  24. data/lib/plex_ruby_sdk/playlists.rb +513 -60
  25. data/lib/plex_ruby_sdk/plex.rb +388 -38
  26. data/lib/plex_ruby_sdk/plex_api.rb +29 -10
  27. data/lib/plex_ruby_sdk/sdk_hooks/hooks.rb +103 -0
  28. data/lib/plex_ruby_sdk/sdk_hooks/registration.rb +35 -0
  29. data/lib/plex_ruby_sdk/sdk_hooks/types.rb +152 -0
  30. data/lib/plex_ruby_sdk/sdkconfiguration.rb +26 -7
  31. data/lib/plex_ruby_sdk/search.rb +174 -21
  32. data/lib/plex_ruby_sdk/server.rb +505 -53
  33. data/lib/plex_ruby_sdk/sessions.rb +228 -25
  34. data/lib/plex_ruby_sdk/statistics.rb +174 -21
  35. data/lib/plex_ruby_sdk/updater.rb +173 -20
  36. data/lib/plex_ruby_sdk/users.rb +56 -4
  37. data/lib/plex_ruby_sdk/utils/retries.rb +95 -0
  38. data/lib/plex_ruby_sdk/utils/utils.rb +10 -0
  39. data/lib/plex_ruby_sdk/video.rb +117 -14
  40. data/lib/plex_ruby_sdk/watchlist.rb +60 -7
  41. metadata +50 -4
@@ -5,7 +5,10 @@
5
5
 
6
6
  require 'faraday'
7
7
  require 'faraday/multipart'
8
+ require 'faraday/retry'
8
9
  require 'sorbet-runtime'
10
+ require_relative 'sdk_hooks/hooks'
11
+ require_relative 'utils/retries'
9
12
 
10
13
  module PlexRubySDK
11
14
  extend T::Sig
@@ -21,8 +24,8 @@ module PlexRubySDK
21
24
  end
22
25
 
23
26
 
24
- sig { returns(::PlexRubySDK::Operations::GetUpdateStatusResponse) }
25
- def get_update_status
27
+ sig { params(timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetUpdateStatusResponse) }
28
+ def get_update_status(timeout_ms = nil)
26
29
  # get_update_status - Querying status of updates
27
30
  # Querying status of updates
28
31
  url, params = @sdk_configuration.get_server_details
@@ -32,10 +35,60 @@ module PlexRubySDK
32
35
  headers['Accept'] = 'application/json'
33
36
  headers['user-agent'] = @sdk_configuration.user_agent
34
37
 
35
- r = @sdk_configuration.client.get(url) do |req|
36
- req.headers = headers
37
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
38
- Utils.configure_request_security(req, security) if !security.nil?
38
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
39
+
40
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
41
+ timeout ||= @sdk_configuration.timeout
42
+
43
+ connection = @sdk_configuration.client
44
+
45
+ hook_ctx = SDKHooks::HookContext.new(
46
+ base_url: base_url,
47
+ oauth2_scopes: nil,
48
+ operation_id: 'getUpdateStatus',
49
+ security_source: @sdk_configuration.security_source
50
+ )
51
+
52
+ error = T.let(nil, T.nilable(StandardError))
53
+ r = T.let(nil, T.nilable(Faraday::Response))
54
+
55
+ begin
56
+ r = connection.get(url) do |req|
57
+ req.headers.merge!(headers)
58
+ req.options.timeout = timeout unless timeout.nil?
59
+ Utils.configure_request_security(req, security)
60
+
61
+ @sdk_configuration.hooks.before_request(
62
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
63
+ hook_ctx: hook_ctx
64
+ ),
65
+ request: req
66
+ )
67
+ end
68
+ rescue StandardError => e
69
+ error = e
70
+ ensure
71
+ if r.nil? || Utils.error_status?(r.status)
72
+ r = @sdk_configuration.hooks.after_error(
73
+ error: error,
74
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
75
+ hook_ctx: hook_ctx
76
+ ),
77
+ response: r
78
+ )
79
+ else
80
+ r = @sdk_configuration.hooks.after_success(
81
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
82
+ hook_ctx: hook_ctx
83
+ ),
84
+ response: r
85
+ )
86
+ end
87
+
88
+ if r.nil?
89
+ raise error if !error.nil?
90
+ raise 'no response'
91
+ end
39
92
  end
40
93
 
41
94
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -64,8 +117,8 @@ module PlexRubySDK
64
117
  end
65
118
 
66
119
 
67
- sig { params(download: T.nilable(::PlexRubySDK::Operations::Download)).returns(::PlexRubySDK::Operations::CheckForUpdatesResponse) }
68
- def check_for_updates(download = nil)
120
+ sig { params(download: T.nilable(::PlexRubySDK::Operations::Download), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::CheckForUpdatesResponse) }
121
+ def check_for_updates(download = nil, timeout_ms = nil)
69
122
  # check_for_updates - Checking for updates
70
123
  # Checking for updates
71
124
  request = ::PlexRubySDK::Operations::CheckForUpdatesRequest.new(
@@ -80,11 +133,61 @@ module PlexRubySDK
80
133
  headers['Accept'] = 'application/json'
81
134
  headers['user-agent'] = @sdk_configuration.user_agent
82
135
 
83
- r = @sdk_configuration.client.put(url) do |req|
84
- req.headers = headers
85
- req.params = query_params
86
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
87
- Utils.configure_request_security(req, security) if !security.nil?
136
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
137
+
138
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
139
+ timeout ||= @sdk_configuration.timeout
140
+
141
+ connection = @sdk_configuration.client
142
+
143
+ hook_ctx = SDKHooks::HookContext.new(
144
+ base_url: base_url,
145
+ oauth2_scopes: nil,
146
+ operation_id: 'checkForUpdates',
147
+ security_source: @sdk_configuration.security_source
148
+ )
149
+
150
+ error = T.let(nil, T.nilable(StandardError))
151
+ r = T.let(nil, T.nilable(Faraday::Response))
152
+
153
+ begin
154
+ r = connection.put(url) do |req|
155
+ req.headers.merge!(headers)
156
+ req.options.timeout = timeout unless timeout.nil?
157
+ req.params = query_params
158
+ Utils.configure_request_security(req, security)
159
+
160
+ @sdk_configuration.hooks.before_request(
161
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
162
+ hook_ctx: hook_ctx
163
+ ),
164
+ request: req
165
+ )
166
+ end
167
+ rescue StandardError => e
168
+ error = e
169
+ ensure
170
+ if r.nil? || Utils.error_status?(r.status)
171
+ r = @sdk_configuration.hooks.after_error(
172
+ error: error,
173
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
174
+ hook_ctx: hook_ctx
175
+ ),
176
+ response: r
177
+ )
178
+ else
179
+ r = @sdk_configuration.hooks.after_success(
180
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
181
+ hook_ctx: hook_ctx
182
+ ),
183
+ response: r
184
+ )
185
+ end
186
+
187
+ if r.nil?
188
+ raise error if !error.nil?
189
+ raise 'no response'
190
+ end
88
191
  end
89
192
 
90
193
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -109,8 +212,8 @@ module PlexRubySDK
109
212
  end
110
213
 
111
214
 
112
- sig { params(tonight: T.nilable(::PlexRubySDK::Operations::Tonight), skip: T.nilable(::PlexRubySDK::Operations::Skip)).returns(::PlexRubySDK::Operations::ApplyUpdatesResponse) }
113
- def apply_updates(tonight = nil, skip = nil)
215
+ sig { params(tonight: T.nilable(::PlexRubySDK::Operations::Tonight), skip: T.nilable(::PlexRubySDK::Operations::Skip), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::ApplyUpdatesResponse) }
216
+ def apply_updates(tonight = nil, skip = nil, timeout_ms = nil)
114
217
  # apply_updates - Apply Updates
115
218
  # Note that these two parameters are effectively mutually exclusive. The `tonight` parameter takes precedence and `skip` will be ignored if `tonight` is also passed
116
219
  #
@@ -127,11 +230,61 @@ module PlexRubySDK
127
230
  headers['Accept'] = 'application/json'
128
231
  headers['user-agent'] = @sdk_configuration.user_agent
129
232
 
130
- r = @sdk_configuration.client.put(url) do |req|
131
- req.headers = headers
132
- req.params = query_params
133
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
134
- Utils.configure_request_security(req, security) if !security.nil?
233
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
234
+
235
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
236
+ timeout ||= @sdk_configuration.timeout
237
+
238
+ connection = @sdk_configuration.client
239
+
240
+ hook_ctx = SDKHooks::HookContext.new(
241
+ base_url: base_url,
242
+ oauth2_scopes: nil,
243
+ operation_id: 'applyUpdates',
244
+ security_source: @sdk_configuration.security_source
245
+ )
246
+
247
+ error = T.let(nil, T.nilable(StandardError))
248
+ r = T.let(nil, T.nilable(Faraday::Response))
249
+
250
+ begin
251
+ r = connection.put(url) do |req|
252
+ req.headers.merge!(headers)
253
+ req.options.timeout = timeout unless timeout.nil?
254
+ req.params = query_params
255
+ Utils.configure_request_security(req, security)
256
+
257
+ @sdk_configuration.hooks.before_request(
258
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
259
+ hook_ctx: hook_ctx
260
+ ),
261
+ request: req
262
+ )
263
+ end
264
+ rescue StandardError => e
265
+ error = e
266
+ ensure
267
+ if r.nil? || Utils.error_status?(r.status)
268
+ r = @sdk_configuration.hooks.after_error(
269
+ error: error,
270
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
271
+ hook_ctx: hook_ctx
272
+ ),
273
+ response: r
274
+ )
275
+ else
276
+ r = @sdk_configuration.hooks.after_success(
277
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
278
+ hook_ctx: hook_ctx
279
+ ),
280
+ response: r
281
+ )
282
+ end
283
+
284
+ if r.nil?
285
+ raise error if !error.nil?
286
+ raise 'no response'
287
+ end
135
288
  end
136
289
 
137
290
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -5,7 +5,10 @@
5
5
 
6
6
  require 'faraday'
7
7
  require 'faraday/multipart'
8
+ require 'faraday/retry'
8
9
  require 'sorbet-runtime'
10
+ require_relative 'sdk_hooks/hooks'
11
+ require_relative 'utils/retries'
9
12
 
10
13
  module PlexRubySDK
11
14
  extend T::Sig
@@ -24,8 +27,8 @@ module PlexRubySDK
24
27
  end
25
28
 
26
29
 
27
- sig { params(request: T.nilable(::PlexRubySDK::Operations::GetUsersRequest), server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetUsersResponse) }
28
- def get_users(request, server_url = nil)
30
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::GetUsersRequest), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetUsersResponse) }
31
+ def get_users(request, server_url = nil, timeout_ms = nil)
29
32
  # get_users - Get list of all connected users
30
33
  # Get list of all users that are friends and have library access with the provided Plex authentication token
31
34
  base_url = Utils.template_url(GET_USERS_SERVERS[0], {
@@ -36,8 +39,57 @@ module PlexRubySDK
36
39
  headers['Accept'] = 'application/json;q=1, application/xml;q=0'
37
40
  headers['user-agent'] = @sdk_configuration.user_agent
38
41
 
39
- r = @sdk_configuration.client.get(url) do |req|
40
- req.headers = headers
42
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
43
+ timeout ||= @sdk_configuration.timeout
44
+
45
+ connection = @sdk_configuration.client
46
+
47
+ hook_ctx = SDKHooks::HookContext.new(
48
+ base_url: base_url,
49
+ oauth2_scopes: nil,
50
+ operation_id: 'get-users',
51
+ security_source: nil
52
+ )
53
+
54
+ error = T.let(nil, T.nilable(StandardError))
55
+ r = T.let(nil, T.nilable(Faraday::Response))
56
+
57
+ begin
58
+ r = connection.get(url) do |req|
59
+ req.headers.merge!(headers)
60
+ req.options.timeout = timeout unless timeout.nil?
61
+
62
+ @sdk_configuration.hooks.before_request(
63
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
64
+ hook_ctx: hook_ctx
65
+ ),
66
+ request: req
67
+ )
68
+ end
69
+ rescue StandardError => e
70
+ error = e
71
+ ensure
72
+ if r.nil? || Utils.error_status?(r.status)
73
+ r = @sdk_configuration.hooks.after_error(
74
+ error: error,
75
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
76
+ hook_ctx: hook_ctx
77
+ ),
78
+ response: r
79
+ )
80
+ else
81
+ r = @sdk_configuration.hooks.after_success(
82
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
83
+ hook_ctx: hook_ctx
84
+ ),
85
+ response: r
86
+ )
87
+ end
88
+
89
+ if r.nil?
90
+ raise error if !error.nil?
91
+ raise 'no response'
92
+ end
41
93
  end
42
94
 
43
95
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -0,0 +1,95 @@
1
+ # Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
2
+
3
+ # typed: true
4
+ # frozen_string_literal: true
5
+
6
+ require 'faraday/retry'
7
+ require 'sorbet-runtime'
8
+
9
+ module PlexRubySDK
10
+ module Utils
11
+ class BackoffStrategy
12
+ extend T::Sig
13
+
14
+ sig { returns(T.nilable(::Float)) }
15
+ attr_accessor :exponent
16
+
17
+ sig { returns(T.nilable(::Integer)) }
18
+ attr_accessor :initial_interval
19
+
20
+ sig { returns(T.nilable(::Integer)) }
21
+ attr_accessor :max_elapsed_time
22
+
23
+ sig { returns(T.nilable(::Integer)) }
24
+ attr_accessor :max_interval
25
+
26
+ sig do
27
+ params(
28
+ exponent: T.nilable(::Float),
29
+ initial_interval: T.nilable(::Integer),
30
+ max_elapsed_time: T.nilable(::Integer),
31
+ max_interval: T.nilable(::Integer)
32
+ ).void
33
+ end
34
+ def initialize(exponent: nil, initial_interval: nil, max_elapsed_time: nil, max_interval: nil)
35
+ @exponent = T.let(exponent, T.nilable(::Float))
36
+ @initial_interval = T.let(initial_interval, T.nilable(::Integer))
37
+ @max_elapsed_time = T.let(max_elapsed_time, T.nilable(::Integer))
38
+ @max_interval = T.let(max_interval, T.nilable(::Integer))
39
+ end
40
+ end
41
+
42
+ class RetryConfig
43
+ extend T::Sig
44
+
45
+ sig { returns(T.nilable(BackoffStrategy)) }
46
+ attr_accessor :backoff
47
+
48
+ sig { returns(T.nilable(T::Boolean)) }
49
+ attr_accessor :retry_connection_errors
50
+
51
+ sig { returns(T.nilable(::String)) }
52
+ attr_accessor :strategy
53
+
54
+ sig do
55
+ params(
56
+ backoff: T.nilable(BackoffStrategy),
57
+ retry_connection_errors: T.nilable(T::Boolean),
58
+ strategy: T.nilable(::String)
59
+ ).void
60
+ end
61
+ def initialize(backoff: nil, retry_connection_errors: nil, strategy: nil)
62
+ @backoff = T.let(backoff, T.nilable(BackoffStrategy))
63
+ @retry_connection_errors = T.let(retry_connection_errors, T.nilable(T::Boolean))
64
+ @strategy = T.let(strategy, T.nilable(::String))
65
+ end
66
+
67
+ sig { params(initial_time: ::Time).returns(::Hash) }
68
+ def to_faraday_retry_options(initial_time:)
69
+ retry_options = {
70
+ # must overwrite default max of 2 retries and it must be positive
71
+ max: 1_000_000_000,
72
+ # ensure all HTTP methods are retried, especially via retry_if
73
+ methods: [],
74
+ }
75
+
76
+ if @retry_connection_errors
77
+ retry_options[:exceptions] = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
78
+ end
79
+
80
+ if @strategy == 'backoff' && @backoff
81
+ retry_options[:backoff_factor] = @backoff.exponent unless @backoff.exponent.nil?
82
+ retry_options[:interval] = (@backoff.initial_interval.to_f / 1000) unless @backoff.initial_interval.nil?
83
+ retry_options[:max_interval] = @backoff.max_interval unless @backoff.max_interval.nil?
84
+
85
+ unless @backoff.max_elapsed_time.nil?
86
+ stop_time = initial_time + (@backoff.max_elapsed_time.to_f / 1000)
87
+ retry_options[:retry_if] = ->(_env, _exc) { Time.now < stop_time }
88
+ end
89
+ end
90
+
91
+ retry_options
92
+ end
93
+ end
94
+ end
95
+ end
@@ -351,6 +351,15 @@ module PlexRubySDK
351
351
  server_url.delete_suffix('/') + path
352
352
  end
353
353
 
354
+ sig { params(status: Integer).returns(T::Boolean) }
355
+ def self.error_status?(status)
356
+ status_major = status / 100
357
+ return true if status_major == 4
358
+ return true if status_major == 5
359
+
360
+ false
361
+ end
362
+
354
363
  sig { params(content_type: String, pattern: String).returns(T::Boolean) }
355
364
  def self.match_content_type(content_type, pattern)
356
365
  return true if content_type == pattern || ['*', '*/*'].include?(pattern)
@@ -365,6 +374,7 @@ module PlexRubySDK
365
374
 
366
375
  sig { params(req: Faraday::Request, security: Object).void }
367
376
  def self.configure_request_security(req, security)
377
+ return if security.nil?
368
378
  sec_fields = security.fields
369
379
  sec_fields.each do |sec_field|
370
380
  value = security.send(sec_field.name)
@@ -5,7 +5,10 @@
5
5
 
6
6
  require 'faraday'
7
7
  require 'faraday/multipart'
8
+ require 'faraday/retry'
8
9
  require 'sorbet-runtime'
10
+ require_relative 'sdk_hooks/hooks'
11
+ require_relative 'utils/retries'
9
12
 
10
13
  module PlexRubySDK
11
14
  extend T::Sig
@@ -20,8 +23,8 @@ module PlexRubySDK
20
23
  end
21
24
 
22
25
 
23
- sig { params(request: T.nilable(::PlexRubySDK::Operations::GetTimelineRequest)).returns(::PlexRubySDK::Operations::GetTimelineResponse) }
24
- def get_timeline(request)
26
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::GetTimelineRequest), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetTimelineResponse) }
27
+ def get_timeline(request, timeout_ms = nil)
25
28
  # get_timeline - Get the timeline for a media item
26
29
  # Get the timeline for a media item
27
30
  url, params = @sdk_configuration.get_server_details
@@ -32,11 +35,61 @@ module PlexRubySDK
32
35
  headers['Accept'] = 'application/json'
33
36
  headers['user-agent'] = @sdk_configuration.user_agent
34
37
 
35
- r = @sdk_configuration.client.get(url) do |req|
36
- req.headers = headers
37
- req.params = query_params
38
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
39
- Utils.configure_request_security(req, security) if !security.nil?
38
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
39
+
40
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
41
+ timeout ||= @sdk_configuration.timeout
42
+
43
+ connection = @sdk_configuration.client
44
+
45
+ hook_ctx = SDKHooks::HookContext.new(
46
+ base_url: base_url,
47
+ oauth2_scopes: nil,
48
+ operation_id: 'getTimeline',
49
+ security_source: @sdk_configuration.security_source
50
+ )
51
+
52
+ error = T.let(nil, T.nilable(StandardError))
53
+ r = T.let(nil, T.nilable(Faraday::Response))
54
+
55
+ begin
56
+ r = connection.get(url) do |req|
57
+ req.headers.merge!(headers)
58
+ req.options.timeout = timeout unless timeout.nil?
59
+ req.params = query_params
60
+ Utils.configure_request_security(req, security)
61
+
62
+ @sdk_configuration.hooks.before_request(
63
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
64
+ hook_ctx: hook_ctx
65
+ ),
66
+ request: req
67
+ )
68
+ end
69
+ rescue StandardError => e
70
+ error = e
71
+ ensure
72
+ if r.nil? || Utils.error_status?(r.status)
73
+ r = @sdk_configuration.hooks.after_error(
74
+ error: error,
75
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
76
+ hook_ctx: hook_ctx
77
+ ),
78
+ response: r
79
+ )
80
+ else
81
+ r = @sdk_configuration.hooks.after_success(
82
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
83
+ hook_ctx: hook_ctx
84
+ ),
85
+ response: r
86
+ )
87
+ end
88
+
89
+ if r.nil?
90
+ raise error if !error.nil?
91
+ raise 'no response'
92
+ end
40
93
  end
41
94
 
42
95
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -61,8 +114,8 @@ module PlexRubySDK
61
114
  end
62
115
 
63
116
 
64
- sig { params(request: T.nilable(::PlexRubySDK::Operations::StartUniversalTranscodeRequest)).returns(::PlexRubySDK::Operations::StartUniversalTranscodeResponse) }
65
- def start_universal_transcode(request)
117
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::StartUniversalTranscodeRequest), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::StartUniversalTranscodeResponse) }
118
+ def start_universal_transcode(request, timeout_ms = nil)
66
119
  # start_universal_transcode - Start Universal Transcode
67
120
  # Begin a Universal Transcode Session
68
121
  url, params = @sdk_configuration.get_server_details
@@ -73,11 +126,61 @@ module PlexRubySDK
73
126
  headers['Accept'] = 'application/json'
74
127
  headers['user-agent'] = @sdk_configuration.user_agent
75
128
 
76
- r = @sdk_configuration.client.get(url) do |req|
77
- req.headers = headers
78
- req.params = query_params
79
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
80
- Utils.configure_request_security(req, security) if !security.nil?
129
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
130
+
131
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
132
+ timeout ||= @sdk_configuration.timeout
133
+
134
+ connection = @sdk_configuration.client
135
+
136
+ hook_ctx = SDKHooks::HookContext.new(
137
+ base_url: base_url,
138
+ oauth2_scopes: nil,
139
+ operation_id: 'startUniversalTranscode',
140
+ security_source: @sdk_configuration.security_source
141
+ )
142
+
143
+ error = T.let(nil, T.nilable(StandardError))
144
+ r = T.let(nil, T.nilable(Faraday::Response))
145
+
146
+ begin
147
+ r = connection.get(url) do |req|
148
+ req.headers.merge!(headers)
149
+ req.options.timeout = timeout unless timeout.nil?
150
+ req.params = query_params
151
+ Utils.configure_request_security(req, security)
152
+
153
+ @sdk_configuration.hooks.before_request(
154
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
155
+ hook_ctx: hook_ctx
156
+ ),
157
+ request: req
158
+ )
159
+ end
160
+ rescue StandardError => e
161
+ error = e
162
+ ensure
163
+ if r.nil? || Utils.error_status?(r.status)
164
+ r = @sdk_configuration.hooks.after_error(
165
+ error: error,
166
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
167
+ hook_ctx: hook_ctx
168
+ ),
169
+ response: r
170
+ )
171
+ else
172
+ r = @sdk_configuration.hooks.after_success(
173
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
174
+ hook_ctx: hook_ctx
175
+ ),
176
+ response: r
177
+ )
178
+ end
179
+
180
+ if r.nil?
181
+ raise error if !error.nil?
182
+ raise 'no response'
183
+ end
81
184
  end
82
185
 
83
186
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')