Module: X::Resources::UserCollections

Included in:
User
Defined in:
x-resources/lib/x/resources/user_collections.rb

Overview

The collections of a user: the users they follow and are followed by, their posts, timelines, bookmarks, and lists, included into User

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

#affiliates(**params) ⇒ Cursor

The users affiliated with this user, such as the people of an organization

They are the accounts whose affiliation names this user, which affiliated_with reads of each of them, so they point the other way from the affiliated_with of this user.

Examples:

Print the users affiliated with an organization

client.find_user!("X").affiliates.each { |user| puts user.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the users affiliated with this one



56
# File 'x-resources/lib/x/resources/user_collections.rb', line 56

def affiliates(**params) = cursor(User, "users/#{id}/affiliates", max_results: MAX_FOLLOW_RESULTS, **params)

#blocking(**params) ⇒ Cursor

The users this user blocks, which must be the authenticated user

Examples:

Print every blocked user

client.current_user!.blocking.each { |user| puts user.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the blocked users



65
66
67
# File 'x-resources/lib/x/resources/user_collections.rb', line 65

def blocking(**params)
  cursor(User, "users/#{id}/blocking", max_results: MAX_FOLLOW_RESULTS, **params)
end

#bookmark_folders(**params) ⇒ Cursor

The bookmark folders of the authenticated user

Examples:

Print the names of the bookmark folders

client.current_user!.bookmark_folders.each { |folder| puts folder.name }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the folders



158
159
160
# File 'x-resources/lib/x/resources/user_collections.rb', line 158

def bookmark_folders(**params)
  cursor(BookmarkFolder, "users/#{id}/bookmarks/folders", max_results: MAX_RESULTS, **params)
end

#bookmarks(folder: nil, **params) ⇒ Cursor

The posts bookmarked by the authenticated user, or those of one of their folders

The API gives the posts of a folder by their identifiers alone, and takes no fields for them, so they are stubs, which hydrate together, a lookup's worth at a time, as the stubs of any cursor do.

The bookmark endpoints take only the authentication of a user, OAuth 2.0 user context or OAuth 1.0a, so an app-only client is refused them; only bookmarking and unbookmarking a post refuse OAuth 1.0a too.

Examples:

Print the bookmarked posts

client.current_user!.bookmarks.each { |post| puts post.text }

Print the posts of the first bookmark folder

user = client.current_user!
if (folder = user.bookmark_folders.first)
  posts = user.bookmarks(folder:).to_a
  X::Post.hydrate_all(posts, client: client).each { |post| puts post.text }
end

Parameters:

  • folder (BookmarkFolder, String, Integer, nil) (defaults to: nil) —

    the folder or its identifier, or nil for every bookmark

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the bookmarked posts

Raises:

  • (ArgumentError) —

    if the folder is not a folder or the identifier of one, before a request



145
146
147
148
149
# File 'x-resources/lib/x/resources/user_collections.rb', line 145

def bookmarks(folder: nil, **params)
  return cursor(Post, "users/#{id}/bookmarks", max_results: MAX_RESULTS, **params) if folder.nil?

  cursor(Post, "users/#{id}/bookmarks/folders/#{Utils.id_of(folder, BookmarkFolder)}", max_results: MAX_RESULTS, ids_only: true, **params)
end

#followed_lists(**params) ⇒ Cursor

The lists this user follows

Examples:

Print the followed lists

user.followed_lists.each { |list| puts list.name }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the followed lists



191
192
193
# File 'x-resources/lib/x/resources/user_collections.rb', line 191

def followed_lists(**params)
  cursor(List, "users/#{id}/followed_lists", max_results: MAX_RESULTS, **params)
end

#followers(**params) ⇒ Cursor

The users following this user

Examples:

Print every follower

user.followers.each { |follower| puts follower.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the followers



31
32
33
# File 'x-resources/lib/x/resources/user_collections.rb', line 31

def followers(**params)
  cursor(User, "users/#{id}/followers", max_results: MAX_FOLLOW_RESULTS, total: :followers_count, **params)
end

#following(**params) ⇒ Cursor

The users this user follows

Examples:

Count the followed users

user.following.count

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the followed users



42
43
44
# File 'x-resources/lib/x/resources/user_collections.rb', line 42

def following(**params)
  cursor(User, "users/#{id}/following", max_results: MAX_FOLLOW_RESULTS, total: :following_count, **params)
end

#home_timeline(**params) ⇒ Cursor

The home timeline of this user, which must be the authenticated user

Examples:

Print the home timeline

client.current_user!.home_timeline.first(10).each { |post| puts post.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the posts by the users this user follows, newest first



98
99
100
# File 'x-resources/lib/x/resources/user_collections.rb', line 98

def home_timeline(**params)
  cursor(Post, "users/#{id}/timelines/reverse_chronological", max_results: MAX_RESULTS, **params)
end

#liked_posts(**params) ⇒ Cursor Also known as: liked_tweets

The posts liked by this user

Examples:

Print the most recently liked posts

user.liked_posts.first(10).each { |post| puts post.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the liked posts



120
121
122
# File 'x-resources/lib/x/resources/user_collections.rb', line 120

def liked_posts(**params)
  cursor(Post, "users/#{id}/liked_tweets", max_results: MAX_RESULTS, min_results: 5, **params)
end

#list_memberships(**params) ⇒ Cursor

The lists this user is a member of

Examples:

Print the list memberships

user.list_memberships.each { |list| puts list.name }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the list memberships



180
181
182
# File 'x-resources/lib/x/resources/user_collections.rb', line 180

def list_memberships(**params)
  cursor(List, "users/#{id}/list_memberships", max_results: MAX_RESULTS, total: :listed_count, **params)
end

#mentions(**params) ⇒ Cursor

The posts mentioning this user

Examples:

Print the most recent mentions

user.mentions.first(10).each { |post| puts post.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the mentions



109
110
111
# File 'x-resources/lib/x/resources/user_collections.rb', line 109

def mentions(**params)
  cursor(Post, "users/#{id}/mentions", max_results: MAX_RESULTS, min_results: 5, **params)
end

#muting(**params) ⇒ Cursor

The users this user mutes, which must be the authenticated user

Examples:

Print every muted user

client.current_user!.muting.each { |user| puts user.username }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the muted users



76
77
78
# File 'x-resources/lib/x/resources/user_collections.rb', line 76

def muting(**params)
  cursor(User, "users/#{id}/muting", max_results: MAX_FOLLOW_RESULTS, **params)
end

#owned_lists(**params) ⇒ Cursor

The lists owned by this user

Examples:

Print the owned lists

user.owned_lists.each { |list| puts list.name }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the owned lists



169
170
171
# File 'x-resources/lib/x/resources/user_collections.rb', line 169

def owned_lists(**params)
  cursor(List, "users/#{id}/owned_lists", max_results: MAX_RESULTS, **params)
end

#pinned_lists(**params) ⇒ Cursor

The lists this user has pinned

The API returns them in one response, without pages.

Examples:

Print the pinned lists

client.current_user!.pinned_lists.each { |list| puts list.name }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the pinned lists



204
205
206
# File 'x-resources/lib/x/resources/user_collections.rb', line 204

def pinned_lists(**params)
  cursor(List, "users/#{id}/pinned_lists", max_results: nil, **params)
end

#posts(**params) ⇒ Cursor Also known as: tweets

The posts by this user

Examples:

Print the most recent posts

user.posts.first(10).each { |post| puts post.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the posts



87
88
89
# File 'x-resources/lib/x/resources/user_collections.rb', line 87

def posts(**params)
  cursor(Post, "users/#{id}/tweets", max_results: MAX_RESULTS, min_results: 5, **params)
end