Class: Tempest::Post
- Inherits:
-
Data
- Object
- Data
- Tempest::Post
- Defined in:
- lib/tempest/post.rb
Instance Attribute Summary collapse
-
#cid ⇒ Object
readonly
Returns the value of attribute cid.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#facets ⇒ Object
readonly
Returns the value of attribute facets.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#reply_parent_uri ⇒ Object
readonly
Returns the value of attribute reply_parent_uri.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.create(client, did:, text:, reply: nil, created_at: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ")) ⇒ Object
Compose a record for com.atproto.repo.createRecord (app.bsky.feed.post).
- .from_feed_view(post) ⇒ Object
Instance Method Summary collapse
-
#initialize(uri:, cid:, handle:, display_name:, text:, created_at:, facets: [], reply_parent_uri: nil) ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize(uri:, cid:, handle:, display_name:, text:, created_at:, facets: [], reply_parent_uri: nil) ⇒ Post
Returns a new instance of Post.
6 7 8 9 |
# File 'lib/tempest/post.rb', line 6 def initialize(uri:, cid:, handle:, display_name:, text:, created_at:, facets: [], reply_parent_uri: nil) super end |
Instance Attribute Details
#cid ⇒ Object (readonly)
Returns the value of attribute cid
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def cid @cid end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def created_at @created_at end |
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def display_name @display_name end |
#facets ⇒ Object (readonly)
Returns the value of attribute facets
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def facets @facets end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def handle @handle end |
#reply_parent_uri ⇒ Object (readonly)
Returns the value of attribute reply_parent_uri
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def reply_parent_uri @reply_parent_uri end |
#text ⇒ Object (readonly)
Returns the value of attribute text
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def text @text end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri
5 6 7 |
# File 'lib/tempest/post.rb', line 5 def uri @uri end |
Class Method Details
.create(client, did:, text:, reply: nil, created_at: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ")) ⇒ Object
Compose a record for com.atproto.repo.createRecord (app.bsky.feed.post). When ‘reply` is provided, both root and parent are set to the same target. This is correct for top-level replies and a known v1 trade-off for replies deeper in a thread (AppView will nest the reply under `parent` instead of the original conversation root).
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tempest/post.rb', line 34 def self.create(client, did:, text:, reply: nil, created_at: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ")) record = { "$type" => "app.bsky.feed.post", "text" => text, "createdAt" => created_at, } if reply ref = { "uri" => reply[:uri], "cid" => reply[:cid] } record["reply"] = { "root" => ref, "parent" => ref } end client.post( "com.atproto.repo.createRecord", body: { repo: did, collection: "app.bsky.feed.post", record: record, }, ) end |
.from_feed_view(post) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tempest/post.rb', line 11 def self.from_feed_view(post) post = post || {} = post["author"] || {} record = post["record"] || {} reply = record["reply"] reply_parent = reply.is_a?(Hash) ? reply["parent"] : nil new( uri: post["uri"], cid: post["cid"], handle: ["handle"], display_name: ["displayName"], text: record["text"], created_at: record["createdAt"], facets: Facet.parse(record["facets"]), reply_parent_uri: reply_parent.is_a?(Hash) ? reply_parent["uri"] : nil, ) end |