ittybit 0.7.4

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 (63) hide show
  1. checksums.yaml +7 -0
  2. data/lib/environment.rb +7 -0
  3. data/lib/gemconfig.rb +14 -0
  4. data/lib/ittybit/automations/client.rb +412 -0
  5. data/lib/ittybit/automations/types/automations_update_request_trigger.rb +75 -0
  6. data/lib/ittybit/automations/types/automations_update_request_trigger_conditions_item.rb +69 -0
  7. data/lib/ittybit/files/client.rb +437 -0
  8. data/lib/ittybit/files/types/files_delete_response.rb +89 -0
  9. data/lib/ittybit/files/types/files_delete_response_data.rb +60 -0
  10. data/lib/ittybit/media/client.rb +367 -0
  11. data/lib/ittybit/signatures/client.rb +132 -0
  12. data/lib/ittybit/signatures/types/signatures_create_request_method.rb +13 -0
  13. data/lib/ittybit/tasks/client.rb +379 -0
  14. data/lib/ittybit/tasks/types/tasks_create_request_kind.rb +22 -0
  15. data/lib/ittybit/tasks/types/tasks_list_request_kind.rb +26 -0
  16. data/lib/ittybit/tasks/types/tasks_list_request_status.rb +16 -0
  17. data/lib/ittybit/types/api_response_base.rb +5 -0
  18. data/lib/ittybit/types/automation.rb +141 -0
  19. data/lib/ittybit/types/automation_list_response.rb +90 -0
  20. data/lib/ittybit/types/automation_response.rb +87 -0
  21. data/lib/ittybit/types/automation_status.rb +10 -0
  22. data/lib/ittybit/types/automation_trigger.rb +72 -0
  23. data/lib/ittybit/types/automation_trigger_conditions_item.rb +65 -0
  24. data/lib/ittybit/types/confirmation_response.rb +87 -0
  25. data/lib/ittybit/types/confirmation_response_data.rb +55 -0
  26. data/lib/ittybit/types/error.rb +57 -0
  27. data/lib/ittybit/types/error_response.rb +74 -0
  28. data/lib/ittybit/types/file.rb +319 -0
  29. data/lib/ittybit/types/file_kind.rb +10 -0
  30. data/lib/ittybit/types/file_list_response.rb +90 -0
  31. data/lib/ittybit/types/file_object.rb +10 -0
  32. data/lib/ittybit/types/file_response.rb +87 -0
  33. data/lib/ittybit/types/file_status.rb +11 -0
  34. data/lib/ittybit/types/links.rb +67 -0
  35. data/lib/ittybit/types/links_list.rb +103 -0
  36. data/lib/ittybit/types/media.rb +195 -0
  37. data/lib/ittybit/types/media_kind.rb +10 -0
  38. data/lib/ittybit/types/media_list_response.rb +90 -0
  39. data/lib/ittybit/types/media_response.rb +87 -0
  40. data/lib/ittybit/types/media_source.rb +261 -0
  41. data/lib/ittybit/types/media_source_kind.rb +10 -0
  42. data/lib/ittybit/types/media_source_object.rb +10 -0
  43. data/lib/ittybit/types/media_source_status.rb +11 -0
  44. data/lib/ittybit/types/media_urls.rb +70 -0
  45. data/lib/ittybit/types/meta.rb +5 -0
  46. data/lib/ittybit/types/meta_list.rb +103 -0
  47. data/lib/ittybit/types/signature.rb +110 -0
  48. data/lib/ittybit/types/signature_response.rb +87 -0
  49. data/lib/ittybit/types/task.rb +204 -0
  50. data/lib/ittybit/types/task_kind.rb +5 -0
  51. data/lib/ittybit/types/task_list_response.rb +90 -0
  52. data/lib/ittybit/types/task_response.rb +87 -0
  53. data/lib/ittybit/types/task_results.rb +74 -0
  54. data/lib/ittybit/types/task_status.rb +15 -0
  55. data/lib/ittybit/types/task_summary.rb +138 -0
  56. data/lib/ittybit/types/task_summary_kind.rb +25 -0
  57. data/lib/ittybit/types/task_summary_status.rb +15 -0
  58. data/lib/ittybit/types/workflow_task_step.rb +112 -0
  59. data/lib/ittybit/types/workflow_task_step_kind.rb +25 -0
  60. data/lib/ittybit.rb +86 -0
  61. data/lib/requests.rb +177 -0
  62. data/lib/types_export.rb +53 -0
  63. metadata +185 -0
@@ -0,0 +1,367 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/media_list_response"
5
+ require_relative "../types/media_response"
6
+ require_relative "../types/confirmation_response"
7
+ require "async"
8
+
9
+ module Ittybit
10
+ class MediaClient
11
+ # @return [Ittybit::RequestClient]
12
+ attr_reader :request_client
13
+
14
+ # @param request_client [Ittybit::RequestClient]
15
+ # @return [Ittybit::MediaClient]
16
+ def initialize(request_client:)
17
+ @request_client = request_client
18
+ end
19
+
20
+ # Retrieves a list of all media for the current project
21
+ #
22
+ # @param limit [Integer] Number of media items to return per page.
23
+ # @param request_options [Ittybit::RequestOptions]
24
+ # @return [Ittybit::MediaListResponse]
25
+ # @example
26
+ # api = Ittybit::Client.new(
27
+ # base_url: "https://api.example.com",
28
+ # environment: Ittybit::Environment::DEFAULT,
29
+ # token: "YOUR_AUTH_TOKEN"
30
+ # )
31
+ # api.media.list
32
+ def list(limit: nil, request_options: nil)
33
+ response = @request_client.conn.get do |req|
34
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
35
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
36
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
37
+ req.headers = {
38
+ **(req.headers || {}),
39
+ **@request_client.get_headers,
40
+ **(request_options&.additional_headers || {})
41
+ }.compact
42
+ req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit }.compact
43
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
44
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
45
+ end
46
+ req.url "#{@request_client.get_url(request_options: request_options)}/media"
47
+ end
48
+ Ittybit::MediaListResponse.from_json(json_object: response.body)
49
+ end
50
+
51
+ # Creates a new media item from a URL or as an empty placeholder
52
+ #
53
+ # @param title [String] Title for the media
54
+ # @param metadata [Hash{String => Object}] Additional metadata for the media
55
+ # @param request_options [Ittybit::RequestOptions]
56
+ # @return [Ittybit::MediaResponse]
57
+ # @example
58
+ # api = Ittybit::Client.new(
59
+ # base_url: "https://api.example.com",
60
+ # environment: Ittybit::Environment::DEFAULT,
61
+ # token: "YOUR_AUTH_TOKEN"
62
+ # )
63
+ # api.media.create(metadata: { "credit": "gtv-videos-bucket" })
64
+ def create(title: nil, metadata: nil, request_options: nil)
65
+ response = @request_client.conn.post do |req|
66
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
67
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
68
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
69
+ req.headers = {
70
+ **(req.headers || {}),
71
+ **@request_client.get_headers,
72
+ **(request_options&.additional_headers || {})
73
+ }.compact
74
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
75
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
76
+ end
77
+ req.body = { **(request_options&.additional_body_parameters || {}), title: title, metadata: metadata }.compact
78
+ req.url "#{@request_client.get_url(request_options: request_options)}/media"
79
+ end
80
+ Ittybit::MediaResponse.from_json(json_object: response.body)
81
+ end
82
+
83
+ # Retrieves a specific media item by its ID
84
+ #
85
+ # @param id [String]
86
+ # @param request_options [Ittybit::RequestOptions]
87
+ # @return [Ittybit::MediaResponse]
88
+ # @example
89
+ # api = Ittybit::Client.new(
90
+ # base_url: "https://api.example.com",
91
+ # environment: Ittybit::Environment::DEFAULT,
92
+ # token: "YOUR_AUTH_TOKEN"
93
+ # )
94
+ # api.media.get(id: "id")
95
+ def get(id:, request_options: nil)
96
+ response = @request_client.conn.get do |req|
97
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
98
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
99
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
100
+ req.headers = {
101
+ **(req.headers || {}),
102
+ **@request_client.get_headers,
103
+ **(request_options&.additional_headers || {})
104
+ }.compact
105
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
106
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
107
+ end
108
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
109
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
110
+ end
111
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
112
+ end
113
+ Ittybit::MediaResponse.from_json(json_object: response.body)
114
+ end
115
+
116
+ # Deletes a specific media item by its ID
117
+ #
118
+ # @param id [String]
119
+ # @param request_options [Ittybit::RequestOptions]
120
+ # @return [Ittybit::ConfirmationResponse]
121
+ # @example
122
+ # api = Ittybit::Client.new(
123
+ # base_url: "https://api.example.com",
124
+ # environment: Ittybit::Environment::DEFAULT,
125
+ # token: "YOUR_AUTH_TOKEN"
126
+ # )
127
+ # api.media.delete(id: "id")
128
+ def delete(id:, request_options: nil)
129
+ response = @request_client.conn.delete do |req|
130
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
131
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
132
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
133
+ req.headers = {
134
+ **(req.headers || {}),
135
+ **@request_client.get_headers,
136
+ **(request_options&.additional_headers || {})
137
+ }.compact
138
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
139
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
140
+ end
141
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
142
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
143
+ end
144
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
145
+ end
146
+ Ittybit::ConfirmationResponse.from_json(json_object: response.body)
147
+ end
148
+
149
+ # Updates specific fields of a media item by its ID. Only the fields provided in
150
+ # the request body will be updated.
151
+ #
152
+ # @param id [String]
153
+ # @param title [String] New title for the media item.
154
+ # @param metadata [Hash{String => Object}] New metadata object for the media item. This will replace the existing metadata.
155
+ # @param request_options [Ittybit::RequestOptions]
156
+ # @return [Ittybit::MediaResponse]
157
+ # @example
158
+ # api = Ittybit::Client.new(
159
+ # base_url: "https://api.example.com",
160
+ # environment: Ittybit::Environment::DEFAULT,
161
+ # token: "YOUR_AUTH_TOKEN"
162
+ # )
163
+ # api.media.update(id: "id")
164
+ def update(id:, title: nil, metadata: nil, request_options: nil)
165
+ response = @request_client.conn.patch do |req|
166
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
167
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
168
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
169
+ req.headers = {
170
+ **(req.headers || {}),
171
+ **@request_client.get_headers,
172
+ **(request_options&.additional_headers || {})
173
+ }.compact
174
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
175
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
176
+ end
177
+ req.body = { **(request_options&.additional_body_parameters || {}), title: title, metadata: metadata }.compact
178
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
179
+ end
180
+ Ittybit::MediaResponse.from_json(json_object: response.body)
181
+ end
182
+ end
183
+
184
+ class AsyncMediaClient
185
+ # @return [Ittybit::AsyncRequestClient]
186
+ attr_reader :request_client
187
+
188
+ # @param request_client [Ittybit::AsyncRequestClient]
189
+ # @return [Ittybit::AsyncMediaClient]
190
+ def initialize(request_client:)
191
+ @request_client = request_client
192
+ end
193
+
194
+ # Retrieves a list of all media for the current project
195
+ #
196
+ # @param limit [Integer] Number of media items to return per page.
197
+ # @param request_options [Ittybit::RequestOptions]
198
+ # @return [Ittybit::MediaListResponse]
199
+ # @example
200
+ # api = Ittybit::Client.new(
201
+ # base_url: "https://api.example.com",
202
+ # environment: Ittybit::Environment::DEFAULT,
203
+ # token: "YOUR_AUTH_TOKEN"
204
+ # )
205
+ # api.media.list
206
+ def list(limit: nil, request_options: nil)
207
+ Async do
208
+ response = @request_client.conn.get do |req|
209
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
210
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
211
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
212
+ req.headers = {
213
+ **(req.headers || {}),
214
+ **@request_client.get_headers,
215
+ **(request_options&.additional_headers || {})
216
+ }.compact
217
+ req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit }.compact
218
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
219
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
220
+ end
221
+ req.url "#{@request_client.get_url(request_options: request_options)}/media"
222
+ end
223
+ Ittybit::MediaListResponse.from_json(json_object: response.body)
224
+ end
225
+ end
226
+
227
+ # Creates a new media item from a URL or as an empty placeholder
228
+ #
229
+ # @param title [String] Title for the media
230
+ # @param metadata [Hash{String => Object}] Additional metadata for the media
231
+ # @param request_options [Ittybit::RequestOptions]
232
+ # @return [Ittybit::MediaResponse]
233
+ # @example
234
+ # api = Ittybit::Client.new(
235
+ # base_url: "https://api.example.com",
236
+ # environment: Ittybit::Environment::DEFAULT,
237
+ # token: "YOUR_AUTH_TOKEN"
238
+ # )
239
+ # api.media.create(metadata: { "credit": "gtv-videos-bucket" })
240
+ def create(title: nil, metadata: nil, request_options: nil)
241
+ Async do
242
+ response = @request_client.conn.post do |req|
243
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
244
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
245
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
246
+ req.headers = {
247
+ **(req.headers || {}),
248
+ **@request_client.get_headers,
249
+ **(request_options&.additional_headers || {})
250
+ }.compact
251
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
252
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
253
+ end
254
+ req.body = { **(request_options&.additional_body_parameters || {}), title: title, metadata: metadata }.compact
255
+ req.url "#{@request_client.get_url(request_options: request_options)}/media"
256
+ end
257
+ Ittybit::MediaResponse.from_json(json_object: response.body)
258
+ end
259
+ end
260
+
261
+ # Retrieves a specific media item by its ID
262
+ #
263
+ # @param id [String]
264
+ # @param request_options [Ittybit::RequestOptions]
265
+ # @return [Ittybit::MediaResponse]
266
+ # @example
267
+ # api = Ittybit::Client.new(
268
+ # base_url: "https://api.example.com",
269
+ # environment: Ittybit::Environment::DEFAULT,
270
+ # token: "YOUR_AUTH_TOKEN"
271
+ # )
272
+ # api.media.get(id: "id")
273
+ def get(id:, request_options: nil)
274
+ Async do
275
+ response = @request_client.conn.get do |req|
276
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
277
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
278
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
279
+ req.headers = {
280
+ **(req.headers || {}),
281
+ **@request_client.get_headers,
282
+ **(request_options&.additional_headers || {})
283
+ }.compact
284
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
285
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
286
+ end
287
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
288
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
289
+ end
290
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
291
+ end
292
+ Ittybit::MediaResponse.from_json(json_object: response.body)
293
+ end
294
+ end
295
+
296
+ # Deletes a specific media item by its ID
297
+ #
298
+ # @param id [String]
299
+ # @param request_options [Ittybit::RequestOptions]
300
+ # @return [Ittybit::ConfirmationResponse]
301
+ # @example
302
+ # api = Ittybit::Client.new(
303
+ # base_url: "https://api.example.com",
304
+ # environment: Ittybit::Environment::DEFAULT,
305
+ # token: "YOUR_AUTH_TOKEN"
306
+ # )
307
+ # api.media.delete(id: "id")
308
+ def delete(id:, request_options: nil)
309
+ Async do
310
+ response = @request_client.conn.delete do |req|
311
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
312
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
313
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
314
+ req.headers = {
315
+ **(req.headers || {}),
316
+ **@request_client.get_headers,
317
+ **(request_options&.additional_headers || {})
318
+ }.compact
319
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
320
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
321
+ end
322
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
323
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
324
+ end
325
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
326
+ end
327
+ Ittybit::ConfirmationResponse.from_json(json_object: response.body)
328
+ end
329
+ end
330
+
331
+ # Updates specific fields of a media item by its ID. Only the fields provided in
332
+ # the request body will be updated.
333
+ #
334
+ # @param id [String]
335
+ # @param title [String] New title for the media item.
336
+ # @param metadata [Hash{String => Object}] New metadata object for the media item. This will replace the existing metadata.
337
+ # @param request_options [Ittybit::RequestOptions]
338
+ # @return [Ittybit::MediaResponse]
339
+ # @example
340
+ # api = Ittybit::Client.new(
341
+ # base_url: "https://api.example.com",
342
+ # environment: Ittybit::Environment::DEFAULT,
343
+ # token: "YOUR_AUTH_TOKEN"
344
+ # )
345
+ # api.media.update(id: "id")
346
+ def update(id:, title: nil, metadata: nil, request_options: nil)
347
+ Async do
348
+ response = @request_client.conn.patch do |req|
349
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
350
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
351
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
352
+ req.headers = {
353
+ **(req.headers || {}),
354
+ **@request_client.get_headers,
355
+ **(request_options&.additional_headers || {})
356
+ }.compact
357
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
358
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
359
+ end
360
+ req.body = { **(request_options&.additional_body_parameters || {}), title: title, metadata: metadata }.compact
361
+ req.url "#{@request_client.get_url(request_options: request_options)}/media/#{id}"
362
+ end
363
+ Ittybit::MediaResponse.from_json(json_object: response.body)
364
+ end
365
+ end
366
+ end
367
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "types/signatures_create_request_method"
5
+ require_relative "../types/signature_response"
6
+ require "async"
7
+
8
+ module Ittybit
9
+ class SignaturesClient
10
+ # @return [Ittybit::RequestClient]
11
+ attr_reader :request_client
12
+
13
+ # @param request_client [Ittybit::RequestClient]
14
+ # @return [Ittybit::SignaturesClient]
15
+ def initialize(request_client:)
16
+ @request_client = request_client
17
+ end
18
+
19
+ # Creates a cryptographically signed URL that provides temporary and restricted
20
+ # access to a file. The URL can expire after a specified time and be limited to
21
+ # specific HTTP methods.
22
+ #
23
+ # @param filename [String] The name of the file to generate a signature for. Special characters will be
24
+ # sanitised.
25
+ # @param folder [String] Optional folder path where the file resides. Special characters will be
26
+ # sanitised.
27
+ # @param expiry [Long] Optional expiry time for the signature in seconds since epoch. Defaults to 60
28
+ # minutes from now. Must be a positive integer and in the future.
29
+ # @param method [Ittybit::Signatures::SignaturesCreateRequestMethod] Optional HTTP method allowed for the signed URL. Defaults to 'get'.
30
+ # @param request_options [Ittybit::RequestOptions]
31
+ # @return [Ittybit::SignatureResponse]
32
+ # @example
33
+ # api = Ittybit::Client.new(
34
+ # base_url: "https://api.example.com",
35
+ # environment: Ittybit::Environment::DEFAULT,
36
+ # token: "YOUR_AUTH_TOKEN"
37
+ # )
38
+ # api.signatures.create(
39
+ # filename: "video.mp4",
40
+ # folder: "private/user_123",
41
+ # expiry: 1735689600,
42
+ # method: GET
43
+ # )
44
+ def create(filename:, folder: nil, expiry: nil, method: nil, request_options: nil)
45
+ response = @request_client.conn.post do |req|
46
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
47
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
48
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
49
+ req.headers = {
50
+ **(req.headers || {}),
51
+ **@request_client.get_headers,
52
+ **(request_options&.additional_headers || {})
53
+ }.compact
54
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
55
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
56
+ end
57
+ req.body = {
58
+ **(request_options&.additional_body_parameters || {}),
59
+ filename: filename,
60
+ folder: folder,
61
+ expiry: expiry,
62
+ method: method
63
+ }.compact
64
+ req.url "#{@request_client.get_url(request_options: request_options)}/signatures"
65
+ end
66
+ Ittybit::SignatureResponse.from_json(json_object: response.body)
67
+ end
68
+ end
69
+
70
+ class AsyncSignaturesClient
71
+ # @return [Ittybit::AsyncRequestClient]
72
+ attr_reader :request_client
73
+
74
+ # @param request_client [Ittybit::AsyncRequestClient]
75
+ # @return [Ittybit::AsyncSignaturesClient]
76
+ def initialize(request_client:)
77
+ @request_client = request_client
78
+ end
79
+
80
+ # Creates a cryptographically signed URL that provides temporary and restricted
81
+ # access to a file. The URL can expire after a specified time and be limited to
82
+ # specific HTTP methods.
83
+ #
84
+ # @param filename [String] The name of the file to generate a signature for. Special characters will be
85
+ # sanitised.
86
+ # @param folder [String] Optional folder path where the file resides. Special characters will be
87
+ # sanitised.
88
+ # @param expiry [Long] Optional expiry time for the signature in seconds since epoch. Defaults to 60
89
+ # minutes from now. Must be a positive integer and in the future.
90
+ # @param method [Ittybit::Signatures::SignaturesCreateRequestMethod] Optional HTTP method allowed for the signed URL. Defaults to 'get'.
91
+ # @param request_options [Ittybit::RequestOptions]
92
+ # @return [Ittybit::SignatureResponse]
93
+ # @example
94
+ # api = Ittybit::Client.new(
95
+ # base_url: "https://api.example.com",
96
+ # environment: Ittybit::Environment::DEFAULT,
97
+ # token: "YOUR_AUTH_TOKEN"
98
+ # )
99
+ # api.signatures.create(
100
+ # filename: "video.mp4",
101
+ # folder: "private/user_123",
102
+ # expiry: 1735689600,
103
+ # method: GET
104
+ # )
105
+ def create(filename:, folder: nil, expiry: nil, method: nil, request_options: nil)
106
+ Async do
107
+ response = @request_client.conn.post do |req|
108
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
109
+ req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
110
+ req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
111
+ req.headers = {
112
+ **(req.headers || {}),
113
+ **@request_client.get_headers,
114
+ **(request_options&.additional_headers || {})
115
+ }.compact
116
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
117
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
118
+ end
119
+ req.body = {
120
+ **(request_options&.additional_body_parameters || {}),
121
+ filename: filename,
122
+ folder: folder,
123
+ expiry: expiry,
124
+ method: method
125
+ }.compact
126
+ req.url "#{@request_client.get_url(request_options: request_options)}/signatures"
127
+ end
128
+ Ittybit::SignatureResponse.from_json(json_object: response.body)
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ittybit
4
+ class Signatures
5
+ # Optional HTTP method allowed for the signed URL. Defaults to 'get'.
6
+ class SignaturesCreateRequestMethod
7
+ GET = "get"
8
+ PUT = "put"
9
+ POST = "post"
10
+ DELETE = "delete"
11
+ end
12
+ end
13
+ end