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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc5669c272bc4c54f69e1761805f666a6b72f36eb36bcc1434b779837efe3a8e
4
- data.tar.gz: 69d1507df62ebe5e46d44305e2dd6d09e2770993cab0b7dcfa1473bb9eb49cab
3
+ metadata.gz: 8c826c6bba14335b50adff99ea7aeadace3961d533aeb638c984539c524ef57a
4
+ data.tar.gz: 1cbc5ab44c993b9a38dee33743a3c20829a38fd74e1d4cac39a89e20caab5147
5
5
  SHA512:
6
- metadata.gz: 9c4bd2b7f9f46463baf38cd598414c2b43957c56b6a47269d0b64db878d4054ad352b1d575c0c8349f24a81fc265ab911684e0851c576e57c2714a798f6dd8d2
7
- data.tar.gz: ee762271f9f25e9e61dfb7b4e168c78e5d665a647fa479b47c5838b5ba054a1416f6554d7c2c4b2ebbe427fe3d23959e27a98670bb84bea769857830ca0d340a
6
+ metadata.gz: 2a523986a25e9095fc461b49e55295d6b7db299ed012719f771cec9ece3eb409996b406f6147a07194ac336140e8939a53b95c4223e8867e39a2ffc70b2b681c
7
+ data.tar.gz: f340e7c3c73b071cf403b98eca04190df9b251999e9d54bdf62e562bd9cb5a39d2d95fa4c26dae6fbba4a22ec35e85791b353146dc6f57c71d50803b56755f60
@@ -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
@@ -26,8 +29,8 @@ module PlexRubySDK
26
29
  end
27
30
 
28
31
 
29
- sig { returns(::PlexRubySDK::Operations::GetServerActivitiesResponse) }
30
- def get_server_activities
32
+ sig { params(timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetServerActivitiesResponse) }
33
+ def get_server_activities(timeout_ms = nil)
31
34
  # get_server_activities - Get Server Activities
32
35
  # Get Server Activities
33
36
  url, params = @sdk_configuration.get_server_details
@@ -37,10 +40,60 @@ module PlexRubySDK
37
40
  headers['Accept'] = 'application/json'
38
41
  headers['user-agent'] = @sdk_configuration.user_agent
39
42
 
40
- r = @sdk_configuration.client.get(url) do |req|
41
- req.headers = headers
42
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
43
- Utils.configure_request_security(req, security) if !security.nil?
43
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
44
+
45
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
46
+ timeout ||= @sdk_configuration.timeout
47
+
48
+ connection = @sdk_configuration.client
49
+
50
+ hook_ctx = SDKHooks::HookContext.new(
51
+ base_url: base_url,
52
+ oauth2_scopes: nil,
53
+ operation_id: 'getServerActivities',
54
+ security_source: @sdk_configuration.security_source
55
+ )
56
+
57
+ error = T.let(nil, T.nilable(StandardError))
58
+ r = T.let(nil, T.nilable(Faraday::Response))
59
+
60
+ begin
61
+ r = connection.get(url) do |req|
62
+ req.headers.merge!(headers)
63
+ req.options.timeout = timeout unless timeout.nil?
64
+ Utils.configure_request_security(req, security)
65
+
66
+ @sdk_configuration.hooks.before_request(
67
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
68
+ hook_ctx: hook_ctx
69
+ ),
70
+ request: req
71
+ )
72
+ end
73
+ rescue StandardError => e
74
+ error = e
75
+ ensure
76
+ if r.nil? || Utils.error_status?(r.status)
77
+ r = @sdk_configuration.hooks.after_error(
78
+ error: error,
79
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
80
+ hook_ctx: hook_ctx
81
+ ),
82
+ response: r
83
+ )
84
+ else
85
+ r = @sdk_configuration.hooks.after_success(
86
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
87
+ hook_ctx: hook_ctx
88
+ ),
89
+ response: r
90
+ )
91
+ end
92
+
93
+ if r.nil?
94
+ raise error if !error.nil?
95
+ raise 'no response'
96
+ end
44
97
  end
45
98
 
46
99
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -69,8 +122,8 @@ module PlexRubySDK
69
122
  end
70
123
 
71
124
 
72
- sig { params(activity_uuid: ::String).returns(::PlexRubySDK::Operations::CancelServerActivitiesResponse) }
73
- def cancel_server_activities(activity_uuid)
125
+ sig { params(activity_uuid: ::String, timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::CancelServerActivitiesResponse) }
126
+ def cancel_server_activities(activity_uuid, timeout_ms = nil)
74
127
  # cancel_server_activities - Cancel Server Activities
75
128
  # Cancel Server Activities
76
129
  request = ::PlexRubySDK::Operations::CancelServerActivitiesRequest.new(
@@ -89,10 +142,60 @@ module PlexRubySDK
89
142
  headers['Accept'] = 'application/json'
90
143
  headers['user-agent'] = @sdk_configuration.user_agent
91
144
 
92
- r = @sdk_configuration.client.delete(url) do |req|
93
- req.headers = headers
94
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
95
- Utils.configure_request_security(req, security) if !security.nil?
145
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
146
+
147
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
148
+ timeout ||= @sdk_configuration.timeout
149
+
150
+ connection = @sdk_configuration.client
151
+
152
+ hook_ctx = SDKHooks::HookContext.new(
153
+ base_url: base_url,
154
+ oauth2_scopes: nil,
155
+ operation_id: 'cancelServerActivities',
156
+ security_source: @sdk_configuration.security_source
157
+ )
158
+
159
+ error = T.let(nil, T.nilable(StandardError))
160
+ r = T.let(nil, T.nilable(Faraday::Response))
161
+
162
+ begin
163
+ r = connection.delete(url) do |req|
164
+ req.headers.merge!(headers)
165
+ req.options.timeout = timeout unless timeout.nil?
166
+ Utils.configure_request_security(req, security)
167
+
168
+ @sdk_configuration.hooks.before_request(
169
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
170
+ hook_ctx: hook_ctx
171
+ ),
172
+ request: req
173
+ )
174
+ end
175
+ rescue StandardError => e
176
+ error = e
177
+ ensure
178
+ if r.nil? || Utils.error_status?(r.status)
179
+ r = @sdk_configuration.hooks.after_error(
180
+ error: error,
181
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
182
+ hook_ctx: hook_ctx
183
+ ),
184
+ response: r
185
+ )
186
+ else
187
+ r = @sdk_configuration.hooks.after_success(
188
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
189
+ hook_ctx: hook_ctx
190
+ ),
191
+ response: r
192
+ )
193
+ end
194
+
195
+ if r.nil?
196
+ raise error if !error.nil?
197
+ raise 'no response'
198
+ end
96
199
  end
97
200
 
98
201
  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
@@ -30,8 +33,8 @@ module PlexRubySDK
30
33
  end
31
34
 
32
35
 
33
- sig { params(type: ::PlexRubySDK::Operations::GetTransientTokenQueryParamType, scope: ::PlexRubySDK::Operations::Scope).returns(::PlexRubySDK::Operations::GetTransientTokenResponse) }
34
- def get_transient_token(type, scope)
36
+ sig { params(type: ::PlexRubySDK::Operations::GetTransientTokenQueryParamType, scope: ::PlexRubySDK::Operations::Scope, timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetTransientTokenResponse) }
37
+ def get_transient_token(type, scope, timeout_ms = nil)
35
38
  # get_transient_token - Get a Transient Token
36
39
  # This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.
37
40
  #
@@ -48,11 +51,61 @@ module PlexRubySDK
48
51
  headers['Accept'] = 'application/json'
49
52
  headers['user-agent'] = @sdk_configuration.user_agent
50
53
 
51
- r = @sdk_configuration.client.get(url) do |req|
52
- req.headers = headers
53
- req.params = query_params
54
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
55
- Utils.configure_request_security(req, security) if !security.nil?
54
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
55
+
56
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
57
+ timeout ||= @sdk_configuration.timeout
58
+
59
+ connection = @sdk_configuration.client
60
+
61
+ hook_ctx = SDKHooks::HookContext.new(
62
+ base_url: base_url,
63
+ oauth2_scopes: nil,
64
+ operation_id: 'getTransientToken',
65
+ security_source: @sdk_configuration.security_source
66
+ )
67
+
68
+ error = T.let(nil, T.nilable(StandardError))
69
+ r = T.let(nil, T.nilable(Faraday::Response))
70
+
71
+ begin
72
+ r = connection.get(url) do |req|
73
+ req.headers.merge!(headers)
74
+ req.options.timeout = timeout unless timeout.nil?
75
+ req.params = query_params
76
+ Utils.configure_request_security(req, security)
77
+
78
+ @sdk_configuration.hooks.before_request(
79
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
80
+ hook_ctx: hook_ctx
81
+ ),
82
+ request: req
83
+ )
84
+ end
85
+ rescue StandardError => e
86
+ error = e
87
+ ensure
88
+ if r.nil? || Utils.error_status?(r.status)
89
+ r = @sdk_configuration.hooks.after_error(
90
+ error: error,
91
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
92
+ hook_ctx: hook_ctx
93
+ ),
94
+ response: r
95
+ )
96
+ else
97
+ r = @sdk_configuration.hooks.after_success(
98
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
99
+ hook_ctx: hook_ctx
100
+ ),
101
+ response: r
102
+ )
103
+ end
104
+
105
+ if r.nil?
106
+ raise error if !error.nil?
107
+ raise 'no response'
108
+ end
56
109
  end
57
110
 
58
111
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -77,8 +130,8 @@ module PlexRubySDK
77
130
  end
78
131
 
79
132
 
80
- sig { params(source: ::String).returns(::PlexRubySDK::Operations::GetSourceConnectionInformationResponse) }
81
- def get_source_connection_information(source)
133
+ sig { params(source: ::String, timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetSourceConnectionInformationResponse) }
134
+ def get_source_connection_information(source, timeout_ms = nil)
82
135
  # get_source_connection_information - Get Source Connection Information
83
136
  # If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
84
137
  # Note: requires Plex Media Server >= 1.15.4.
@@ -95,11 +148,61 @@ module PlexRubySDK
95
148
  headers['Accept'] = 'application/json'
96
149
  headers['user-agent'] = @sdk_configuration.user_agent
97
150
 
98
- r = @sdk_configuration.client.get(url) do |req|
99
- req.headers = headers
100
- req.params = query_params
101
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
102
- Utils.configure_request_security(req, security) if !security.nil?
151
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
152
+
153
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
154
+ timeout ||= @sdk_configuration.timeout
155
+
156
+ connection = @sdk_configuration.client
157
+
158
+ hook_ctx = SDKHooks::HookContext.new(
159
+ base_url: base_url,
160
+ oauth2_scopes: nil,
161
+ operation_id: 'getSourceConnectionInformation',
162
+ security_source: @sdk_configuration.security_source
163
+ )
164
+
165
+ error = T.let(nil, T.nilable(StandardError))
166
+ r = T.let(nil, T.nilable(Faraday::Response))
167
+
168
+ begin
169
+ r = connection.get(url) do |req|
170
+ req.headers.merge!(headers)
171
+ req.options.timeout = timeout unless timeout.nil?
172
+ req.params = query_params
173
+ Utils.configure_request_security(req, security)
174
+
175
+ @sdk_configuration.hooks.before_request(
176
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
177
+ hook_ctx: hook_ctx
178
+ ),
179
+ request: req
180
+ )
181
+ end
182
+ rescue StandardError => e
183
+ error = e
184
+ ensure
185
+ if r.nil? || Utils.error_status?(r.status)
186
+ r = @sdk_configuration.hooks.after_error(
187
+ error: error,
188
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
189
+ hook_ctx: hook_ctx
190
+ ),
191
+ response: r
192
+ )
193
+ else
194
+ r = @sdk_configuration.hooks.after_success(
195
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
196
+ hook_ctx: hook_ctx
197
+ ),
198
+ response: r
199
+ )
200
+ end
201
+
202
+ if r.nil?
203
+ raise error if !error.nil?
204
+ raise 'no response'
205
+ end
103
206
  end
104
207
 
105
208
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -124,8 +227,8 @@ module PlexRubySDK
124
227
  end
125
228
 
126
229
 
127
- sig { params(server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::GetTokenDetailsResponse) }
128
- def get_token_details(server_url = nil)
230
+ sig { params(server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetTokenDetailsResponse) }
231
+ def get_token_details(server_url = nil, timeout_ms = nil)
129
232
  # get_token_details - Get Token Details
130
233
  # Get the User data from the provided X-Plex-Token
131
234
  base_url = Utils.template_url(GET_TOKEN_DETAILS_SERVERS[0], {
@@ -136,10 +239,60 @@ module PlexRubySDK
136
239
  headers['Accept'] = 'application/json'
137
240
  headers['user-agent'] = @sdk_configuration.user_agent
138
241
 
139
- r = @sdk_configuration.client.get(url) do |req|
140
- req.headers = headers
141
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
142
- Utils.configure_request_security(req, security) if !security.nil?
242
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
243
+
244
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
245
+ timeout ||= @sdk_configuration.timeout
246
+
247
+ connection = @sdk_configuration.client
248
+
249
+ hook_ctx = SDKHooks::HookContext.new(
250
+ base_url: base_url,
251
+ oauth2_scopes: nil,
252
+ operation_id: 'getTokenDetails',
253
+ security_source: @sdk_configuration.security_source
254
+ )
255
+
256
+ error = T.let(nil, T.nilable(StandardError))
257
+ r = T.let(nil, T.nilable(Faraday::Response))
258
+
259
+ begin
260
+ r = connection.get(url) do |req|
261
+ req.headers.merge!(headers)
262
+ req.options.timeout = timeout unless timeout.nil?
263
+ Utils.configure_request_security(req, security)
264
+
265
+ @sdk_configuration.hooks.before_request(
266
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
267
+ hook_ctx: hook_ctx
268
+ ),
269
+ request: req
270
+ )
271
+ end
272
+ rescue StandardError => e
273
+ error = e
274
+ ensure
275
+ if r.nil? || Utils.error_status?(r.status)
276
+ r = @sdk_configuration.hooks.after_error(
277
+ error: error,
278
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
279
+ hook_ctx: hook_ctx
280
+ ),
281
+ response: r
282
+ )
283
+ else
284
+ r = @sdk_configuration.hooks.after_success(
285
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
286
+ hook_ctx: hook_ctx
287
+ ),
288
+ response: r
289
+ )
290
+ end
291
+
292
+ if r.nil?
293
+ raise error if !error.nil?
294
+ raise 'no response'
295
+ end
143
296
  end
144
297
 
145
298
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -168,8 +321,8 @@ module PlexRubySDK
168
321
  end
169
322
 
170
323
 
171
- sig { params(request: T.nilable(::PlexRubySDK::Operations::PostUsersSignInDataRequest), server_url: T.nilable(String)).returns(::PlexRubySDK::Operations::PostUsersSignInDataResponse) }
172
- def post_users_sign_in_data(request, server_url = nil)
324
+ sig { params(request: T.nilable(::PlexRubySDK::Operations::PostUsersSignInDataRequest), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::PostUsersSignInDataResponse) }
325
+ def post_users_sign_in_data(request, server_url = nil, timeout_ms = nil)
173
326
  # post_users_sign_in_data - Get User Sign In Data
174
327
  # Sign in user with username and password and return user data with Plex authentication token
175
328
  base_url = Utils.template_url(POST_USERS_SIGN_IN_DATA_SERVERS[0], {
@@ -179,17 +332,68 @@ module PlexRubySDK
179
332
  headers = Utils.get_headers(request)
180
333
  req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :form)
181
334
  headers['content-type'] = req_content_type
335
+
336
+ if form
337
+ body = Utils.encode_form(form)
338
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
339
+ body = URI.encode_www_form(data)
340
+ else
341
+ body = data
342
+ end
182
343
  headers['Accept'] = 'application/json'
183
344
  headers['user-agent'] = @sdk_configuration.user_agent
184
345
 
185
- r = @sdk_configuration.client.post(url) do |req|
186
- req.headers = headers
187
- if form
188
- req.body = Utils.encode_form(form)
189
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
190
- req.body = URI.encode_www_form(data)
346
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
347
+ timeout ||= @sdk_configuration.timeout
348
+
349
+ connection = @sdk_configuration.client
350
+
351
+ hook_ctx = SDKHooks::HookContext.new(
352
+ base_url: base_url,
353
+ oauth2_scopes: nil,
354
+ operation_id: 'post-users-sign-in-data',
355
+ security_source: nil
356
+ )
357
+
358
+ error = T.let(nil, T.nilable(StandardError))
359
+ r = T.let(nil, T.nilable(Faraday::Response))
360
+
361
+ begin
362
+ r = connection.post(url) do |req|
363
+ req.body = body
364
+ req.headers.merge!(headers)
365
+ req.options.timeout = timeout unless timeout.nil?
366
+
367
+ @sdk_configuration.hooks.before_request(
368
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
369
+ hook_ctx: hook_ctx
370
+ ),
371
+ request: req
372
+ )
373
+ end
374
+ rescue StandardError => e
375
+ error = e
376
+ ensure
377
+ if r.nil? || Utils.error_status?(r.status)
378
+ r = @sdk_configuration.hooks.after_error(
379
+ error: error,
380
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
381
+ hook_ctx: hook_ctx
382
+ ),
383
+ response: r
384
+ )
191
385
  else
192
- req.body = data
386
+ r = @sdk_configuration.hooks.after_success(
387
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
388
+ hook_ctx: hook_ctx
389
+ ),
390
+ response: r
391
+ )
392
+ end
393
+
394
+ if r.nil?
395
+ raise error if !error.nil?
396
+ raise 'no response'
193
397
  end
194
398
  end
195
399