Module: X::Resources::PostCollections

Included in:
Post
Defined in:
x-resources/lib/x/resources/post_collections.rb

Overview

The collections of a post: the users who liked and reposted it, and its reposts and quotes, included into Post

Internal to x-resources: the methods it gives a post, such as liked_by, 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

Instance Method Details

#liked_by(**params) ⇒ Cursor

The users who liked this post

Examples:

Print the users who liked a post

post.liked_by.each { |user| puts user.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the users who liked the post



24
25
26
# File 'x-resources/lib/x/resources/post_collections.rb', line 24

def liked_by(**params)
  cursor(User, "tweets/#{id}/liking_users", max_results: MAX_RESULTS, **params)
end

#quotes(**params) ⇒ Cursor Also known as: quote_tweets

The posts quoting this post

Examples:

Print the quotes

post.quotes.each { |quote| puts quote.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the quotes



57
58
59
# File 'x-resources/lib/x/resources/post_collections.rb', line 57

def quotes(**params)
  cursor(Post, "tweets/#{id}/quote_tweets", max_results: MAX_RESULTS, min_results: 10, **params)
end

#reposted_by(**params) ⇒ Cursor Also known as: retweeted_by

The users who reposted this post

Examples:

Print the reposting users

post.reposted_by.each { |user| puts user.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the reposting users



35
36
37
# File 'x-resources/lib/x/resources/post_collections.rb', line 35

def reposted_by(**params)
  cursor(User, "tweets/#{id}/retweeted_by", max_results: MAX_RESULTS, **params)
end

#reposts(**params) ⇒ Cursor Also known as: retweets

The reposts of this post, each a post of its own by the user who reposted it

Examples:

Print when and by whom a post was reposted

post.reposts.each { |repost| puts "#{repost.author.username} at #{repost.created_at}" }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the reposts



46
47
48
# File 'x-resources/lib/x/resources/post_collections.rb', line 46

def reposts(**params)
  cursor(Post, "tweets/#{id}/retweets", max_results: MAX_RESULTS, **params)
end