Class: Ittybit::AsyncAutomationsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ittybit/automations/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Ittybit::AsyncAutomationsClient

Parameters:



249
250
251
# File 'lib/ittybit/automations/client.rb', line 249

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientIttybit::AsyncRequestClient (readonly)



245
246
247
# File 'lib/ittybit/automations/client.rb', line 245

def request_client
  @request_client
end

Instance Method Details

#create(trigger:, workflow:, name: nil, description: nil, status: nil, request_options: nil) ⇒ Ittybit::Automations::AutomationsCreateResponse

Creates a new automation.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.automations.create(
  name: "My Example Automation",
  description: "This workflow will run whenever new media is created.",
  trigger: { kind: "event", event: "media.created" },
  workflow: [{ kind: DESCRIPTION }, { kind: IMAGE, ref: "thumbnail" }, { kind: VIDEO, next_: [{ kind: "subtitles", ref: "subtitles" }] }],
  status: ACTIVE
)

Parameters:

  • name (String) (defaults to: nil)
  • description (String) (defaults to: nil)
  • trigger (Hash)

    Request of type Ittybit::Automations::AutomationsCreateRequestTrigger, as a Hash

    • :kind (String)

    • :event (String)

  • workflow (Array<Hash>)

    Request of type Array<Ittybit::Automations::AutomationsCreateRequestWorkflowItem>, as a Hash

    • :kind (Ittybit::Automations::AutomationsCreateRequestWorkflowItemKind)

    • :ref (String)

    • :next_ (Array<Ittybit::Automations::AutomationsCreateRequestWorkflowItemNextItem>)

  • status (Ittybit::Automations::AutomationsCreateRequestStatus) (defaults to: nil)
  • request_options (Ittybit::RequestOptions) (defaults to: nil)

Returns:



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/ittybit/automations/client.rb', line 319

def create(trigger:, workflow:, name: nil, description: nil, status: nil, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        name: name,
        description: description,
        trigger: trigger,
        workflow: workflow,
        status: status
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/automations"
    end
    Ittybit::Automations::AutomationsCreateResponse.from_json(json_object: response.body)
  end
end

#delete(id:, request_options: nil) ⇒ Ittybit::Automations::AutomationsDeleteResponse

Permanently removes an automation from the system. This action cannot be undone.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.automations.delete(id: "auto_abcdefgh1234")

Parameters:

Returns:



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/ittybit/automations/client.rb', line 395

def delete(id:, request_options: nil)
  Async do
    response = @request_client.conn.delete do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
      req.headers = {
        **(req.headers || {}),
        **@request_client.get_headers,
        **(request_options&.additional_headers || {}),
        "Accept-Version": "2025-08-20"
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/automations/#{id}"
    end
    Ittybit::Automations::AutomationsDeleteResponse.from_json(json_object: response.body)
  end
end

#get(id:, request_options: nil) ⇒ Ittybit::Automations::AutomationsGetResponse

Retrieve the automation object for a automation with the given ID.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.automations.get(id: "auto_abcdefgh1234")

Parameters:

Returns:



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/ittybit/automations/client.rb', line 359

def get(id:, request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
      req.headers = {
        **(req.headers || {}),
        **@request_client.get_headers,
        **(request_options&.additional_headers || {}),
        "Accept-Version": "2025-08-20"
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/automations/#{id}"
    end
    Ittybit::Automations::AutomationsGetResponse.from_json(json_object: response.body)
  end
end

#list(page: nil, limit: nil, request_options: nil) ⇒ Array<Ittybit::Automations::AutomationsListResponseItem>

Retrieves a paginated list of all automations for the current project.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.automations.list

Parameters:

  • page (Integer) (defaults to: nil)
  • limit (Integer) (defaults to: nil)
  • request_options (Ittybit::RequestOptions) (defaults to: nil)

Returns:



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/ittybit/automations/client.rb', line 266

def list(page: nil, limit: nil, request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
      req.headers = {
        **(req.headers || {}),
        **@request_client.get_headers,
        **(request_options&.additional_headers || {}),
        "Accept-Version": "2025-08-20"
      }.compact
      req.params = { **(request_options&.additional_query_parameters || {}), "page": page, "limit": limit }.compact
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/automations"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      Ittybit::Automations::AutomationsListResponseItem.from_json(json_object: item)
    end
  end
end

#update(id:, name: nil, description: nil, trigger: nil, workflow: nil, status: nil, request_options: nil) ⇒ Ittybit::Automations::AutomationsUpdateResponse

Updates an automation’s ‘name`, `description`, `trigger`, `workflow`, or

`status`. Only the specified fields will be updated.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.automations.update(
  id: "auto_abcdefgh1234",
  name: "My Updated Automation",
  workflow: [{ kind: NSFW }, { kind: DESCRIPTION }, { kind: IMAGE, ref: "big_thumbnail" }, { kind: VIDEO, next_: [{ kind: "subtitle", ref: "subtitle" }] }],
  status: ACTIVE
)

Parameters:

  • id (String)
  • name (String) (defaults to: nil)
  • description (String) (defaults to: nil)
  • trigger (Hash) (defaults to: nil)

    Request of type Ittybit::Automations::AutomationsUpdateRequestTrigger, as a Hash

    • :kind (String)

    • :event (String)

  • workflow (Array<Hash>) (defaults to: nil)

    Request of type Array<Ittybit::Automations::AutomationsUpdateRequestWorkflowItem>, as a Hash

    • :kind (Ittybit::Automations::AutomationsUpdateRequestWorkflowItemKind)

    • :ref (String)

    • :next_ (Array<Ittybit::Automations::AutomationsUpdateRequestWorkflowItemNextItem>)

  • status (Ittybit::Automations::AutomationsUpdateRequestStatus) (defaults to: nil)
  • request_options (Ittybit::RequestOptions) (defaults to: nil)

Returns:



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/ittybit/automations/client.rb', line 447

def update(id:, name: nil, description: nil, trigger: nil, workflow: nil, status: nil, request_options: nil)
  Async do
    response = @request_client.conn.patch do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["ACCEPT_VERSION"] = request_options.version unless request_options&.version.nil?
      req.headers = {
        **(req.headers || {}),
        **@request_client.get_headers,
        **(request_options&.additional_headers || {}),
        "Accept-Version": "2025-08-20"
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        name: name,
        description: description,
        trigger: trigger,
        workflow: workflow,
        status: status
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/automations/#{id}"
    end
    Ittybit::Automations::AutomationsUpdateResponse.from_json(json_object: response.body)
  end
end