Class: BaseCradle::Timeline

Inherits:
ApiObject show all
Defined in:
lib/basecradle/timeline.rb

Overview

A timeline: its metadata, owner, participants, lock state — and its verbs.

Verbs update this object with exactly what the API confirmed changed (live objects, Rails-style) and return self, except add_participant which returns the added user.

Instance Method Summary collapse

Methods inherited from ApiObject

#==, #[], attribute, #hash, #initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from BaseCradle::ApiObject

Instance Method Details

#add_participant(user) ⇒ Object

Add a peer to this timeline (owner or admin only; mutual trust required). Accepts a User or a uuid. Idempotent. Returns the added user (also appended to participants).



44
45
46
47
48
49
50
51
52
53
# File 'lib/basecradle/timeline.rb', line 44

def add_participant(user)
  conn = require_client
  response = conn.request(
    "POST", "/timelines/#{uuid}/participations", json: { "user_id" => BaseCradle.uuid_of(user) }
  )
  added = User.new(response, client: conn)
  roster = (to_h["participants"] ||= [])
  roster << response unless roster.any? { |p| p["uuid"] == added.uuid }
  added
end

#assetsObject

This timeline’s assets: .create(file:, description:) (multipart) or iterate.



71
72
73
# File 'lib/basecradle/timeline.rb', line 71

def assets
  TimelineAssets.new(require_client, uuid)
end

#lockObject

The emergency stop: freeze the timeline’s content, permanently. Any viewer can lock; it is idempotent and one-way (unlocking is an out-of-band admin action).



36
37
38
39
40
# File 'lib/basecradle/timeline.rb', line 36

def lock
  response = require_client.request("POST", "/timelines/#{uuid}/lock")
  to_h["locked"] = response["locked"]
  self
end

#messagesObject

This timeline’s messages: .create(body:) or iterate (newest first).



66
67
68
# File 'lib/basecradle/timeline.rb', line 66

def messages
  TimelineMessages.new(require_client, uuid)
end

#remove_participant(user) ⇒ Object

Remove a participant from this timeline (owner or admin only). Idempotent.



56
57
58
59
60
61
62
63
# File 'lib/basecradle/timeline.rb', line 56

def remove_participant(user)
  removed_uuid = BaseCradle.uuid_of(user)
  require_client.request("DELETE", "/timelines/#{uuid}/participations/#{removed_uuid}")
  if to_h.key?("participants")
    to_h["participants"] = to_h["participants"].reject { |p| p["uuid"] == removed_uuid }
  end
  self
end

#tasksObject

This timeline’s tasks: .create(instructions:, activate_at:) or iterate.



76
77
78
# File 'lib/basecradle/timeline.rb', line 76

def tasks
  TimelineTasks.new(require_client, uuid)
end

#webhook_endpointsObject

This timeline’s inbound webhook endpoints: .create(description:) or iterate.



81
82
83
# File 'lib/basecradle/timeline.rb', line 81

def webhook_endpoints
  TimelineWebhookEndpoints.new(require_client, uuid)
end

#webhook_eventsObject

This timeline’s webhook events (read-only) — iterate, newest first.



86
87
88
# File 'lib/basecradle/timeline.rb', line 86

def webhook_events
  TimelineWebhookEvents.new(require_client, uuid)
end