Module: X::Objects::Lookups::Users
- Included in:
- API
- Defined in:
- x-objects/lib/x/objects/lookups/users.rb
Overview
Look up and search users, and the authenticated user, mixed into a client through API
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
-
#current_user(**params) {|problem| ... } ⇒ User?
Look up the authenticated user.
-
#current_user!(**params) ⇒ User
Look up the authenticated user, who must be found.
-
#current_user_id ⇒ Integer
The identifier of the authenticated user, from an OAuth 1.0a token if possible.
-
#find_all_users(ids_or_usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by identifier or username, in parallel batches.
-
#find_all_users_by_id(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by identifier, in parallel batches.
-
#find_all_users_by_username(usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by username, in parallel batches.
-
#find_user(id_or_username, **params) {|problem| ... } ⇒ User?
Look up a user by identifier or username.
-
#find_user!(id_or_username, **params) ⇒ User
Look up a user by identifier or username, which must exist.
-
#find_user_by_id(id, **params) {|problem| ... } ⇒ User?
Look up a user by identifier.
-
#find_user_by_id!(id, **params) ⇒ User
Look up a user by identifier, which must exist.
-
#find_user_by_username(username, **params) {|problem| ... } ⇒ User?
Look up a user by username.
-
#find_user_by_username!(username, **params) ⇒ User
Look up a user by username, which must exist.
-
#search_users(query, **params) ⇒ Cursor
Search users.
Instance Method Details
#current_user(**params) {|problem| ... } ⇒ User?
Look up the authenticated user
Each call looks the user up, as X::User.current does, so its counts and profile are as they are now. Keep the user it returns to read them again without a request.
173 174 175 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 173 def current_user(**params, &) User.current(client: self, **params, &)&.tap { |user| Utils.remember_user_id(self, user.id) } end |
#current_user!(**params) ⇒ User
Look up the authenticated user, who must be found
Each call looks the user up, as X::User.current! does, so its counts and profile are as they are now. Keep the user it returns to read them again without a request.
188 189 190 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 188 def current_user!(**params) User.current!(client: self, **params).tap { |user| Utils.remember_user_id(self, user.id) } end |
#current_user_id ⇒ Integer
The identifier of the authenticated user, from an OAuth 1.0a token if possible
An OAuth 1.0a access token begins with the identifier of its user, so a client that holds one needs no lookup. Any other client looks the user up the first time, unless current_user or current_user! already has, and keeps the identifier, which never changes, for as long as it holds the same authenticator, since a client whose credentials change authenticates as someone else. A frozen client keeps nothing, and looks the user up each time.
205 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 205 def current_user_id = Utils.authenticated_user_id(self) || Utils.remembered_user_id(self) || current_user!.id |
#find_all_users(ids_or_usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by identifier or username, in parallel batches
121 122 123 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 121 def find_all_users(ids_or_usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &) User.find_all(ids_or_usernames, client: self, concurrency:, **params, &) end |
#find_all_users_by_id(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by identifier, in parallel batches
A String of digits is an identifier, as it is read from a response or an environment variable, so this looks the accounts those numbers identify up, where find_all_users would take them for usernames.
158 159 160 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 158 def find_all_users_by_id(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &) User.find_all_by_id(ids, client: self, concurrency:, **params, &) end |
#find_all_users_by_username(usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
Look up many users by username, in parallel batches
It looks every value up as a username, Strings of digits as the accounts whose handles are those numbers, as find_all_users looks up any String, so code that reads values from elsewhere says which it means, as find_all_users_by_id does.
140 141 142 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 140 def find_all_users_by_username(usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &) User.find_all_by_username(usernames, client: self, concurrency:, **params, &) end |
#find_user(id_or_username, **params) {|problem| ... } ⇒ User?
Look up a user by identifier or username
27 28 29 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 27 def find_user(id_or_username, **params, &) User.find(id_or_username, client: self, **params, &) end |
#find_user!(id_or_username, **params) ⇒ User
Look up a user by identifier or username, which must exist
40 41 42 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 40 def find_user!(id_or_username, **params) User.find!(id_or_username, client: self, **params) end |
#find_user_by_id(id, **params) {|problem| ... } ⇒ User?
Look up a user by identifier
A String of digits is an identifier, as it is read from a response or an environment variable, so this looks the account that number identifies up, where find_user would take it for a username.
89 90 91 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 89 def find_user_by_id(id, **params, &) User.find_by_id(id, client: self, **params, &) end |
#find_user_by_id!(id, **params) ⇒ User
Look up a user by identifier, which must exist
103 104 105 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 103 def find_user_by_id!(id, **params) User.find_by_id!(id, client: self, **params) end |
#find_user_by_username(username, **params) {|problem| ... } ⇒ User?
Look up a user by username
It looks every value up as a username, a String of digits as the account whose handle is that number, as find_user looks up any String, so code that reads a value from elsewhere says which it means, as find_user_by_id does.
58 59 60 |
# File 'x-objects/lib/x/objects/lookups/users.rb', line 58 def find_user_by_username(username, **params, &) User.find_by_username(username, client: self, **params, &) end |