Class: Ittybit::AutomationsClient

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::AutomationsClient

Parameters:



25
26
27
# File 'lib/ittybit/automations/client.rb', line 25

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientIttybit::RequestClient (readonly)



21
22
23
# File 'lib/ittybit/automations/client.rb', line 21

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:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ittybit/automations/client.rb', line 93

def create(trigger:, workflow:, name: nil, description: nil, status: nil, request_options: nil)
  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

#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:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ittybit/automations/client.rb', line 165

def delete(id:, request_options: nil)
  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

#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:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ittybit/automations/client.rb', line 131

def get(id:, request_options: nil)
  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

#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:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ittybit/automations/client.rb', line 42

def list(page: nil, limit: nil, request_options: nil)
  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

#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:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/ittybit/automations/client.rb', line 215

def update(id:, name: nil, description: nil, trigger: nil, workflow: nil, status: nil, request_options: nil)
  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