plex_ruby_sdk 0.7.7 → 0.8.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.
@@ -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
@@ -50,8 +53,8 @@ module PlexRubySDK
50
53
  end
51
54
 
52
55
 
53
- sig { params(server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetCompanionsDataResponse) }
54
- def get_companions_data(server_url = nil)
56
+ sig { params(server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetCompanionsDataResponse) }
57
+ def get_companions_data(server_url = nil, timeout_ms = nil)
55
58
  # get_companions_data - Get Companions Data
56
59
  # Get Companions Data
57
60
  base_url = Utils.template_url(GET_COMPANIONS_DATA_SERVERS[0], {
@@ -62,10 +65,60 @@ module PlexRubySDK
62
65
  headers['Accept'] = 'application/json'
63
66
  headers['user-agent'] = @sdk_configuration.user_agent
64
67
 
65
- r = @sdk_configuration.client.get(url) do |req|
66
- req.headers = headers
67
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
68
- Utils.configure_request_security(req, security) if !security.nil?
68
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
69
+
70
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
71
+ timeout ||= @sdk_configuration.timeout
72
+
73
+ connection = @sdk_configuration.client
74
+
75
+ hook_ctx = SDKHooks::HookContext.new(
76
+ base_url: base_url,
77
+ oauth2_scopes: nil,
78
+ operation_id: 'getCompanionsData',
79
+ security_source: @sdk_configuration.security_source
80
+ )
81
+
82
+ error = T.let(nil, T.nilable(StandardError))
83
+ r = T.let(nil, T.nilable(Faraday::Response))
84
+
85
+ begin
86
+ r = connection.get(url) do |req|
87
+ req.headers.merge!(headers)
88
+ req.options.timeout = timeout unless timeout.nil?
89
+ Utils.configure_request_security(req, security)
90
+
91
+ @sdk_configuration.hooks.before_request(
92
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
93
+ hook_ctx: hook_ctx
94
+ ),
95
+ request: req
96
+ )
97
+ end
98
+ rescue StandardError => e
99
+ error = e
100
+ ensure
101
+ if r.nil? || Utils.error_status?(r.status)
102
+ r = @sdk_configuration.hooks.after_error(
103
+ error: error,
104
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
105
+ hook_ctx: hook_ctx
106
+ ),
107
+ response: r
108
+ )
109
+ else
110
+ r = @sdk_configuration.hooks.after_success(
111
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
112
+ hook_ctx: hook_ctx
113
+ ),
114
+ response: r
115
+ )
116
+ end
117
+
118
+ if r.nil?
119
+ raise error if !error.nil?
120
+ raise 'no response'
121
+ end
69
122
  end
70
123
 
71
124
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -94,8 +147,8 @@ module PlexRubySDK
94
147
  end
95
148
 
96
149
 
97
- sig { params(server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetUserFriendsResponse) }
98
- def get_user_friends(server_url = nil)
150
+ sig { params(server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetUserFriendsResponse) }
151
+ def get_user_friends(server_url = nil, timeout_ms = nil)
99
152
  # get_user_friends - Get list of friends of the user logged in
100
153
  # Get friends of provided auth token.
101
154
  base_url = Utils.template_url(GET_USER_FRIENDS_SERVERS[0], {
@@ -106,10 +159,60 @@ module PlexRubySDK
106
159
  headers['Accept'] = 'application/json'
107
160
  headers['user-agent'] = @sdk_configuration.user_agent
108
161
 
109
- r = @sdk_configuration.client.get(url) do |req|
110
- req.headers = headers
111
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
112
- Utils.configure_request_security(req, security) if !security.nil?
162
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
163
+
164
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
165
+ timeout ||= @sdk_configuration.timeout
166
+
167
+ connection = @sdk_configuration.client
168
+
169
+ hook_ctx = SDKHooks::HookContext.new(
170
+ base_url: base_url,
171
+ oauth2_scopes: nil,
172
+ operation_id: 'getUserFriends',
173
+ security_source: @sdk_configuration.security_source
174
+ )
175
+
176
+ error = T.let(nil, T.nilable(StandardError))
177
+ r = T.let(nil, T.nilable(Faraday::Response))
178
+
179
+ begin
180
+ r = connection.get(url) do |req|
181
+ req.headers.merge!(headers)
182
+ req.options.timeout = timeout unless timeout.nil?
183
+ Utils.configure_request_security(req, security)
184
+
185
+ @sdk_configuration.hooks.before_request(
186
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
187
+ hook_ctx: hook_ctx
188
+ ),
189
+ request: req
190
+ )
191
+ end
192
+ rescue StandardError => e
193
+ error = e
194
+ ensure
195
+ if r.nil? || Utils.error_status?(r.status)
196
+ r = @sdk_configuration.hooks.after_error(
197
+ error: error,
198
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
199
+ hook_ctx: hook_ctx
200
+ ),
201
+ response: r
202
+ )
203
+ else
204
+ r = @sdk_configuration.hooks.after_success(
205
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
206
+ hook_ctx: hook_ctx
207
+ ),
208
+ response: r
209
+ )
210
+ end
211
+
212
+ if r.nil?
213
+ raise error if !error.nil?
214
+ raise 'no response'
215
+ end
113
216
  end
114
217
 
115
218
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -138,8 +241,8 @@ module PlexRubySDK
138
241
  end
139
242
 
140
243
 
141
- sig { params(server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetGeoDataResponse) }
142
- def get_geo_data(server_url = nil)
244
+ sig { params(server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetGeoDataResponse) }
245
+ def get_geo_data(server_url = nil, timeout_ms = nil)
143
246
  # get_geo_data - Get Geo Data
144
247
  # Returns the geolocation and locale data of the caller
145
248
  base_url = Utils.template_url(GET_GEO_DATA_SERVERS[0], {
@@ -150,8 +253,57 @@ module PlexRubySDK
150
253
  headers['Accept'] = 'application/json'
151
254
  headers['user-agent'] = @sdk_configuration.user_agent
152
255
 
153
- r = @sdk_configuration.client.get(url) do |req|
154
- req.headers = headers
256
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
257
+ timeout ||= @sdk_configuration.timeout
258
+
259
+ connection = @sdk_configuration.client
260
+
261
+ hook_ctx = SDKHooks::HookContext.new(
262
+ base_url: base_url,
263
+ oauth2_scopes: nil,
264
+ operation_id: 'getGeoData',
265
+ security_source: nil
266
+ )
267
+
268
+ error = T.let(nil, T.nilable(StandardError))
269
+ r = T.let(nil, T.nilable(Faraday::Response))
270
+
271
+ begin
272
+ r = connection.get(url) do |req|
273
+ req.headers.merge!(headers)
274
+ req.options.timeout = timeout unless timeout.nil?
275
+
276
+ @sdk_configuration.hooks.before_request(
277
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
278
+ hook_ctx: hook_ctx
279
+ ),
280
+ request: req
281
+ )
282
+ end
283
+ rescue StandardError => e
284
+ error = e
285
+ ensure
286
+ if r.nil? || Utils.error_status?(r.status)
287
+ r = @sdk_configuration.hooks.after_error(
288
+ error: error,
289
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
290
+ hook_ctx: hook_ctx
291
+ ),
292
+ response: r
293
+ )
294
+ else
295
+ r = @sdk_configuration.hooks.after_success(
296
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
297
+ hook_ctx: hook_ctx
298
+ ),
299
+ response: r
300
+ )
301
+ end
302
+
303
+ if r.nil?
304
+ raise error if !error.nil?
305
+ raise 'no response'
306
+ end
155
307
  end
156
308
 
157
309
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -180,8 +332,8 @@ module PlexRubySDK
180
332
  end
181
333
 
182
334
 
183
- sig { returns(::PlexRubySDK::Operations::GetHomeDataResponse) }
184
- def get_home_data
335
+ sig { params(timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetHomeDataResponse) }
336
+ def get_home_data(timeout_ms = nil)
185
337
  # get_home_data - Get Plex Home Data
186
338
  # Retrieves the home data for the authenticated user, including details like home ID, name, guest access information, and subscription status.
187
339
  url, params = @sdk_configuration.get_server_details
@@ -191,10 +343,60 @@ module PlexRubySDK
191
343
  headers['Accept'] = 'application/json'
192
344
  headers['user-agent'] = @sdk_configuration.user_agent
193
345
 
194
- r = @sdk_configuration.client.get(url) do |req|
195
- req.headers = headers
196
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
197
- Utils.configure_request_security(req, security) if !security.nil?
346
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
347
+
348
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
349
+ timeout ||= @sdk_configuration.timeout
350
+
351
+ connection = @sdk_configuration.client
352
+
353
+ hook_ctx = SDKHooks::HookContext.new(
354
+ base_url: base_url,
355
+ oauth2_scopes: nil,
356
+ operation_id: 'getHomeData',
357
+ security_source: @sdk_configuration.security_source
358
+ )
359
+
360
+ error = T.let(nil, T.nilable(StandardError))
361
+ r = T.let(nil, T.nilable(Faraday::Response))
362
+
363
+ begin
364
+ r = connection.get(url) do |req|
365
+ req.headers.merge!(headers)
366
+ req.options.timeout = timeout unless timeout.nil?
367
+ Utils.configure_request_security(req, security)
368
+
369
+ @sdk_configuration.hooks.before_request(
370
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
371
+ hook_ctx: hook_ctx
372
+ ),
373
+ request: req
374
+ )
375
+ end
376
+ rescue StandardError => e
377
+ error = e
378
+ ensure
379
+ if r.nil? || Utils.error_status?(r.status)
380
+ r = @sdk_configuration.hooks.after_error(
381
+ error: error,
382
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
383
+ hook_ctx: hook_ctx
384
+ ),
385
+ response: r
386
+ )
387
+ else
388
+ r = @sdk_configuration.hooks.after_success(
389
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
390
+ hook_ctx: hook_ctx
391
+ ),
392
+ response: r
393
+ )
394
+ end
395
+
396
+ if r.nil?
397
+ raise error if !error.nil?
398
+ raise 'no response'
399
+ end
198
400
  end
199
401
 
200
402
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -223,8 +425,8 @@ module PlexRubySDK
223
425
  end
224
426
 
225
427
 
226
- sig { params(client_id: ::String, include_https: T.nilable(::PlexRubySDK::Operations::IncludeHttps), include_relay: T.nilable(::PlexRubySDK::Operations::IncludeRelay), include_i_pv6: T.nilable(::PlexRubySDK::Operations::IncludeIPv6), server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetServerResourcesResponse) }
227
- def get_server_resources(client_id, include_https = nil, include_relay = nil, include_i_pv6 = nil, server_url = nil)
428
+ sig { params(client_id: ::String, include_https: T.nilable(::PlexRubySDK::Operations::IncludeHttps), include_relay: T.nilable(::PlexRubySDK::Operations::IncludeRelay), include_i_pv6: T.nilable(::PlexRubySDK::Operations::IncludeIPv6), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetServerResourcesResponse) }
429
+ def get_server_resources(client_id, include_https = nil, include_relay = nil, include_i_pv6 = nil, server_url = nil, timeout_ms = nil)
228
430
  # get_server_resources - Get Server Resources
229
431
  # Get Plex server access tokens and server connections
230
432
  request = ::PlexRubySDK::Operations::GetServerResourcesRequest.new(
@@ -243,11 +445,61 @@ module PlexRubySDK
243
445
  headers['Accept'] = 'application/json'
244
446
  headers['user-agent'] = @sdk_configuration.user_agent
245
447
 
246
- r = @sdk_configuration.client.get(url) do |req|
247
- req.headers = headers
248
- req.params = query_params
249
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
250
- Utils.configure_request_security(req, security) if !security.nil?
448
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
449
+
450
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
451
+ timeout ||= @sdk_configuration.timeout
452
+
453
+ connection = @sdk_configuration.client
454
+
455
+ hook_ctx = SDKHooks::HookContext.new(
456
+ base_url: base_url,
457
+ oauth2_scopes: nil,
458
+ operation_id: 'get-server-resources',
459
+ security_source: @sdk_configuration.security_source
460
+ )
461
+
462
+ error = T.let(nil, T.nilable(StandardError))
463
+ r = T.let(nil, T.nilable(Faraday::Response))
464
+
465
+ begin
466
+ r = connection.get(url) do |req|
467
+ req.headers.merge!(headers)
468
+ req.options.timeout = timeout unless timeout.nil?
469
+ req.params = query_params
470
+ Utils.configure_request_security(req, security)
471
+
472
+ @sdk_configuration.hooks.before_request(
473
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
474
+ hook_ctx: hook_ctx
475
+ ),
476
+ request: req
477
+ )
478
+ end
479
+ rescue StandardError => e
480
+ error = e
481
+ ensure
482
+ if r.nil? || Utils.error_status?(r.status)
483
+ r = @sdk_configuration.hooks.after_error(
484
+ error: error,
485
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
486
+ hook_ctx: hook_ctx
487
+ ),
488
+ response: r
489
+ )
490
+ else
491
+ r = @sdk_configuration.hooks.after_success(
492
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
493
+ hook_ctx: hook_ctx
494
+ ),
495
+ response: r
496
+ )
497
+ end
498
+
499
+ if r.nil?
500
+ raise error if !error.nil?
501
+ raise 'no response'
502
+ end
251
503
  end
252
504
 
253
505
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -276,8 +528,8 @@ module PlexRubySDK
276
528
  end
277
529
 
278
530
 
279
- sig { params(request: T.nilable(::PlexRubySDK::Operations::GetPinRequest), server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetPinResponse) }
280
- def get_pin(request, server_url = nil)
531
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::GetPinRequest), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetPinResponse) }
532
+ def get_pin(request, server_url = nil, timeout_ms = nil)
281
533
  # get_pin - Get a Pin
282
534
  # Retrieve a Pin ID from Plex.tv to use for authentication flows
283
535
  base_url = Utils.template_url(GET_PIN_SERVERS[0], {
@@ -289,9 +541,58 @@ module PlexRubySDK
289
541
  headers['Accept'] = 'application/json'
290
542
  headers['user-agent'] = @sdk_configuration.user_agent
291
543
 
292
- r = @sdk_configuration.client.post(url) do |req|
293
- req.headers = headers
294
- req.params = query_params
544
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
545
+ timeout ||= @sdk_configuration.timeout
546
+
547
+ connection = @sdk_configuration.client
548
+
549
+ hook_ctx = SDKHooks::HookContext.new(
550
+ base_url: base_url,
551
+ oauth2_scopes: nil,
552
+ operation_id: 'getPin',
553
+ security_source: nil
554
+ )
555
+
556
+ error = T.let(nil, T.nilable(StandardError))
557
+ r = T.let(nil, T.nilable(Faraday::Response))
558
+
559
+ begin
560
+ r = connection.post(url) do |req|
561
+ req.headers.merge!(headers)
562
+ req.options.timeout = timeout unless timeout.nil?
563
+ req.params = query_params
564
+
565
+ @sdk_configuration.hooks.before_request(
566
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
567
+ hook_ctx: hook_ctx
568
+ ),
569
+ request: req
570
+ )
571
+ end
572
+ rescue StandardError => e
573
+ error = e
574
+ ensure
575
+ if r.nil? || Utils.error_status?(r.status)
576
+ r = @sdk_configuration.hooks.after_error(
577
+ error: error,
578
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
579
+ hook_ctx: hook_ctx
580
+ ),
581
+ response: r
582
+ )
583
+ else
584
+ r = @sdk_configuration.hooks.after_success(
585
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
586
+ hook_ctx: hook_ctx
587
+ ),
588
+ response: r
589
+ )
590
+ end
591
+
592
+ if r.nil?
593
+ raise error if !error.nil?
594
+ raise 'no response'
595
+ end
295
596
  end
296
597
 
297
598
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -315,8 +616,8 @@ module PlexRubySDK
315
616
  end
316
617
 
317
618
 
318
- sig { params(request: T.nilable(::PlexRubySDK::Operations::GetTokenByPinIdRequest), server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetTokenByPinIdResponse) }
319
- def get_token_by_pin_id(request, server_url = nil)
619
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::GetTokenByPinIdRequest), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetTokenByPinIdResponse) }
620
+ def get_token_by_pin_id(request, server_url = nil, timeout_ms = nil)
320
621
  # get_token_by_pin_id - Get Access Token by PinId
321
622
  # Retrieve an Access Token from Plex.tv after the Pin has been authenticated
322
623
  base_url = Utils.template_url(GET_TOKEN_BY_PIN_ID_SERVERS[0], {
@@ -332,8 +633,57 @@ module PlexRubySDK
332
633
  headers['Accept'] = 'application/json'
333
634
  headers['user-agent'] = @sdk_configuration.user_agent
334
635
 
335
- r = @sdk_configuration.client.get(url) do |req|
336
- req.headers = headers
636
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
637
+ timeout ||= @sdk_configuration.timeout
638
+
639
+ connection = @sdk_configuration.client
640
+
641
+ hook_ctx = SDKHooks::HookContext.new(
642
+ base_url: base_url,
643
+ oauth2_scopes: nil,
644
+ operation_id: 'getTokenByPinId',
645
+ security_source: nil
646
+ )
647
+
648
+ error = T.let(nil, T.nilable(StandardError))
649
+ r = T.let(nil, T.nilable(Faraday::Response))
650
+
651
+ begin
652
+ r = connection.get(url) do |req|
653
+ req.headers.merge!(headers)
654
+ req.options.timeout = timeout unless timeout.nil?
655
+
656
+ @sdk_configuration.hooks.before_request(
657
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
658
+ hook_ctx: hook_ctx
659
+ ),
660
+ request: req
661
+ )
662
+ end
663
+ rescue StandardError => e
664
+ error = e
665
+ ensure
666
+ if r.nil? || Utils.error_status?(r.status)
667
+ r = @sdk_configuration.hooks.after_error(
668
+ error: error,
669
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
670
+ hook_ctx: hook_ctx
671
+ ),
672
+ response: r
673
+ )
674
+ else
675
+ r = @sdk_configuration.hooks.after_success(
676
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
677
+ hook_ctx: hook_ctx
678
+ ),
679
+ response: r
680
+ )
681
+ end
682
+
683
+ if r.nil?
684
+ raise error if !error.nil?
685
+ raise 'no response'
686
+ end
337
687
  end
338
688
 
339
689
  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
@@ -17,7 +20,9 @@ module PlexRubySDK
17
20
 
18
21
  sig do
19
22
  params(
20
- client: T.nilable(Faraday::Request),
23
+ client: T.nilable(Faraday::Connection),
24
+ retry_config: T.nilable(::PlexRubySDK::Utils::RetryConfig),
25
+ timeout_ms: T.nilable(Integer),
21
26
  security: T.nilable(::PlexRubySDK::Shared::Security),
22
27
  security_source: T.nilable(T.proc.returns(::PlexRubySDK::Shared::Security)),
23
28
  protocol: T.nilable(::PlexRubySDK::ServerVariables::ServerProtocol),
@@ -28,9 +33,11 @@ module PlexRubySDK
28
33
  url_params: T.nilable(T::Hash[Symbol, String])
29
34
  ).void
30
35
  end
31
- def initialize(client: nil, security: nil, security_source: nil, protocol: nil, ip: nil, port: nil, server_idx: nil, server_url: nil, url_params: nil)
36
+ def initialize(client: nil, retry_config: nil, timeout_ms: nil, security: nil, security_source: nil, protocol: nil, ip: nil, port: nil, server_idx: nil, server_url: nil, url_params: nil)
32
37
  ## Instantiates the SDK configuring it with the provided parameters.
33
- # @param [T.nilable(Faraday::Request)] client The faraday HTTP client to use for all operations
38
+ # @param [T.nilable(Faraday::Connection)] client The faraday HTTP client to use for all operations
39
+ # @param [T.nilable(::PlexRubySDK::Utils::RetryConfig)] retry_config The retry configuration to use for all operations
40
+ # @param [T.nilable(Integer)] timeout_ms Request timeout in milliseconds for all operations
34
41
  # @param [T.nilable(::PlexRubySDK::Shared::Security)] security: The security details required for authentication
35
42
  # @param [T.proc.returns(T.nilable(::PlexRubySDK::Shared::Security))] security_source: A function that returns security details required for authentication
36
43
  # @param [T.nilable(::PlexRubySDK::ServerVariables::ServerProtocol)] protocol: Allows setting the protocol variable for url substitution
@@ -40,13 +47,16 @@ module PlexRubySDK
40
47
  # @param [T.nilable(::String)] server_url The server URL to use for all operations
41
48
  # @param [T.nilable(::Hash<::Symbol, ::String>)] url_params Parameters to optionally template the server URL with
42
49
 
43
- if client.nil?
44
- client = Faraday.new(request: {
45
- params_encoder: Faraday::FlatParamsEncoder
46
- }) do |f|
47
- f.request :multipart, {}
48
- # f.response :logger
49
- end
50
+ connection_options = {
51
+ request: {
52
+ params_encoder: Faraday::FlatParamsEncoder
53
+ }
54
+ }
55
+ connection_options[:request][:timeout] = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
56
+
57
+ client ||= Faraday.new(**connection_options) do |f|
58
+ f.request :multipart, {}
59
+ # f.response :logger, nil, { headers: true, bodies: true, errors: true }
50
60
  end
51
61
 
52
62
  if !server_url.nil?
@@ -71,14 +81,23 @@ module PlexRubySDK
71
81
  port: port || '32400',
72
82
  },
73
83
  ]
84
+ hooks = SDKHooks::Hooks.new
74
85
  @sdk_configuration = SDKConfiguration.new(
75
86
  client,
87
+ hooks,
88
+ retry_config,
89
+ timeout_ms,
76
90
  security,
77
91
  security_source,
78
92
  server_url,
79
93
  server_idx,
80
94
  server_params
81
95
  )
96
+
97
+ original_server_url = @sdk_configuration.get_server_details.first
98
+ new_server_url, @sdk_configuration.client = hooks.sdk_init(base_url: original_server_url, client: client)
99
+ @sdk_configuration.server_url = new_server_url if new_server_url != original_server_url
100
+
82
101
  init_sdks
83
102
  end
84
103