Module: X::Resources::Actions::Engagement

Included in:
X::Resources::API
Defined in:
x-resources/lib/x/resources/actions/engagement.rb

Overview

Like, repost, and bookmark posts as the authenticated user

Internal to x-resources: X::Resources::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

#bookmark(post) ⇒ Boolean

Bookmark a post as the authenticated user

Bookmarking a post takes only OAuth 2.0 user context, which the object layer cannot route around, so a client that signs with OAuth 1.0a is refused.

Examples:

Bookmark a post

client.bookmark("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user has bookmarked the post



72
73
74
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 72

def bookmark(post)
  RelationWrites.relate(self, current_user_id, "bookmarks", {"tweet_id" => Utils.id_of(post, Post)}, "bookmarked")
end

#like(post) ⇒ Boolean

Like a post as the authenticated user

Examples:

Like a post

client.like("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user now likes the post



25
26
27
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 25

def like(post)
  RelationWrites.relate(self, current_user_id, "likes", {"tweet_id" => Utils.id_of(post, Post)}, "liked")
end

#repost(post) ⇒ Boolean Also known as: retweet

Repost a post as the authenticated user

Examples:

Repost a post

client.repost("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user has reposted the post



47
48
49
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 47

def repost(post)
  RelationWrites.relate(self, current_user_id, "retweets", {"tweet_id" => Utils.id_of(post, Post)}, "retweeted")
end

#unbookmark(post) ⇒ Boolean

Remove a bookmark as the authenticated user

Removing a bookmark takes only OAuth 2.0 user context, which the object layer cannot route around, so a client that signs with OAuth 1.0a is refused.

Examples:

Remove a bookmark

client.unbookmark("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user no longer has the post bookmarked



86
87
88
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 86

def unbookmark(post)
  RelationWrites.unrelate(self, current_user_id, "bookmarks", Utils.id_of(post, Post), "bookmarked")
end

#unlike(post) ⇒ Boolean

Unlike a post as the authenticated user

Examples:

Unlike a post

client.unlike("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user no longer likes the post



36
37
38
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 36

def unlike(post)
  RelationWrites.unrelate(self, current_user_id, "likes", Utils.id_of(post, Post), "liked")
end

#unrepost(post) ⇒ Boolean Also known as: unretweet

Undo a repost as the authenticated user

Examples:

Undo a repost

client.unrepost("1234567890")

Parameters:

  • post (Post, String, Integer) —

    the post or its identifier

Returns:

  • (Boolean) —

    true if the authenticated user no longer reposts the post



58
59
60
# File 'x-resources/lib/x/resources/actions/engagement.rb', line 58

def unrepost(post)
  RelationWrites.unrelate(self, current_user_id, "retweets", Utils.id_of(post, Post), "retweeted")
end