Skip to main content

LocalModeXClient

Struct LocalModeXClient 

Source
pub struct LocalModeXClient { /* private fields */ }
Expand description

X API client for local/scraper mode — no OAuth credentials required.

When a valid scraper_session.json exists in the data directory, operations are dispatched to the cookie-based transport. Otherwise, they return ScraperTransportUnavailable.

All transport calls are wrapped with retry_with_backoff so transient network errors and 5xx responses are retried automatically. Health is tracked in health and exposed via LocalModeXClient::health.

Implementations§

Source§

impl LocalModeXClient

Source

pub fn new(allow_mutations: bool) -> Self

Create a new local-mode client (no session — stub mode).

allow_mutations controls whether write operations are attempted (when true) or immediately rejected (when false).

Source

pub async fn with_session(allow_mutations: bool, data_dir: &Path) -> Self

Create a local-mode client with cookie-auth from a session file.

If the session file exists and is valid, operations will use the cookie transport. Otherwise, falls back to stub behavior.

Auto-detects GraphQL query IDs from X’s web client JS bundles at startup.

Source

pub async fn with_session_and_health( allow_mutations: bool, data_dir: &Path, health: ScraperHealth, ) -> Self

Create a local-mode client with cookie-auth and a shared health handle.

Use this instead of [with_session] when you want multiple ephemeral clients (e.g. one per HTTP request) to update the same health tracker held in AppState. Enables the /health endpoint to reflect real scraper health across the lifetime of the server process.

Source

pub fn health(&self) -> ScraperHealth

Return a clone of the shared health handle.

Callers (e.g. the health endpoint) can snapshot the current state without coupling to the client implementation.

Source

pub fn session_path(data_dir: &Path) -> PathBuf

Path to the session file in a given data directory.

Trait Implementations§

Source§

impl XApiClient for LocalModeXClient

Source§

fn get_me<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<User, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the authenticated user’s profile.
Source§

fn get_mentions<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _user_id: &'life1 str, _since_id: Option<&'life2 str>, _pagination_token: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<MentionResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Get mentions for the authenticated user. Read more
Source§

fn get_home_timeline<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get the authenticated user’s home timeline (reverse chronological).
Source§

fn get_bookmarks<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get the authenticated user’s bookmarks.
Source§

fn bookmark_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Bookmark a tweet.
Source§

fn unbookmark_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Remove a bookmark.
Source§

fn search_tweets<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, query: &'life1 str, max_results: u32, _since_id: Option<&'life2 str>, pagination_token: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Search recent tweets matching the given query. Read more
Source§

fn get_tweet<'life0, 'life1, 'async_trait>( &'life0 self, tweet_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Tweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single tweet by ID.
Source§

fn get_user_by_username<'life0, 'life1, 'async_trait>( &'life0 self, username: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<User, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Look up a user by their username.
Source§

fn get_user_tweets<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get recent tweets from a specific user.
Source§

fn get_user_by_id<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<User, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a user by their ID.
Source§

fn get_followers<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<UsersResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get followers of a user.
Source§

fn get_following<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<UsersResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get accounts a user is following.
Source§

fn get_users_by_ids<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_ids: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<UsersResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get multiple users by their IDs.
Source§

fn get_liked_tweets<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user_id: &'life1 str, max_results: u32, pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get tweets liked by a user.
Source§

fn get_tweet_liking_users<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tweet_id: &'life1 str, _max_results: u32, _pagination_token: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<UsersResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get users who liked a specific tweet.
Source§

fn raw_request<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, _method: &'life1 str, _url: &'life2 str, _query: Option<&'life3 [(String, String)]>, _body: Option<&'life4 str>, _headers: Option<&'life5 [(String, String)]>, ) -> Pin<Box<dyn Future<Output = Result<RawApiResponse, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

Execute a raw HTTP request against the X API. Read more
Source§

fn post_tweet<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<PostedTweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Post a new tweet.
Source§

fn reply_to_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, text: &'life1 str, in_reply_to_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<PostedTweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Reply to an existing tweet.
Source§

fn post_tweet_with_media<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, text: &'life1 str, _media_ids: &'life2 [String], ) -> Pin<Box<dyn Future<Output = Result<PostedTweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Post a new tweet with media attachments. Read more
Source§

fn reply_to_tweet_with_media<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, text: &'life1 str, in_reply_to_id: &'life2 str, _media_ids: &'life3 [String], ) -> Pin<Box<dyn Future<Output = Result<PostedTweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Reply to an existing tweet with media attachments. Read more
Source§

fn quote_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _text: &'life1 str, _quoted_tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<PostedTweet, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Post a quote tweet referencing another tweet.
Source§

fn like_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Like a tweet on behalf of the authenticated user.
Source§

fn unlike_tweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Unlike a tweet on behalf of the authenticated user.
Source§

fn follow_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, target_user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Follow a user on behalf of the authenticated user.
Source§

fn unfollow_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, target_user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Unfollow a user on behalf of the authenticated user.
Source§

fn retweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retweet a tweet on behalf of the authenticated user.
Source§

fn unretweet<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _user_id: &'life1 str, tweet_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Undo a retweet on behalf of the authenticated user.
Source§

fn delete_tweet<'life0, 'life1, 'async_trait>( &'life0 self, tweet_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a tweet by its ID.
Source§

fn upload_media<'life0, 'life1, 'async_trait>( &'life0 self, _data: &'life1 [u8], _media_type: MediaType, ) -> Pin<Box<dyn Future<Output = Result<MediaId, XApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Upload media to X API for attaching to tweets. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more