Module: X::Objects::Actions::Posts

Included in:
X::Objects::API
Defined in:
x-objects/lib/x/objects/actions/posts.rb

Overview

Create and delete posts as the authenticated user

Internal to x-objects: X::Objects::API includes it, and its methods are public API of the client that includes API, but the module is only how they are grouped, and some of them need the methods of another, so include API rather than this module alone.

Instance Method Summary collapse

Instance Method Details

#create_post(text = nil, **params) ⇒ Post Also known as: create_tweet

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.

Examples:

Create a post

client.create_post("Hello, World!")

Post an image without text

client.create_post(media_ids: [media])

Reply to a post with an image

client.create_post("Hello!", reply_to: post, media_ids: [media["id"]])

Quote a post

client.create_post("Worth reading", quote: post)

Parameters:

  • text (String, nil) (defaults to: nil) —

    the text of the post, or nil for a post without text, such as one of media alone

  • params (Hash) —

    additional request body fields, such as reply_to, quote, media_ids, or poll

Returns:

  • (Post) —

    the created post, holding only its identifier and text

Raises:

  • (ArgumentError) —

    if the post has neither text nor any other field

  • (MissingResource) —

    if the API answers without the post



35
36
37
# File 'x-objects/lib/x/objects/actions/posts.rb', line 35

def create_post(text = nil, **params) # steep:ignore DifferentMethodParameterKind
  Post.create(text, client: self, **params)
end

#delete_post(post) ⇒ Boolean Also known as: delete_tweet

Delete a post as the authenticated user

Examples:

Delete a post

client.delete_post("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the post was deleted



46
47
48
# File 'x-objects/lib/x/objects/actions/posts.rb', line 46

def delete_post(post)
  Post.delete(post, client: self)
end

#hide_reply(post) ⇒ Boolean

Hide a reply to a post of the authenticated user

Examples:

Hide a reply

client.hide_reply("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the reply or its identifier

Returns:

  • (Boolean) —

    true if the reply is now hidden



57
58
59
# File 'x-objects/lib/x/objects/actions/posts.rb', line 57

def hide_reply(post)
  Post.hide_reply(post, client: self)
end

#unhide_reply(post) ⇒ Boolean

Show a reply to a post of the authenticated user after hiding it

Examples:

Show a hidden reply

client.unhide_reply("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the reply or its identifier

Returns:

  • (Boolean) —

    true if the reply is no longer hidden



68
69
70
# File 'x-objects/lib/x/objects/actions/posts.rb', line 68

def unhide_reply(post)
  Post.unhide_reply(post, client: self)
end