Class: BaseCradle::TimelineTasks

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/basecradle/items.rb

Overview

One timeline’s tasks: create here, or iterate (newest first).

Instance Method Summary collapse

Constructor Details

#initialize(client, timeline_uuid) ⇒ TimelineTasks

Returns a new instance of TimelineTasks.



204
205
206
207
# File 'lib/basecradle/items.rb', line 204

def initialize(client, timeline_uuid)
  @client = client
  @timeline_uuid = timeline_uuid
end

Instance Method Details

#create(instructions:, activate_at:) ⇒ Object

Schedule a task on this timeline. activate_at accepts a Time/DateTime (serialized to ISO 8601 — make it timezone-aware to be unambiguous) or an ISO 8601 string.



211
212
213
214
215
216
217
218
# File 'lib/basecradle/items.rb', line 211

def create(instructions:, activate_at:)
  activate_at = activate_at.iso8601 if activate_at.respond_to?(:iso8601)
  response = @client.request(
    "POST", "/timelines/#{@timeline_uuid}/tasks",
    json: { "task" => { "instructions" => instructions, "activate_at" => activate_at } }
  )
  Task.new(response.fetch("task"), client: @client)
end

#each(&block) ⇒ Object



220
221
222
# File 'lib/basecradle/items.rb', line 220

def each(&block)
  TasksResource.new(@client).filter(timeline: @timeline_uuid).each(&block)
end