Class: X::User
- Extended by:
- UserFinders
- Includes:
- Relationships, UserCollections
- Defined in:
- x-objects/lib/x/objects/user.rb
Overview
A user account
Constant Summary collapse
- FIELDS =
The user fields the object layer requests: every one that does not depend on who is authenticated, since a field that does, such as connection_status, would make every request fail for a client that cannot read it; the identifiers of referenced posts, and the affiliation, come with their expansions
A minor release may add to it the fields the API adds, so that a lookup asks for them too; see Resource#hydrated? for what that means for a resource looked up with a list of fields of its own.
%w[created_at description entities id is_identity_verified location name parody profile_banner_url profile_image_url protected public_metrics subscriber_count subscription_type url username verified verified_followers_count verified_type withheld].freeze
- EXPANSIONS =
Every expansion available on user endpoints
The API gives a user its affiliation when a request asks for the affiliation expansion, which it takes only at the endpoints whose data is users, so the users a post, a list, a space, or a direct message includes hold none, and hydrate looks them up with it.
A minor release may add to it the expansions the API adds, so that a lookup asks for them too; see Resource#hydrated? for what that means for a resource looked up with a list of expansions of its own.
%w[affiliation most_recent_post_id pinned_post_id].freeze
Instance Attribute Summary collapse
-
#affiliated_with_ids ⇒ Array<Integer>
readonly
The identifiers of the accounts this account is affiliated with.
-
#affiliation ⇒ Hash?
readonly
The organization the account is affiliated with, with its badge.
-
#connection_status ⇒ Array<String>?
readonly
How the authenticated user and this user are connected.
-
#created_at ⇒ Time?
readonly
The time when the account was created.
-
#description ⇒ String?
readonly
The profile description.
-
#entities ⇒ Hash?
readonly
The entities found in the description and URL.
-
#followers_count ⇒ Integer?
readonly
The number of followers.
-
#following_count ⇒ Integer?
readonly
The number of followed users.
-
#identity_verified ⇒ Boolean?
readonly
Whether the account's identity is verified, the is_identity_verified field.
-
#like_count ⇒ Integer?
readonly
The number of posts the user has liked.
-
#listed_count ⇒ Integer?
readonly
The number of lists the user is a member of.
-
#location ⇒ String?
readonly
The profile location.
-
#media_count ⇒ Integer?
readonly
The number of photos and videos the user has posted.
-
#most_recent_post_id ⇒ Integer?
readonly
The identifier of the most recent post.
-
#name ⇒ String?
readonly
The display name.
-
#parody ⇒ Boolean?
readonly
Whether the account labels itself a parody.
-
#pinned_post_id ⇒ Integer?
readonly
The identifier of the pinned post.
-
#post_count ⇒ Integer?
readonly
The number of posts.
-
#profile_banner_url ⇒ String?
readonly
The profile banner URL.
-
#profile_image_url ⇒ String?
readonly
The profile image URL.
-
#protected ⇒ Boolean?
readonly
Whether the account's posts are protected.
-
#public_metrics ⇒ Hash?
readonly
The public metrics.
-
#receives_your_dm ⇒ Boolean?
readonly
Whether the authenticated user can send this user a direct message.
-
#subscriber_count ⇒ Integer?
readonly
The number of users who subscribe to the user.
-
#subscribes_to_you ⇒ Boolean?
readonly
Whether this user subscribes to the authenticated user.
-
#subscription ⇒ Hash?
readonly
The subscription between this user and the authenticated user.
-
#subscription_type ⇒ String?
readonly
The subscription the account pays for: Basic, Premium, PremiumPlus, or None.
-
#url ⇒ String?
readonly
The URL of the website the profile links to.
-
#username ⇒ String?
readonly
The handle, without the leading at sign.
-
#verified ⇒ Boolean?
readonly
Whether the account is verified.
-
#verified_followers_count ⇒ Integer?
readonly
The number of verified followers.
-
#verified_type ⇒ String?
readonly
The verification type: blue, business, government, or none.
-
#withheld ⇒ Hash?
readonly
The withholding details.
Class Method Summary collapse
-
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every user field and expansion.
-
.search(query, client:, **params) ⇒ Cursor
Search users.
Instance Method Summary collapse
-
#affiliated_with ⇒ Array<User>
The accounts this account is affiliated with, such as its organization.
-
#identity_verified? ⇒ Boolean
Check whether the account's identity is verified.
-
#most_recent_post ⇒ Post?
(also: #most_recent_tweet)
The most recent post, from the includes or as a stub holding only its identifier.
-
#parody? ⇒ Boolean
Check whether the account labels itself a parody.
-
#permalink ⇒ String
The permalink of the profile, by username when known and by identifier otherwise.
-
#pinned_post ⇒ Post?
(also: #pinned_tweet)
The pinned post, from the includes or as a stub holding only its identifier.
-
#protected? ⇒ Boolean
Check whether the account's posts are protected.
-
#receives_your_dm? ⇒ Boolean
Check whether the authenticated user can send this user a direct message.
-
#subscribes_to_you? ⇒ Boolean
Check whether this user subscribes to the authenticated user.
-
#uri ⇒ URI::Generic
The permalink of the user as a URI.
-
#verified? ⇒ Boolean
Check whether the account is verified.
Constructor Details
This class inherits a constructor from X::Resource
Instance Attribute Details
#affiliated_with_ids ⇒ Array<Integer> (readonly)
The identifiers of the accounts this account is affiliated with
254 |
# File 'x-objects/lib/x/objects/user.rb', line 254 attribute :affiliated_with_ids, :integers, key: %w[affiliation user_id] |
#affiliation ⇒ Hash? (readonly)
The organization the account is affiliated with, with its badge
The API gives it for the affiliation expansion, which only the endpoints whose data is users take, so a user a post, a list, a space, or a direct message includes holds none until it is hydrated.
246 |
# File 'x-objects/lib/x/objects/user.rb', line 246 attribute :affiliation, :object |
#connection_status ⇒ Array<String>? (readonly)
How the authenticated user and this user are connected
No lookup asks for it unless user.fields names it, so a user looked up otherwise holds none, and reads nil rather than an empty list, which would say the users are not connected.
283 |
# File 'x-objects/lib/x/objects/user.rb', line 283 attribute :connection_status, :requested_list |
#created_at ⇒ Time? (readonly)
The time when the account was created
158 |
# File 'x-objects/lib/x/objects/user.rb', line 158 attribute :created_at, :time |
#description ⇒ String? (readonly)
The profile description
114 |
# File 'x-objects/lib/x/objects/user.rb', line 114 attribute :description |
#entities ⇒ Hash? (readonly)
The entities found in the description and URL
366 |
# File 'x-objects/lib/x/objects/user.rb', line 366 attribute :entities, :object |
#followers_count ⇒ Integer? (readonly)
The number of followers
390 |
# File 'x-objects/lib/x/objects/user.rb', line 390 attribute :followers_count, :integer, key: %w[public_metrics followers_count] |
#following_count ⇒ Integer? (readonly)
The number of followed users
398 |
# File 'x-objects/lib/x/objects/user.rb', line 398 attribute :following_count, :integer, key: %w[public_metrics following_count] |
#identity_verified ⇒ Boolean? (readonly)
Whether the account's identity is verified, the is_identity_verified field
219 |
# File 'x-objects/lib/x/objects/user.rb', line 219 attribute :identity_verified, :boolean, key: %w[is_identity_verified] |
#like_count ⇒ Integer? (readonly)
The number of posts the user has liked
422 |
# File 'x-objects/lib/x/objects/user.rb', line 422 attribute :like_count, :integer, key: %w[public_metrics like_count] |
#listed_count ⇒ Integer? (readonly)
The number of lists the user is a member of
414 |
# File 'x-objects/lib/x/objects/user.rb', line 414 attribute :listed_count, :integer, key: %w[public_metrics listed_count] |
#location ⇒ String? (readonly)
The profile location
122 |
# File 'x-objects/lib/x/objects/user.rb', line 122 attribute :location |
#media_count ⇒ Integer? (readonly)
The number of photos and videos the user has posted
430 |
# File 'x-objects/lib/x/objects/user.rb', line 430 attribute :media_count, :integer, key: %w[public_metrics media_count] |
#most_recent_post_id ⇒ Integer? (readonly)
The identifier of the most recent post
358 |
# File 'x-objects/lib/x/objects/user.rb', line 358 attribute :most_recent_post_id, :integer, tweet_key: %w[most_recent_tweet_id] |
#name ⇒ String? (readonly)
The display name
98 |
# File 'x-objects/lib/x/objects/user.rb', line 98 attribute :name |
#parody ⇒ Boolean? (readonly)
Whether the account labels itself a parody
204 |
# File 'x-objects/lib/x/objects/user.rb', line 204 attribute :parody, :boolean |
#pinned_post_id ⇒ Integer? (readonly)
The identifier of the pinned post
350 |
# File 'x-objects/lib/x/objects/user.rb', line 350 attribute :pinned_post_id, :integer, tweet_key: %w[pinned_tweet_id] |
#post_count ⇒ Integer? (readonly)
The number of posts
406 |
# File 'x-objects/lib/x/objects/user.rb', line 406 attribute :post_count, :integer, key: %w[public_metrics post_count], tweet_key: %w[public_metrics tweet_count] |
#profile_banner_url ⇒ String? (readonly)
The profile banner URL
150 |
# File 'x-objects/lib/x/objects/user.rb', line 150 attribute :profile_banner_url |
#profile_image_url ⇒ String? (readonly)
The profile image URL
142 |
# File 'x-objects/lib/x/objects/user.rb', line 142 attribute :profile_image_url |
#protected ⇒ Boolean? (readonly)
Whether the account's posts are protected
166 |
# File 'x-objects/lib/x/objects/user.rb', line 166 attribute :protected, :boolean |
#public_metrics ⇒ Hash? (readonly)
The public metrics
382 |
# File 'x-objects/lib/x/objects/user.rb', line 382 attribute :public_metrics, :object |
#receives_your_dm ⇒ Boolean? (readonly)
Whether the authenticated user can send this user a direct message
It depends on who is authenticated, so no lookup asks for it unless user.fields names it, and a user looked up otherwise holds none, and reads nil rather than false, which would say the user receives none.
296 |
# File 'x-objects/lib/x/objects/user.rb', line 296 attribute :receives_your_dm, :boolean |
#subscriber_count ⇒ Integer? (readonly)
The number of users who subscribe to the user
270 |
# File 'x-objects/lib/x/objects/user.rb', line 270 attribute :subscriber_count, :integer |
#subscribes_to_you ⇒ Boolean? (readonly)
Whether this user subscribes to the authenticated user
It depends on who is authenticated, so no lookup asks for it unless user.fields names it, and a user looked up otherwise holds none, and reads nil rather than false.
320 |
# File 'x-objects/lib/x/objects/user.rb', line 320 attribute :subscribes_to_you, :boolean |
#subscription ⇒ Hash? (readonly)
The subscription between this user and the authenticated user
It depends on who is authenticated, so no lookup asks for it unless user.fields names it, and a user looked up otherwise holds none.
342 |
# File 'x-objects/lib/x/objects/user.rb', line 342 attribute :subscription, :object |
#subscription_type ⇒ String? (readonly)
The subscription the account pays for: Basic, Premium, PremiumPlus, or None
234 |
# File 'x-objects/lib/x/objects/user.rb', line 234 attribute :subscription_type |
#url ⇒ String? (readonly)
The URL of the website the profile links to
The API gives it shortened, as a t.co link, and the URL it stands for is in the url entities of #entities. It is not the address of the profile on x.com, which #permalink and #uri read.
134 |
# File 'x-objects/lib/x/objects/user.rb', line 134 attribute :url |
#username ⇒ String? (readonly)
The handle, without the leading at sign
106 |
# File 'x-objects/lib/x/objects/user.rb', line 106 attribute :username |
#verified ⇒ Boolean? (readonly)
Whether the account is verified
181 |
# File 'x-objects/lib/x/objects/user.rb', line 181 attribute :verified, :boolean |
#verified_followers_count ⇒ Integer? (readonly)
The number of verified followers
262 |
# File 'x-objects/lib/x/objects/user.rb', line 262 attribute :verified_followers_count, :integer |
#verified_type ⇒ String? (readonly)
The verification type: blue, business, government, or none
196 |
# File 'x-objects/lib/x/objects/user.rb', line 196 attribute :verified_type |
#withheld ⇒ Hash? (readonly)
The withholding details
374 |
# File 'x-objects/lib/x/objects/user.rb', line 374 attribute :withheld, :object |
Class Method Details
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every user field and expansion
74 75 76 |
# File 'x-objects/lib/x/objects/user.rb', line 74 def default_params {"user.fields" => FIELDS, "post.fields" => Post::FIELDS, "expansions" => EXPANSIONS} end |
.search(query, client:, **params) ⇒ Cursor
Search users
87 88 89 |
# File 'x-objects/lib/x/objects/user.rb', line 87 def search(query, client:, **params) Cursor.__send__(:build, self, "users/search", client:, params: {query:, max_results: MAX_SEARCH_RESULTS}.merge(params), token_param: "next_token") end |
Instance Method Details
#affiliated_with ⇒ Array<User>
The accounts this account is affiliated with, such as its organization
They come from the includes, or as stubs holding their identifiers. They point the other way from affiliates, the accounts affiliated with this one.
457 |
# File 'x-objects/lib/x/objects/user.rb', line 457 references :affiliated_with, :User, key: %w[affiliation user_id] |
#identity_verified? ⇒ Boolean
Check whether the account's identity is verified
|
|
# File 'x-objects/lib/x/objects/user.rb', line 221
|
#most_recent_post ⇒ Post? Also known as: most_recent_tweet
The most recent post, from the includes or as a stub holding only its identifier
446 |
# File 'x-objects/lib/x/objects/user.rb', line 446 reference :most_recent_post, :Post, key: %w[most_recent_post_id], tweet_key: %w[most_recent_tweet_id] |
#parody? ⇒ Boolean
Check whether the account labels itself a parody
|
|
# File 'x-objects/lib/x/objects/user.rb', line 206
|
#permalink ⇒ String
The permalink of the profile, by username when known and by identifier otherwise
It is the address of the profile on x.com, not the website the profile links to, which #url reads.
473 |
# File 'x-objects/lib/x/objects/user.rb', line 473 def permalink = "https://x.com/#{username || "i/user/#{id}"}" |
#pinned_post ⇒ Post? Also known as: pinned_tweet
The pinned post, from the includes or as a stub holding only its identifier
438 |
# File 'x-objects/lib/x/objects/user.rb', line 438 reference :pinned_post, :Post, key: %w[pinned_post_id], tweet_key: %w[pinned_tweet_id] |
#protected? ⇒ Boolean
Check whether the account's posts are protected
|
|
# File 'x-objects/lib/x/objects/user.rb', line 168
|
#receives_your_dm? ⇒ Boolean
Check whether the authenticated user can send this user a direct message
A user whose response holds no receives_your_dm, such as one looked up without asking for it, is not known to receive one, and reads false.
|
|
# File 'x-objects/lib/x/objects/user.rb', line 298
|
#subscribes_to_you? ⇒ Boolean
Check whether this user subscribes to the authenticated user
A user whose response holds no subscribes_to_you, such as one looked up without asking for it, reads false.
|
|
# File 'x-objects/lib/x/objects/user.rb', line 322
|
#uri ⇒ URI::Generic
The permalink of the user as a URI
It is the address of the profile on x.com, not the website the profile links to, which #url reads.
483 |
# File 'x-objects/lib/x/objects/user.rb', line 483 def uri = URI(permalink) |
#verified? ⇒ Boolean
Check whether the account is verified
|
|
# File 'x-objects/lib/x/objects/user.rb', line 183
|