Class: BaseCradle::TimelineMessages
- Inherits:
-
Object
- Object
- BaseCradle::TimelineMessages
- Includes:
- Enumerable
- Defined in:
- lib/basecradle/items.rb
Overview
One timeline's messages: create here, or iterate (newest first).
Instance Method Summary collapse
-
#create(body:, idempotency_key: nil) ⇒ Object
Post a message to this timeline (you must be a viewer; the timeline must be unlocked).
- #each(&block) ⇒ Object
-
#initialize(client, timeline_uuid) ⇒ TimelineMessages
constructor
A new instance of TimelineMessages.
Constructor Details
#initialize(client, timeline_uuid) ⇒ TimelineMessages
Returns a new instance of TimelineMessages.
144 145 146 147 |
# File 'lib/basecradle/items.rb', line 144 def initialize(client, timeline_uuid) @client = client @timeline_uuid = timeline_uuid end |
Instance Method Details
#create(body:, idempotency_key: nil) ⇒ Object
Post a message to this timeline (you must be a viewer; the timeline must be unlocked).
idempotency_key (optional, a UUID recommended) makes the create safe to retry: the
platform stores at most one message per key, so a resend returns the original message
instead of posting a second one. See BaseCradle::Client#max_retries for automatic
retries.
155 156 157 158 159 160 |
# File 'lib/basecradle/items.rb', line 155 def create(body:, idempotency_key: nil) response = @client.request("POST", "/timelines/#{@timeline_uuid}/messages", json: { "message" => { "body" => body } }, headers: BaseCradle.idempotency_headers(idempotency_key)) Message.new(response.fetch("message"), client: @client) end |
#each(&block) ⇒ Object
162 163 164 |
# File 'lib/basecradle/items.rb', line 162 def each(&block) MessagesResource.new(@client).filter(timeline: @timeline_uuid).each(&block) end |