Class: X::Client
- Inherits:
-
Object
- Object
- X::Client
- Includes:
- CredentialHolder, Objects::API, Streaming::API, Uploader::API
- Defined in:
- x-core/lib/x/core/client.rb
Overview
A client for interacting with the X API
An endpoint is resolved against the base URL, and a request carries the client's credentials to the origin of that base URL alone: the scheme, host, and port it names. An endpoint that names a whole URL of another origin is sent there without them, as a redirect that leads to one is, so that the credentials of the API never reach a host they were not meant for; see X::Core::Origin.
The object_class of a request, of a stream, or of a client is one of two things. A class that JSON.parse builds each JSON object of the body into, as it does Hash, the default, OpenStruct, or a Struct, whose new takes no arguments and whose instances take each member with []=. Or anything that responds to from_response, which builds the result from the whole body instead, as the resource classes of x-objects do: it is passed the body parsed into Hashes and Arrays, whatever the array_class, and the client that made the request as client:, and what it returns is what the request returns, or, for a stream, what its block is passed for each object. Later versions of 1.x may pass it keyword arguments of their own, so it accepts the ones it does not read with **, as in def self.from_response(body, client:, **). The signatures of x-core state it as the X::_ResponseBuilder interface.
A client keeps its credentials, settings, and connection in an object of x-core it delegates to, and has no private methods but initialize, so that the methods x-objects and x-uploader include into it, which may be named as they like, take the place of none of its own.
Constant Summary collapse
- DEFAULT_BASE_URL =
Default base URL for the X API
"https://api.x.com/2/"- DEFAULT_ARRAY_CLASS =
Default class for parsing JSON arrays
Array- DEFAULT_OBJECT_CLASS =
Default class for parsing JSON objects
Hash- DEFAULT_OPEN_TIMEOUT =
Default timeout for opening connections in seconds
Connection::DEFAULT_OPEN_TIMEOUT
- DEFAULT_READ_TIMEOUT =
Default timeout for reading responses in seconds
Connection::DEFAULT_READ_TIMEOUT
- DEFAULT_WRITE_TIMEOUT =
Default timeout for writing requests in seconds
Connection::DEFAULT_WRITE_TIMEOUT
- DEFAULT_KEEP_ALIVE_TIMEOUT =
Default time to keep a connection open for the next request to the same host, in seconds
Connection::DEFAULT_KEEP_ALIVE_TIMEOUT
- DEFAULT_MAX_REDIRECTS =
Default maximum number of redirects to follow
RedirectHandler::DEFAULT_MAX_REDIRECTS
- DEFAULT_MAX_RATE_LIMIT_RETRIES =
Default maximum number of times to retry a request refused for a rate limit
RateLimitHandler::DEFAULT_MAX_RETRIES
- DEFAULT_MAX_RATE_LIMIT_WAIT =
Default maximum number of seconds to wait for a rate limit to reset
RateLimitHandler::DEFAULT_MAX_WAIT
- DEFAULT_MAX_RETRIES =
Default maximum number of times to send an idempotent request again after a failure
RetryHandler::DEFAULT_MAX_RETRIES
Instance Method Summary collapse
-
#add_alt_text(media, text) ⇒ UploadedMedia
included
from Uploader::API
Describe uploaded media with alt text, for people who cannot see it.
-
#add_list_member(list, user) ⇒ Boolean
included
from Objects::Actions::Lists
Add a member to a list as the authenticated user.
-
#add_subtitles(video, subtitles, language_code, **options) ⇒ UploadedMedia
included
from Uploader::API
Attach uploaded subtitles to an uploaded video.
-
#api_key ⇒ String?
The API key for OAuth 1.0a authentication.
-
#app_only ⇒ Client
A client that authenticates as the app, for the endpoints that refuse OAuth 1.0a.
-
#authenticator ⇒ Authenticator
The authenticator for API requests.
-
#await_media_processing(media, **options) ⇒ UploadedMedia
included
from Uploader::API
Wait until media has been processed, whether its processing succeeded or failed.
-
#await_media_processing!(media, **options) ⇒ UploadedMedia
included
from Uploader::API
Wait until media has been processed, raising if its processing failed.
-
#base_url ⇒ String
The base URL for API requests.
-
#block(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Block a user as the authenticated user.
-
#bookmark(post) ⇒ Boolean
included
from Objects::Actions::Engagement
Bookmark a post as the authenticated user.
-
#chunked_upload_media(media, **options) ⇒ UploadedMedia
included
from Uploader::API
Upload media in chunks, without waiting for it to be processed.
-
#client_id ⇒ String?
The OAuth 2.0 client ID.
-
#close ⇒ void
Close the connections the client keeps open between requests.
-
#count_all_posts(query, **params) ⇒ Integer
(also: #count_all_tweets)
included
from Objects::Lookups::Posts
Count the posts from the full archive that match a query, without reading them.
-
#count_all_posts_by_period(query, **params) ⇒ Hash{Range<Time> => Integer}
(also: #count_all_tweets_by_period)
included
from Objects::Lookups::Posts
Count the posts from the full archive that match a query, by period.
-
#count_posts(query, **params) ⇒ Integer
(also: #count_tweets)
included
from Objects::Lookups::Posts
Count the recent posts that match a query, without reading them.
-
#count_posts_by_period(query, **params) ⇒ Hash{Range<Time> => Integer}
(also: #count_tweets_by_period)
included
from Objects::Lookups::Posts
Count the posts from the last seven days that match a query, by period.
-
#create_direct_message(user, text = nil, **params) ⇒ DirectMessage
(also: #create_dm)
included
from Objects::Actions::DirectMessages
Send a direct message to a user as the authenticated user.
-
#create_direct_message_in(conversation, text = nil, **params) ⇒ DirectMessage
(also: #create_dm_in)
included
from Objects::Actions::DirectMessages
Send a direct message to a conversation as the authenticated user.
-
#create_group_direct_message(users, text = nil, **params) ⇒ DirectMessage
(also: #create_group_dm)
included
from Objects::Actions::DirectMessages
Start a group conversation, sending its first message as the authenticated user.
-
#create_list(name, **params) ⇒ List
included
from Objects::Actions::Lists
Create a list owned by the authenticated user.
-
#create_post(text = nil, **params) ⇒ Post
(also: #create_tweet)
included
from Objects::Actions::Posts
Create a post as the authenticated user.
-
#current_user(**params) {|problem| ... } ⇒ User?
included
from Objects::Lookups::Users
Look up the authenticated user.
-
#current_user!(**params) ⇒ User
included
from Objects::Lookups::Users
Look up the authenticated user, who must be found.
-
#current_user_id ⇒ Integer
included
from Objects::Lookups::Users
The identifier of the authenticated user, from an OAuth 1.0a token if possible.
-
#debug_output ⇒ IO, ...
The IO debug output is written to.
-
#default_array_class ⇒ Class
The default class for parsing JSON arrays.
-
#default_object_class ⇒ Class, #from_response
The default class for parsing JSON objects.
-
#delete(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class) {|response| ... } ⇒ Object?
Perform a DELETE request to the X API.
-
#delete_direct_message(message) ⇒ Boolean
(also: #delete_dm)
included
from Objects::Actions::DirectMessages
Delete a direct message event as the authenticated user.
-
#delete_list(list) ⇒ Boolean
included
from Objects::Actions::Lists
Delete a list as the authenticated user.
-
#delete_post(post) ⇒ Boolean
(also: #delete_tweet)
included
from Objects::Actions::Posts
Delete a post as the authenticated user.
-
#direct_messages(**params) ⇒ Cursor
(also: #dms)
included
from Objects::Lookups::DirectMessages
The most recent direct message events across every conversation.
-
#direct_messages_in(conversation, **params) ⇒ Cursor
(also: #dms_in)
included
from Objects::Lookups::DirectMessages
The direct message events of a conversation, one-to-one or group.
-
#direct_messages_with(user, **params) ⇒ Cursor
(also: #dms_with)
included
from Objects::Lookups::DirectMessages
The direct message events in the one-to-one conversation with a user.
-
#expires_at ⇒ Time?
The time the OAuth 2.0 access token expires, as last refreshed.
-
#find_all_media(media, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<X::Media>
included
from Objects::Lookups::Media
Look up media by media key, in parallel batches.
-
#find_all_posts(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Post>
(also: #find_all_tweets)
included
from Objects::Lookups::Posts
Look up many posts by identifier, in parallel batches.
-
#find_all_spaces(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>
included
from Objects::Lookups::Spaces
Look up many spaces by identifier, in parallel batches.
-
#find_all_spaces_by_creator(users, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>
included
from Objects::Lookups::Spaces
Look up the live and scheduled spaces many users created, in parallel batches.
-
#find_all_users(ids_or_usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
included
from Objects::Lookups::Users
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>
included
from Objects::Lookups::Users
Look up many users by identifier, in parallel batches.
-
#find_all_users_by_username(usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User>
included
from Objects::Lookups::Users
Look up many users by username, in parallel batches.
-
#find_community(id, **params) {|problem| ... } ⇒ Community?
included
from Objects::Lookups::Communities
Look up a community by identifier.
-
#find_community!(id, **params) ⇒ Community
included
from Objects::Lookups::Communities
Look up a community by identifier, which must exist.
-
#find_direct_message(id, **params) {|problem| ... } ⇒ DirectMessage?
(also: #find_dm)
included
from Objects::Lookups::DirectMessages
Look up a direct message event by identifier.
-
#find_direct_message!(id, **params) ⇒ DirectMessage
(also: #find_dm!)
included
from Objects::Lookups::DirectMessages
Look up a direct message event by identifier, which must exist.
-
#find_list(id, **params) {|problem| ... } ⇒ List?
included
from Objects::Lookups::Lists
Look up a list by identifier.
-
#find_list!(id, **params) ⇒ List
included
from Objects::Lookups::Lists
Look up a list by identifier, which must exist.
-
#find_media(media_key, **params) {|problem| ... } ⇒ X::Media?
included
from Objects::Lookups::Media
Look up media by media key.
-
#find_media!(media_key, **params) ⇒ X::Media
included
from Objects::Lookups::Media
Look up media by media key, raising if it is not found.
-
#find_post(id, **params) {|problem| ... } ⇒ Post?
(also: #find_tweet)
included
from Objects::Lookups::Posts
Look up a post by identifier.
-
#find_post!(id, **params) ⇒ Post
(also: #find_tweet!)
included
from Objects::Lookups::Posts
Look up a post by identifier, which must exist.
-
#find_space(id, **params) {|problem| ... } ⇒ Space?
included
from Objects::Lookups::Spaces
Look up a space by identifier.
-
#find_space!(id, **params) ⇒ Space
included
from Objects::Lookups::Spaces
Look up a space by identifier, which must exist.
-
#find_user(id_or_username, **params) {|problem| ... } ⇒ User?
included
from Objects::Lookups::Users
Look up a user by identifier or username.
-
#find_user!(id_or_username, **params) ⇒ User
included
from Objects::Lookups::Users
Look up a user by identifier or username, which must exist.
-
#find_user_by_id(id, **params) {|problem| ... } ⇒ User?
included
from Objects::Lookups::Users
Look up a user by identifier.
-
#find_user_by_id!(id, **params) ⇒ User
included
from Objects::Lookups::Users
Look up a user by identifier, which must exist.
-
#find_user_by_username(username, **params) {|problem| ... } ⇒ User?
included
from Objects::Lookups::Users
Look up a user by username.
-
#find_user_by_username!(username, **params) ⇒ User
included
from Objects::Lookups::Users
Look up a user by username, which must exist.
-
#follow(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Follow a user as the authenticated user.
-
#follow_list(list) ⇒ Boolean
included
from Objects::Actions::Lists
Follow a list as the authenticated user.
-
#get(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class) {|response| ... } ⇒ Object?
Perform a GET request to the X API.
-
#get_stream(endpoint, params: nil, headers: {}) {|http_response| ... } ⇒ Object
Open a GET request whose body the block reads as it arrives, as a stream's is.
-
#headers ⇒ Hash{String => String}
The headers sent with every request the client makes.
-
#hide_reply(post) ⇒ Boolean
included
from Objects::Actions::Posts
Hide a reply to a post of the authenticated user.
-
#initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, client_id: nil, client_secret: nil, refresh_token: nil, expires_at: nil, scopes: nil, authenticator: nil, base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT, debug_output: nil, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, headers: {}, max_redirects: DEFAULT_MAX_REDIRECTS, max_rate_limit_retries: DEFAULT_MAX_RATE_LIMIT_RETRIES, max_rate_limit_wait: DEFAULT_MAX_RATE_LIMIT_WAIT, max_retries: DEFAULT_MAX_RETRIES, on_response: nil, save_tokens: nil, load_tokens: nil) ⇒ Client
constructor
Initialize a new X API client.
-
#inspect ⇒ String
Summarize the client for the console without revealing credentials.
-
#keep_alive_timeout ⇒ Integer, Float
The time to keep an idle connection open for the next request, in seconds.
-
#like(post) ⇒ Boolean
included
from Objects::Actions::Engagement
Like a post as the authenticated user.
-
#load_tokens ⇒ #call?
The callable a refresh reads the stored OAuth2Tokens with.
-
#max_rate_limit_retries ⇒ Integer
The maximum number of times to retry a request refused for a rate limit.
-
#max_rate_limit_wait ⇒ Integer, Float
The maximum number of seconds to wait for a rate limit to reset.
-
#max_redirects ⇒ Integer
The maximum number of redirects to follow.
-
#max_retries ⇒ Integer
The maximum number of times to send an idempotent request again after a failure.
-
#memoize(key, value) ⇒ Object
Keep a value under a key, for the authenticator of the client.
-
#memoized(key) ⇒ Object?
The value kept under a key for the authenticator the client holds.
-
#mute(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Mute a user as the authenticated user.
-
#on_response ⇒ #call?
A callable passed an X::Response after each request and streamed object.
-
#open_timeout ⇒ Integer, ...
The timeout for opening connections, in seconds.
-
#personalized_trends(**params) ⇒ Array<PersonalizedTrend>
included
from Objects::Lookups::Trends
The topics trending for the authenticated user.
-
#pin_list(list) ⇒ Boolean
included
from Objects::Actions::Lists
Pin a list as the authenticated user.
-
#post(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown) {|response| ... } ⇒ Object?
Perform a POST request to the X API.
-
#post_usage(**params) {|problem| ... } ⇒ PostUsage?
included
from Objects::Lookups::Posts
Look up how many posts the app's project has read.
-
#post_usage!(**params) ⇒ PostUsage
included
from Objects::Lookups::Posts
Look up how many posts the app's project has read, which must be returned.
-
#put(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown) {|response| ... } ⇒ Object?
Perform a PUT request to the X API.
-
#read_timeout ⇒ Integer, ...
The timeout for reading responses, in seconds.
-
#remove_list_member(list, user) ⇒ Boolean
included
from Objects::Actions::Lists
Remove a member from a list as the authenticated user.
-
#repost(post) ⇒ Boolean
(also: #retweet)
included
from Objects::Actions::Engagement
Repost a post as the authenticated user.
-
#reposts_of_me(**params) ⇒ Cursor
(also: #retweets_of_me)
included
from Objects::Lookups::Posts
The posts of the authenticated user that other users have reposted.
-
#save_tokens ⇒ #call?
A callable passed the OAuth2Tokens of each refresh, and of an authorization.
-
#scopes ⇒ Array<String>?
The scopes X granted the OAuth 2.0 access token, as last refreshed.
-
#search_all_posts(query, **params) ⇒ Cursor
(also: #search_all_tweets)
included
from Objects::Lookups::Posts
Search the full archive of posts.
-
#search_communities(query, **params) ⇒ Cursor
included
from Objects::Lookups::Communities
Search communities.
-
#search_posts(query, **params) ⇒ Cursor
(also: #search_tweets)
included
from Objects::Lookups::Posts
Search recent posts.
-
#search_spaces(query, **params) ⇒ Cursor
included
from Objects::Lookups::Spaces
Search spaces by their titles.
-
#search_users(query, **params) ⇒ Cursor
included
from Objects::Lookups::Users
Search users.
-
#streaming(read_timeout: StreamingClient::DEFAULT_READ_TIMEOUT, max_reconnects: StreamingClient::DEFAULT_MAX_RECONNECTS, on_reconnect: nil) ⇒ StreamingClient
included
from Streaming::API
A client for the streaming endpoints, which reads and reconnects differently.
-
#trends(woeid, **params) ⇒ Array<Trend>
included
from Objects::Lookups::Trends
The topics trending in a place.
-
#unblock(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Unblock a user as the authenticated user.
-
#unbookmark(post) ⇒ Boolean
included
from Objects::Actions::Engagement
Remove a bookmark as the authenticated user.
-
#unfollow(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Unfollow a user as the authenticated user.
-
#unfollow_list(list) ⇒ Boolean
included
from Objects::Actions::Lists
Unfollow a list as the authenticated user.
-
#unhide_reply(post) ⇒ Boolean
included
from Objects::Actions::Posts
Show a reply to a post of the authenticated user after hiding it.
-
#unlike(post) ⇒ Boolean
included
from Objects::Actions::Engagement
Unlike a post as the authenticated user.
-
#unmute(user) ⇒ Boolean
included
from Objects::Actions::Relationships
Unmute a user as the authenticated user.
-
#unpin_list(list) ⇒ Boolean
included
from Objects::Actions::Lists
Unpin a list as the authenticated user.
-
#unrepost(post) ⇒ Boolean
(also: #unretweet)
included
from Objects::Actions::Engagement
Undo a repost as the authenticated user.
-
#update_list(list, **params) ⇒ Boolean
included
from Objects::Actions::Lists
Update the name, description, or privacy of a list as the authenticated user.
-
#update_profile_banner(media, **options) ⇒ void
included
from Uploader::API
Update the profile banner of the authenticated user from a file.
-
#update_profile_image(media) ⇒ void
included
from Uploader::API
Update the profile image of the authenticated user from a file.
-
#upload_media(media, **options) ⇒ UploadedMedia
included
from Uploader::API
Upload media and wait for it to be processed.
-
#with(**options) ⇒ Client
Copy the client with some of its options changed.
-
#with_retries { ... } ⇒ Object
Send a request that is safe to send twice again after a failure.
-
#write_timeout ⇒ Integer, ...
The timeout for writing requests, in seconds.
Constructor Details
#initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, client_id: nil, client_secret: nil, refresh_token: nil, expires_at: nil, scopes: nil, authenticator: nil, base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT, debug_output: nil, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, headers: {}, max_redirects: DEFAULT_MAX_REDIRECTS, max_rate_limit_retries: DEFAULT_MAX_RATE_LIMIT_RETRIES, max_rate_limit_wait: DEFAULT_MAX_RATE_LIMIT_WAIT, max_retries: DEFAULT_MAX_RETRIES, on_response: nil, save_tokens: nil, load_tokens: nil) ⇒ Client
Initialize a new X API client
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'x-core/lib/x/core/client.rb', line 364 def initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, client_id: nil, client_secret: nil, refresh_token: nil, expires_at: nil, scopes: nil, authenticator: nil, base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT, debug_output: nil, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, headers: {}, max_redirects: DEFAULT_MAX_REDIRECTS, max_rate_limit_retries: DEFAULT_MAX_RATE_LIMIT_RETRIES, max_rate_limit_wait: DEFAULT_MAX_RATE_LIMIT_WAIT, max_retries: DEFAULT_MAX_RETRIES, on_response: nil, save_tokens: nil, load_tokens: nil) @internals = ClientInternals.new(self, api_key:, api_key_secret:, access_token:, access_token_secret:, bearer_token:, client_id:, client_secret:, refresh_token:, expires_at:, scopes:, authenticator:, base_url:, open_timeout:, read_timeout:, write_timeout:, keep_alive_timeout:, debug_output:, proxy_url:, default_array_class:, default_object_class:, headers:, max_redirects:, max_rate_limit_retries:, max_rate_limit_wait:, max_retries:, on_response:, save_tokens:, load_tokens:) end |
Instance Method Details
#add_alt_text(media, text) ⇒ UploadedMedia Originally defined in module Uploader::API
Describe uploaded media with alt text, for people who cannot see it
#add_list_member(list, user) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Add a member to a list as the authenticated user
#add_subtitles(video, subtitles, language_code, **options) ⇒ UploadedMedia Originally defined in module Uploader::API
Attach uploaded subtitles to an uploaded video
#api_key ⇒ String?
The API key for OAuth 1.0a authentication
It is the one the client was given, or the one the OAuth1Authenticator or AppOnlyAuthenticator it was given in place of credentials holds.
166 |
# File 'x-core/lib/x/core/client.rb', line 166 def api_key = @internals.api_key_in_use |
#app_only ⇒ Client
A client that authenticates as the app, for the endpoints that refuse OAuth 1.0a
A client that authenticates as a user, signing with OAuth 1.0a or with OAuth 2.0, returns a copy that authenticates with the app's bearer token: the one it was given, or one it fetches with its API key and secret the first time. It returns the same copy, with the connections it keeps open, from then on, since the credentials and settings of a client never change; threads that ask for the copy together get one. A copy of the client made with #with that holds the same API key and secret, and the same base URL, builds a copy of its own, but sends the token the client fetched, or fetches, rather than fetch one of its own from the token endpoint, which X limits the rate of. A client with a bearer token or an API key and secret alone already authenticates as the app, and is returned as it is, as is one given an authenticator that authenticates as the app, or as no one. A client given an OAuth1Authenticator fetches the token with the API key and secret it signs with. A client that authenticates with OAuth 2.0 as a user and holds neither the app's bearer token nor its API key and secret, as a client given an OAuth2Authenticator holds neither, raises, rather than send the user's credentials to an endpoint that would refuse them with 403 Forbidden.
457 |
# File 'x-core/lib/x/core/client.rb', line 457 def app_only = @internals.app_only(self) |
#authenticator ⇒ Authenticator
The authenticator for API requests
It is the one the client was given, or else the one it built of its credentials. A client sends the token requests of an authenticator that makes them, an AppOnlyAuthenticator or an OAuth2Authenticator, over its own connection, with its proxy, timeouts, and debug output, whether it built the authenticator or was given it; an authenticator given to several clients sends them over the connection of the first. The refreshes of an OAuth2Authenticator reach the save_tokens of each client that authenticates with it, a refresh reads the stored tokens with the load_tokens of the authenticator, or else with the load_tokens of a client that authenticates with it, and the expires_at of the client is the authenticator's.
138 |
# File 'x-core/lib/x/core/client.rb', line 138 def authenticator = @internals.authenticator |
#await_media_processing(media, **options) ⇒ UploadedMedia Originally defined in module Uploader::API
Wait until media has been processed, whether its processing succeeded or failed
It returns the status X reported, which failed? tells a failure by, and ready? a success by, since a status in no state X documents is neither; await_media_processing! raises for either instead. Media that already says its processing succeeded or failed, or holds an upload response that names no processing, such as that of an image, is returned as it is, without a request.
#await_media_processing!(media, **options) ⇒ UploadedMedia Originally defined in module Uploader::API
Wait until media has been processed, raising if its processing failed
#base_url ⇒ String
The base URL for API requests
206 |
# File 'x-core/lib/x/core/client.rb', line 206 def base_url = @internals.base_url |
#block(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Block a user as the authenticated user
#bookmark(post) ⇒ Boolean Originally defined in module Objects::Actions::Engagement
Bookmark a post as the authenticated user
The bookmark endpoints take only OAuth 2.0 user context, which the object layer cannot route around, so a client that signs with OAuth 1.0a is refused.
#chunked_upload_media(media, **options) ⇒ UploadedMedia Originally defined in module Uploader::API
Upload media in chunks, without waiting for it to be processed
It is the way to upload media without waiting for X to process it: #upload_media waits for the processing of media X processes, such as a video, and this does not. It uploads the media as #upload_media uploads a video, a chunk at a time, but returns once the upload is finalized, so that the caller can go on while X processes a long video, and wait for it with #await_media_processing or #await_media_processing! when it needs it. It uploads in chunks whatever the media, an image as well, and adds no alt text. The chunks are sent by threads of their own, so the on_response of the client runs on those threads for the response of each chunk.
Each chunk is a request a rate limit can refuse, which fails the upload with ChunkedUploadFailed unless the client retries it, which it does only max_rate_limit_retries times, 0 by default, so upload a large video with a client whose max_rate_limit_retries is set, such as X::Client.new(max_rate_limit_retries: 3).
#client_id ⇒ String?
The OAuth 2.0 client ID
It is the one the client was given, or the one the OAuth2Authenticator it was given in place of credentials holds.
177 |
# File 'x-core/lib/x/core/client.rb', line 177 def client_id = @internals.client_id_in_use |
#close ⇒ void
This method returns an undefined value.
Close the connections the client keeps open between requests
A later request opens a connection again. A client and the copies made of it with #with that open their connections as it does share their connections, as the app-only copy of a client that signs with OAuth 1.0a does, so closing one closes them for all of them.
618 |
# File 'x-core/lib/x/core/client.rb', line 618 def close = @internals.close |
#count_all_posts(query, **params) ⇒ Integer Also known as: count_all_tweets Originally defined in module Objects::Lookups::Posts
Count the posts from the full archive that match a query, without reading them
The API bills a count by the request, not by the post, and refuses OAuth 1.0a for it, so a client that signs with OAuth 1.0a counts with a copy that authenticates as the app. A client signed in with OAuth 2.0 as a user that holds no credentials of the app counts as the user, which the full archive refuses with X::Forbidden.
#count_all_posts_by_period(query, **params) ⇒ Hash{Range<Time> => Integer} Also known as: count_all_tweets_by_period Originally defined in module Objects::Lookups::Posts
Count the posts from the full archive that match a query, by period
The API bills a count by the request, not by the post, and refuses OAuth 1.0a for it, so a client that signs with OAuth 1.0a counts with a copy that authenticates as the app. A client signed in with OAuth 2.0 as a user that holds no credentials of the app counts as the user, which the full archive refuses with X::Forbidden.
#count_posts(query, **params) ⇒ Integer Also known as: count_tweets Originally defined in module Objects::Lookups::Posts
Count the recent posts that match a query, without reading them
The API bills a count by the request, not by the post, and refuses OAuth 1.0a for it, so a client that signs with OAuth 1.0a counts with a copy that authenticates as the app.
#count_posts_by_period(query, **params) ⇒ Hash{Range<Time> => Integer} Also known as: count_tweets_by_period Originally defined in module Objects::Lookups::Posts
Count the posts from the last seven days that match a query, by period
The API bills a count by the request, not by the post, and refuses OAuth 1.0a for it, so a client that signs with OAuth 1.0a counts with a copy that authenticates as the app.
#create_direct_message(user, text = nil, **params) ⇒ DirectMessage Also known as: create_dm Originally defined in module Objects::Actions::DirectMessages
Send a direct message to a user as the authenticated user
#create_direct_message_in(conversation, text = nil, **params) ⇒ DirectMessage Also known as: create_dm_in Originally defined in module Objects::Actions::DirectMessages
Send a direct message to a conversation as the authenticated user
The conversation can be one-to-one or a group.
#create_group_direct_message(users, text = nil, **params) ⇒ DirectMessage Also known as: create_group_dm Originally defined in module Objects::Actions::DirectMessages
Start a group conversation, sending its first message as the authenticated user
#create_list(name, **params) ⇒ List Originally defined in module Objects::Actions::Lists
Create a list owned by the authenticated user
#create_post(text = nil, **params) ⇒ Post Also known as: create_tweet Originally defined in module Objects::Actions::Posts
Create a post as the authenticated user
The API bills each post created, and bills a post whose text holds a URL more than ten times as much. A post needs no text when it has something else to show, such as media.
#current_user(**params) {|problem| ... } ⇒ User? Originally defined in module Objects::Lookups::Users
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.
#current_user!(**params) ⇒ User Originally defined in module Objects::Lookups::Users
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.
#current_user_id ⇒ Integer Originally defined in module Objects::Lookups::Users
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.
#debug_output ⇒ IO, ...
The IO debug output is written to
94 |
# File 'x-core/lib/x/core/client.rb', line 94 def debug_output = @internals.debug_output |
#default_array_class ⇒ Class
The default class for parsing JSON arrays
213 |
# File 'x-core/lib/x/core/client.rb', line 213 def default_array_class = @internals.default_array_class |
#default_object_class ⇒ Class, #from_response
The default class for parsing JSON objects
It is a class that JSON.parse builds each JSON object into, or one that responds to from_response and builds the result from the whole body; see X::Client.
224 |
# File 'x-core/lib/x/core/client.rb', line 224 def default_object_class = @internals.default_object_class |
#delete(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class) {|response| ... } ⇒ Object?
Perform a DELETE request to the X API
567 568 569 |
# File 'x-core/lib/x/core/client.rb', line 567 def delete(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, &) @internals.execute_request(self, :delete, endpoint, params:, headers:, array_class:, object_class:, &) end |
#delete_direct_message(message) ⇒ Boolean Also known as: delete_dm Originally defined in module Objects::Actions::DirectMessages
Delete a direct message event as the authenticated user
#delete_list(list) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Delete a list as the authenticated user
#delete_post(post) ⇒ Boolean Also known as: delete_tweet Originally defined in module Objects::Actions::Posts
Delete a post as the authenticated user
#direct_messages(**params) ⇒ Cursor Also known as: dms Originally defined in module Objects::Lookups::DirectMessages
The most recent direct message events across every conversation
#direct_messages_in(conversation, **params) ⇒ Cursor Also known as: dms_in Originally defined in module Objects::Lookups::DirectMessages
The direct message events of a conversation, one-to-one or group
#direct_messages_with(user, **params) ⇒ Cursor Also known as: dms_with Originally defined in module Objects::Lookups::DirectMessages
The direct message events in the one-to-one conversation with a user
#expires_at ⇒ Time?
The time the OAuth 2.0 access token expires, as last refreshed
A refresh that reports no lifetime leaves it nil, rather than the time the client was given.
187 |
# File 'x-core/lib/x/core/client.rb', line 187 def expires_at = @internals.expires_at |
#find_all_media(media, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<X::Media> Originally defined in module Objects::Lookups::Media
Look up media by media key, in parallel batches
#find_all_posts(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Post> Also known as: find_all_tweets Originally defined in module Objects::Lookups::Posts
Look up many posts by identifier, in parallel batches
#find_all_spaces(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space> Originally defined in module Objects::Lookups::Spaces
Look up many spaces by identifier, in parallel batches
#find_all_spaces_by_creator(users, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space> Originally defined in module Objects::Lookups::Spaces
Look up the live and scheduled spaces many users created, in parallel batches
#find_all_users(ids_or_usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User> Originally defined in module Objects::Lookups::Users
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> Originally defined in module Objects::Lookups::Users
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.
#find_all_users_by_username(usernames, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<User> Originally defined in module Objects::Lookups::Users
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.
#find_community(id, **params) {|problem| ... } ⇒ Community? Originally defined in module Objects::Lookups::Communities
Look up a community by identifier
#find_community!(id, **params) ⇒ Community Originally defined in module Objects::Lookups::Communities
Look up a community by identifier, which must exist
#find_direct_message(id, **params) {|problem| ... } ⇒ DirectMessage? Also known as: find_dm Originally defined in module Objects::Lookups::DirectMessages
Look up a direct message event by identifier
#find_direct_message!(id, **params) ⇒ DirectMessage Also known as: find_dm! Originally defined in module Objects::Lookups::DirectMessages
Look up a direct message event by identifier, which must exist
#find_list(id, **params) {|problem| ... } ⇒ List? Originally defined in module Objects::Lookups::Lists
Look up a list by identifier
#find_list!(id, **params) ⇒ List Originally defined in module Objects::Lookups::Lists
Look up a list by identifier, which must exist
#find_media(media_key, **params) {|problem| ... } ⇒ X::Media? Originally defined in module Objects::Lookups::Media
Look up media by media key
A post refers to its media by media key, and so does what an upload returns, so this reads the photo, video, or animated GIF that was uploaded, with its URL and variants.
#find_media!(media_key, **params) ⇒ X::Media Originally defined in module Objects::Lookups::Media
Look up media by media key, raising if it is not found
#find_post(id, **params) {|problem| ... } ⇒ Post? Also known as: find_tweet Originally defined in module Objects::Lookups::Posts
Look up a post by identifier
#find_post!(id, **params) ⇒ Post Also known as: find_tweet! Originally defined in module Objects::Lookups::Posts
Look up a post by identifier, which must exist
#find_space(id, **params) {|problem| ... } ⇒ Space? Originally defined in module Objects::Lookups::Spaces
Look up a space by identifier
#find_space!(id, **params) ⇒ Space Originally defined in module Objects::Lookups::Spaces
Look up a space by identifier, which must exist
#find_user(id_or_username, **params) {|problem| ... } ⇒ User? Originally defined in module Objects::Lookups::Users
Look up a user by identifier or username
#find_user!(id_or_username, **params) ⇒ User Originally defined in module Objects::Lookups::Users
Look up a user by identifier or username, which must exist
#find_user_by_id(id, **params) {|problem| ... } ⇒ User? Originally defined in module Objects::Lookups::Users
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.
#find_user_by_id!(id, **params) ⇒ User Originally defined in module Objects::Lookups::Users
Look up a user by identifier, which must exist
#find_user_by_username(username, **params) {|problem| ... } ⇒ User? Originally defined in module Objects::Lookups::Users
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.
#find_user_by_username!(username, **params) ⇒ User Originally defined in module Objects::Lookups::Users
Look up a user by username, which must exist
#follow(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Follow a user as the authenticated user
A protected user must accept a request to follow them first, so for a protected user true means the follow was requested, not that the authenticated user follows them: until they accept it, the follows? of the authenticated user, as in client.current_user!.follows?(user), answers false.
#follow_list(list) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Follow a list as the authenticated user
#get(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class) {|response| ... } ⇒ Object?
Perform a GET request to the X API
482 483 484 |
# File 'x-core/lib/x/core/client.rb', line 482 def get(endpoint, params: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, &) @internals.execute_request(self, :get, endpoint, params:, headers:, array_class:, object_class:, &) end |
#get_stream(endpoint, params: nil, headers: {}) {|http_response| ... } ⇒ Object
Open a GET request whose body the block reads as it arrives, as a stream's is
The response is passed to the block before its body is read, so the block reads it, as with read_body, for as long as it likes; the connection is opened for the request alone, with the client's timeouts and proxy, and closed once the block returns. The request carries the client's credentials and headers as any other does, and a token the API rejects is refreshed, or fetched again, and the request sent once more, as for any other. It is neither retried after a failure nor redirected, and a response that is not successful raises the HTTPError of its status, once on_response is passed it, without reaching the block. Nothing the block reads is passed to on_response, since the body is the block's to read.
An error the block raises reaches the caller as it was raised, but for the errors of the socket the body is read from, such as the IOError of a body that could not be read, or a read that timed out, which raise a NetworkError that names the request, as a connection that fails does, so that a stream that dropped is told apart from a block that failed. An error is the socket's when read_body raises it from the socket, whatever its class, so the IOError or Errno::ENOSPC of a file the block writes to, in the block passed to read_body or out of it, is the block's, and raised as it was.
602 603 604 605 606 |
# File 'x-core/lib/x/core/client.rb', line 602 def get_stream(endpoint, params: nil, headers: {}, &) raise ArgumentError, "get_stream takes a block, which reads the body of the response" unless block_given? @internals.execute_stream(self, endpoint, params:, headers:, &) end |
#headers ⇒ Hash{String => String}
The headers sent with every request the client makes
They are defaults: a header of the same name passed to a request, or to a stream, is sent in place of the client's, and each of them is sent in place of a default of the gem, such as its User-Agent. A header that carries credentials, such as Authorization or Cookie, is dropped by a redirect to another origin, as one passed to a request is.
Each is named by a String, a header the client was given by a Symbol among them, so that a header is read by the name it is sent with, whichever the client was given: a Symbol names the header its underscores name with hyphens, as :user_agent names User-Agent.
252 |
# File 'x-core/lib/x/core/client.rb', line 252 def headers = @internals.headers |
#hide_reply(post) ⇒ Boolean Originally defined in module Objects::Actions::Posts
Hide a reply to a post of the authenticated user
#inspect ⇒ String
Summarize the client for the console without revealing credentials
397 398 399 |
# File 'x-core/lib/x/core/client.rb', line 397 def inspect "#<#{self.class} base_url=#{base_url.inspect} authenticator=#{authenticator.inspect}>" end |
#keep_alive_timeout ⇒ Integer, Float
The time to keep an idle connection open for the next request, in seconds
87 |
# File 'x-core/lib/x/core/client.rb', line 87 def keep_alive_timeout = @internals.keep_alive_timeout |
#like(post) ⇒ Boolean Originally defined in module Objects::Actions::Engagement
Like a post as the authenticated user
#load_tokens ⇒ #call?
The callable a refresh reads the stored OAuth2Tokens with
It returns the tokens in the storage that processes sharing the tokens of a user read, or nil for none there.
155 |
# File 'x-core/lib/x/core/client.rb', line 155 def load_tokens = @internals.load_tokens |
#max_rate_limit_retries ⇒ Integer
The maximum number of times to retry a request refused for a rate limit
108 |
# File 'x-core/lib/x/core/client.rb', line 108 def max_rate_limit_retries = @internals.max_rate_limit_retries |
#max_rate_limit_wait ⇒ Integer, Float
The maximum number of seconds to wait for a rate limit to reset
115 |
# File 'x-core/lib/x/core/client.rb', line 115 def max_rate_limit_wait = @internals.max_rate_limit_wait |
#max_redirects ⇒ Integer
The maximum number of redirects to follow
101 |
# File 'x-core/lib/x/core/client.rb', line 101 def max_redirects = @internals.max_redirects |
#max_retries ⇒ Integer
The maximum number of times to send an idempotent request again after a failure
122 |
# File 'x-core/lib/x/core/client.rb', line 122 def max_retries = @internals.max_retries |
#memoize(key, value) ⇒ Object
Keep a value under a key, for the authenticator of the client
For the gems that extend a client, and kept throughout 1.x, as #memoized is.
674 |
# File 'x-core/lib/x/core/client.rb', line 674 def memoize(key, value) = @internals.memoize(key, value) |
#memoized(key) ⇒ Object?
The value kept under a key for the authenticator the client holds
For the gems that extend a client, such as x-objects, which keeps the identifier of the user its credentials act for with it, so that a later x-core 1.x, which installs beside an earlier x-objects 1.x, keeps its name and behavior throughout 1.x. A value is read only while the client holds the authenticator it was kept with, and a client keeps values though it is frozen, which a copy made with dup or clone shares, and a copy made with #with does not.
662 |
# File 'x-core/lib/x/core/client.rb', line 662 def memoized(key) = @internals.memoized(key) |
#mute(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Mute a user as the authenticated user
#on_response ⇒ #call?
A callable passed an X::Response after each request and streamed object
It is the hook of every request a client makes. A block passed to a single request receives the same summary, after this, for code that reads the response of that one request rather than of all of them.
235 |
# File 'x-core/lib/x/core/client.rb', line 235 def on_response = @internals.on_response |
#open_timeout ⇒ Integer, ...
The timeout for opening connections, in seconds
66 |
# File 'x-core/lib/x/core/client.rb', line 66 def open_timeout = @internals.open_timeout |
#personalized_trends(**params) ⇒ Array<PersonalizedTrend> Originally defined in module Objects::Lookups::Trends
The topics trending for the authenticated user
#pin_list(list) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Pin a list as the authenticated user
#post(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown) {|response| ... } ⇒ Object?
Perform a POST request to the X API
513 514 515 516 |
# File 'x-core/lib/x/core/client.rb', line 513 def post(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown, &) # steep:ignore DifferentMethodParameterKind SettingValidator.no_unknown_keywords!(:post, endpoint, unknown) @internals.execute_request(self, :post, endpoint, body:, params:, form:, headers:, array_class:, object_class:, &) end |
#post_usage(**params) {|problem| ... } ⇒ PostUsage? Originally defined in module Objects::Lookups::Posts
Look up how many posts the app's project has read
The usage endpoint takes app-only authentication alone, so a client that signs with OAuth 1.0a looks it up with a copy that authenticates as the app, and one signed in with OAuth 2.0 as a user that holds no credentials of the app is refused with X::Forbidden.
A response that holds no usage returns nil, as current_user does for a users/me that holds no user, and passes the problems it reported to the block, if there is one.
#post_usage!(**params) ⇒ PostUsage Originally defined in module Objects::Lookups::Posts
Look up how many posts the app's project has read, which must be returned
#put(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown) {|response| ... } ⇒ Object?
Perform a PUT request to the X API
543 544 545 546 |
# File 'x-core/lib/x/core/client.rb', line 543 def put(endpoint, body = nil, params: nil, form: nil, headers: {}, array_class: default_array_class, object_class: default_object_class, **unknown, &) # steep:ignore DifferentMethodParameterKind SettingValidator.no_unknown_keywords!(:put, endpoint, unknown) @internals.execute_request(self, :put, endpoint, body:, params:, form:, headers:, array_class:, object_class:, &) end |
#read_timeout ⇒ Integer, ...
The timeout for reading responses, in seconds
73 |
# File 'x-core/lib/x/core/client.rb', line 73 def read_timeout = @internals.read_timeout |
#remove_list_member(list, user) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Remove a member from a list as the authenticated user
#repost(post) ⇒ Boolean Also known as: retweet Originally defined in module Objects::Actions::Engagement
Repost a post as the authenticated user
#reposts_of_me(**params) ⇒ Cursor Also known as: retweets_of_me Originally defined in module Objects::Lookups::Posts
The posts of the authenticated user that other users have reposted
#save_tokens ⇒ #call?
A callable passed the OAuth2Tokens of each refresh, and of an authorization
145 |
# File 'x-core/lib/x/core/client.rb', line 145 def save_tokens = @internals.save_tokens |
#scopes ⇒ Array<String>?
The scopes X granted the OAuth 2.0 access token, as last refreshed
A refresh that names no scopes keeps those the client held, as OAuth 2.0 has it. They are the ones the client was given, as the client of OAuth2Authorization#client is given those of the exchange of the code, until a refresh names others.
199 |
# File 'x-core/lib/x/core/client.rb', line 199 def scopes = @internals.scopes |
#search_all_posts(query, **params) ⇒ Cursor Also known as: search_all_tweets Originally defined in module Objects::Lookups::Posts
Search the full archive of posts
#search_communities(query, **params) ⇒ Cursor Originally defined in module Objects::Lookups::Communities
Search communities
#search_posts(query, **params) ⇒ Cursor Also known as: search_tweets Originally defined in module Objects::Lookups::Posts
Search recent posts
#search_spaces(query, **params) ⇒ Cursor Originally defined in module Objects::Lookups::Spaces
Search spaces by their titles
#search_users(query, **params) ⇒ Cursor Originally defined in module Objects::Lookups::Users
Search users
#streaming(read_timeout: StreamingClient::DEFAULT_READ_TIMEOUT, max_reconnects: StreamingClient::DEFAULT_MAX_RECONNECTS, on_reconnect: nil) ⇒ StreamingClient Originally defined in module Streaming::API
A client for the streaming endpoints, which reads and reconnects differently
Each call builds a new streaming client, so the one a stream runs on is kept in a variable to stop it with X::StreamingClient#stop, and a streaming client that was stopped, which stays stopped, is replaced by another.
#trends(woeid, **params) ⇒ Array<Trend> Originally defined in module Objects::Lookups::Trends
The topics trending in a place
#unblock(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Unblock a user as the authenticated user
#unbookmark(post) ⇒ Boolean Originally defined in module Objects::Actions::Engagement
Remove a bookmark as the authenticated user
The bookmark endpoints take only OAuth 2.0 user context, which the object layer cannot route around, so a client that signs with OAuth 1.0a is refused.
#unfollow(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Unfollow a user as the authenticated user
#unfollow_list(list) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Unfollow a list as the authenticated user
#unhide_reply(post) ⇒ Boolean Originally defined in module Objects::Actions::Posts
Show a reply to a post of the authenticated user after hiding it
#unlike(post) ⇒ Boolean Originally defined in module Objects::Actions::Engagement
Unlike a post as the authenticated user
#unmute(user) ⇒ Boolean Originally defined in module Objects::Actions::Relationships
Unmute a user as the authenticated user
#unpin_list(list) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Unpin a list as the authenticated user
#unrepost(post) ⇒ Boolean Also known as: unretweet Originally defined in module Objects::Actions::Engagement
Undo a repost as the authenticated user
#update_list(list, **params) ⇒ Boolean Originally defined in module Objects::Actions::Lists
Update the name, description, or privacy of a list as the authenticated user
#update_profile_banner(media, **options) ⇒ void Originally defined in module Uploader::API
This method returns an undefined value.
Update the profile banner of the authenticated user from a file
#update_profile_image(media) ⇒ void Originally defined in module Uploader::API
This method returns an undefined value.
Update the profile image of the authenticated user from a file
#upload_media(media, **options) ⇒ UploadedMedia Originally defined in module Uploader::API
Upload media and wait for it to be processed
The media is a path, or an IO open on it. Media given as a String or a Pathname is read from the file it names, and media given as a File or a Tempfile through that IO, a chunk at a time, so media of any size uploads without being held in memory; media given as any other IO, such as a StringIO, is read to its end and held.
A video or subtitles upload in chunks, which send their media type, as a single request does not. The media category is inferred from the bytes the media begins with, or else from the name of its file, unless media_category says what it is. The chunks are sent by threads of their own, so the on_response of the client runs on those threads for the response of each chunk.
An image, and a GIF that a single request takes, upload in a single request, which takes no chunks and no media type, so chunk_size, concurrency, and media_type are ignored for them: a chunk_size or a concurrency that is not valid still raises, but none is sent. Media given shared: true uploads in chunks, and uses all three.
Each chunk is a request a rate limit can refuse, which fails the upload with ChunkedUploadFailed unless the client retries it, which it does only max_rate_limit_retries times, 0 by default, so upload a large video with a client whose max_rate_limit_retries is set, such as X::Client.new(max_rate_limit_retries: 3).
#with(**options) ⇒ Client
Copy the client with some of its options changed
A copy that authenticates with OAuth 2.0 shares the client's authenticator, so that a refresh by either client reaches the other, since X accepts a refresh token once, unless it is given a client ID, client secret, access token, or refresh token that the authenticator does not hold. It shares it whatever the tokens are when it is built, so a refresh on another thread while it is built reaches it too. A refresh then passes the tokens it issued to the save_tokens of each client that shares it, once for each distinct callable. The expiration time and the scopes belong to the access token they share, so such a copy is refused either: give expires_at or scopes beside the access token and refresh token they describe.
A copy that does not share the OAuth 2.0 authenticator, since it is given credentials the authenticator does not hold or an authenticator of its own, holds tokens that may be another user's, so it holds none of the refresh token, expiration time, scopes, save_tokens, or load_tokens of the client unless it is given them.
A copy of a client that was given its authenticator shares it, unless the copy is given a credential, which replaces it, or an authenticator of its own, which also replaces the credentials of a client that holds them.
A copy that opens its connections as the client does, with the same timeouts, keep-alive timeout, debug output, and proxy, shares the connections the client keeps open, so that a copy made for each request, such as to send a header of its own, opens none of its own; #close on either closes them for both, and a later request of either opens them again.
434 |
# File 'x-core/lib/x/core/client.rb', line 434 def with(**) = @internals.with(self, ) # steep:ignore DifferentMethodParameterKind |
#with_retries { ... } ⇒ Object
Send a request that is safe to send twice again after a failure
The client sends no POST again, since the API may have acted on one whose answer never arrived, and sends no request again after its answer failed to arrive, since the API bills a read it answered whether or not the answer arrived. A request that is safe to send again anyway, such as the chunk of an upload, which names the segment it is appended at and which the API bills nothing for, is sent again with this: after a ServerError, a RequestTimeout, or a NetworkError of any kind, up to max_retries times, as the client sends an idempotent request again, after the wait a response asks for, or a backoff that doubles with each retry up to a minute and is cut short at random. A response that asks to be left alone for longer than a minute raises at once. The block must build its request anew each time, so that each attempt is signed afresh, as a request of the client is.
Wrap a request the client sends no more than once, such as a POST: the client sends a GET, a PUT, or a DELETE again itself, so one wrapped in this is sent max_retries times more for each time this sends it, nine times in all with the defaults, rather than three.
For the gems that extend a client, such as x-uploader, which sends each chunk of an upload with it, so that a later x-core 1.x, which installs beside an earlier x-uploader 1.x, keeps its name and behavior throughout 1.x.
647 |
# File 'x-core/lib/x/core/client.rb', line 647 def with_retries(&) = @internals.with_retries(&) |
#write_timeout ⇒ Integer, ...
The timeout for writing requests, in seconds
80 |
# File 'x-core/lib/x/core/client.rb', line 80 def write_timeout = @internals.write_timeout |