Module: X::Resources::PostWrites
- Included in:
- Post
- Defined in:
- x-resources/lib/x/resources/post_writes.rb
Overview
Creating and deleting posts, and hiding replies, as the authenticated user
Internal to x-resources: the methods it gives Post, such as X::Post.create, are public API, but the module is only how they are shared, and which classes extend or include it can change within 1.x.
Instance Method Summary collapse
-
#create(text = nil, client:, reply_to: nil, quote: nil, media_ids: nil, community: nil, **params) ⇒ Post
Create a post as the authenticated user.
-
#delete(post, client:) ⇒ Boolean
Delete a post as the authenticated user.
-
#hide_reply(post, client:) ⇒ Boolean
Hide a reply to a post of the authenticated user.
-
#unhide_reply(post, client:) ⇒ Boolean
Show a reply that was hidden, as the author of the post it replies to.
Instance Method Details
#create(text = nil, client:, reply_to: nil, quote: nil, media_ids: nil, community: nil, **params) ⇒ Post
Create a post as the authenticated user
The API bills each post created, and bills a post whose text holds a URL more than ten times as much. A post needs no text when it has something else to show, such as media.
46 47 48 49 50 51 52 |
# File 'x-resources/lib/x/resources/post_writes.rb', line 46 def create(text = nil, client:, reply_to: nil, quote: nil, media_ids: nil, community: nil, **params) params = Utils.fields(params) fields = {text:, **params, **referenced(params, reply_to:, quote:, media_ids:, community:)}.compact raise ArgumentError, "a post needs text, or something else to show, such as media_ids" if fields.empty? created_from_response(client.post("tweets", fields, **Utils::JSON_CLASSES), "POST tweets", client:) end |
#delete(post, client:) ⇒ Boolean
Delete a post as the authenticated user
62 63 64 65 |
# File 'x-resources/lib/x/resources/post_writes.rb', line 62 def delete(post, client:) body = client.delete("tweets/#{Utils.id_of(post, Post)}", **Utils::JSON_CLASSES) Utils.written(body, "deleted").eql?(true) end |
#hide_reply(post, client:) ⇒ Boolean
Hide a reply to a post of the authenticated user
X still shows a hidden reply, behind a notice that its author was hidden.
77 78 79 |
# File 'x-resources/lib/x/resources/post_writes.rb', line 77 def hide_reply(post, client:) change_visibility(post, true, client:).eql?(true) end |
#unhide_reply(post, client:) ⇒ Boolean
Show a reply that was hidden, as the author of the post it replies to
89 90 91 |
# File 'x-resources/lib/x/resources/post_writes.rb', line 89 def unhide_reply(post, client:) change_visibility(post, false, client:).eql?(false) end |