Class: Ittybit::AsyncTasksClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Ittybit::AsyncTasksClient

Parameters:



132
133
134
# File 'lib/ittybit/tasks/client.rb', line 132

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientIttybit::AsyncRequestClient (readonly)



128
129
130
# File 'lib/ittybit/tasks/client.rb', line 128

def request_client
  @request_client
end

Instance Method Details

#create(request: nil, request_options: nil) ⇒ Ittybit::Tasks::TasksCreateResponse

Creates a new task item. See [Tasks](/docs/tasks) for detailed coverage of all

available props and values.

Examples:

api = Ittybit::Client.new(
  base_url: "https://api.example.com",
  environment: Ittybit::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.tasks.create(request: {"file_id":"file_abcdefgh1234","kind":"image","width":320,"format":"png","ref":"thumbnail"})

Parameters:

Returns:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/ittybit/tasks/client.rb', line 188

def create(request: 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 || {}),
        "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 || {}), **(request_options&.additional_body_parameters || {}) }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/tasks"
    end
    Ittybit::Tasks::TasksCreateResponse.from_json(json_object: response.body)
  end
end

#get(id:, request_options: nil) ⇒ Ittybit::Tasks::TasksGetResponse

Retrieves the task object for a task 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.tasks.get(id: "task_abcdefgh1234")

Parameters:

Returns:



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/ittybit/tasks/client.rb', line 222

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)}/tasks/#{id}"
    end
    Ittybit::Tasks::TasksGetResponse.from_json(json_object: response.body)
  end
end

#list(page: nil, limit: nil, request_options: nil) ⇒ Array<Ittybit::Tasks::TasksListResponseItem>

Retrieves a paginated list of all tasks 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.tasks.list

Parameters:

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

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/ittybit/tasks/client.rb', line 149

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)}/tasks"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      Ittybit::Tasks::TasksListResponseItem.from_json(json_object: item)
    end
  end
end