Class: XTwitterScraper::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- XTwitterScraper::Client
- Defined in:
- lib/x_twitter_scraper/client.rb,
sig/x_twitter_scraper/client.rbs
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS, Internal::Transport::BaseClient::XTwitterScraper
Instance Attribute Summary collapse
-
#account ⇒ XTwitterScraper::Resources::Account
readonly
Account info and settings.
- #api_key ⇒ String? readonly
-
#bearer_token ⇒ String?
readonly
OAuth 2.1 access token.
-
#compose ⇒ XTwitterScraper::Resources::Compose
readonly
AI tweet composition, drafts, writing styles, and radar.
-
#credits ⇒ XTwitterScraper::Resources::Credits
readonly
Subscription, billing, and credits.
-
#drafts ⇒ XTwitterScraper::Resources::Drafts
readonly
AI tweet composition, drafts, writing styles, and radar.
-
#draws ⇒ XTwitterScraper::Resources::Draws
readonly
Giveaway draws from tweet replies.
-
#events ⇒ XTwitterScraper::Resources::Events
readonly
Activity events from monitored accounts.
-
#extractions ⇒ XTwitterScraper::Resources::Extractions
readonly
Bulk data extraction (23 tool types).
-
#guest_wallets ⇒ XTwitterScraper::Resources::GuestWallets
readonly
Accountless prepaid access for paid read endpoints.
-
#monitors ⇒ XTwitterScraper::Resources::Monitors
readonly
X account monitoring with 1-second checks.
-
#radar ⇒ XTwitterScraper::Resources::Radar
readonly
AI tweet composition, drafts, writing styles, and radar.
-
#styles ⇒ XTwitterScraper::Resources::Styles
readonly
AI tweet composition, drafts, writing styles, and radar.
-
#subscribe ⇒ XTwitterScraper::Resources::Subscribe
readonly
Subscription, billing, and credits.
- #support ⇒ XTwitterScraper::Resources::Support readonly
-
#trends ⇒ XTwitterScraper::Resources::Trends
readonly
Trending topics and hashtags by region.
-
#webhooks ⇒ XTwitterScraper::Resources::Webhooks
readonly
Webhook endpoint management and delivery.
- #x ⇒ XTwitterScraper::Resources::X readonly
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(api_key: ENV["X_TWITTER_SCRAPER_API_KEY"], bearer_token: ENV["X_TWITTER_SCRAPER_BEARER_TOKEN"], base_url: ENV["X_TWITTER_SCRAPER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: ENV["X_TWITTER_SCRAPER_API_KEY"], bearer_token: ENV["X_TWITTER_SCRAPER_BEARER_TOKEN"], base_url: ENV["X_TWITTER_SCRAPER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
Creates and returns a new client for interacting with the API.
"https://api.example.com/v2/". Defaults to ENV["X_TWITTER_SCRAPER_BASE_URL"]
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/x_twitter_scraper/client.rb', line 132 def initialize( api_key: ENV["X_TWITTER_SCRAPER_API_KEY"], bearer_token: ENV["X_TWITTER_SCRAPER_BEARER_TOKEN"], base_url: ENV["X_TWITTER_SCRAPER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY ) base_url ||= "https://xquik.com/api/v1" headers = {} custom_headers_env = ENV["X_TWITTER_SCRAPER_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key = api_key&.to_s @bearer_token = bearer_token&.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers ) @account = XTwitterScraper::Resources::Account.new(client: self) @subscribe = XTwitterScraper::Resources::Subscribe.new(client: self) @compose = XTwitterScraper::Resources::Compose.new(client: self) @drafts = XTwitterScraper::Resources::Drafts.new(client: self) @styles = XTwitterScraper::Resources::Styles.new(client: self) @radar = XTwitterScraper::Resources::Radar.new(client: self) @monitors = XTwitterScraper::Resources::Monitors.new(client: self) @events = XTwitterScraper::Resources::Events.new(client: self) @extractions = XTwitterScraper::Resources::Extractions.new(client: self) @draws = XTwitterScraper::Resources::Draws.new(client: self) @webhooks = XTwitterScraper::Resources::Webhooks.new(client: self) @x = XTwitterScraper::Resources::X.new(client: self) @trends = XTwitterScraper::Resources::Trends.new(client: self) @support = XTwitterScraper::Resources::Support.new(client: self) @credits = XTwitterScraper::Resources::Credits.new(client: self) @guest_wallets = XTwitterScraper::Resources::GuestWallets.new(client: self) end |
Instance Attribute Details
#account ⇒ XTwitterScraper::Resources::Account (readonly)
Account info and settings
31 32 33 |
# File 'lib/x_twitter_scraper/client.rb', line 31 def account @account end |
#api_key ⇒ String? (readonly)
23 24 25 |
# File 'lib/x_twitter_scraper/client.rb', line 23 def api_key @api_key end |
#bearer_token ⇒ String? (readonly)
OAuth 2.1 access token
27 28 29 |
# File 'lib/x_twitter_scraper/client.rb', line 27 def bearer_token @bearer_token end |
#compose ⇒ XTwitterScraper::Resources::Compose (readonly)
AI tweet composition, drafts, writing styles, and radar
39 40 41 |
# File 'lib/x_twitter_scraper/client.rb', line 39 def compose @compose end |
#credits ⇒ XTwitterScraper::Resources::Credits (readonly)
Subscription, billing, and credits
85 86 87 |
# File 'lib/x_twitter_scraper/client.rb', line 85 def credits @credits end |
#drafts ⇒ XTwitterScraper::Resources::Drafts (readonly)
AI tweet composition, drafts, writing styles, and radar
43 44 45 |
# File 'lib/x_twitter_scraper/client.rb', line 43 def drafts @drafts end |
#draws ⇒ XTwitterScraper::Resources::Draws (readonly)
Giveaway draws from tweet replies
67 68 69 |
# File 'lib/x_twitter_scraper/client.rb', line 67 def draws @draws end |
#events ⇒ XTwitterScraper::Resources::Events (readonly)
Activity events from monitored accounts
59 60 61 |
# File 'lib/x_twitter_scraper/client.rb', line 59 def events @events end |
#extractions ⇒ XTwitterScraper::Resources::Extractions (readonly)
Bulk data extraction (23 tool types)
63 64 65 |
# File 'lib/x_twitter_scraper/client.rb', line 63 def extractions @extractions end |
#guest_wallets ⇒ XTwitterScraper::Resources::GuestWallets (readonly)
Accountless prepaid access for paid read endpoints
89 90 91 |
# File 'lib/x_twitter_scraper/client.rb', line 89 def guest_wallets @guest_wallets end |
#monitors ⇒ XTwitterScraper::Resources::Monitors (readonly)
X account monitoring with 1-second checks
55 56 57 |
# File 'lib/x_twitter_scraper/client.rb', line 55 def monitors @monitors end |
#radar ⇒ XTwitterScraper::Resources::Radar (readonly)
AI tweet composition, drafts, writing styles, and radar
51 52 53 |
# File 'lib/x_twitter_scraper/client.rb', line 51 def radar @radar end |
#styles ⇒ XTwitterScraper::Resources::Styles (readonly)
AI tweet composition, drafts, writing styles, and radar
47 48 49 |
# File 'lib/x_twitter_scraper/client.rb', line 47 def styles @styles end |
#subscribe ⇒ XTwitterScraper::Resources::Subscribe (readonly)
Subscription, billing, and credits
35 36 37 |
# File 'lib/x_twitter_scraper/client.rb', line 35 def subscribe @subscribe end |
#support ⇒ XTwitterScraper::Resources::Support (readonly)
81 82 83 |
# File 'lib/x_twitter_scraper/client.rb', line 81 def support @support end |
#trends ⇒ XTwitterScraper::Resources::Trends (readonly)
Trending topics and hashtags by region
78 79 80 |
# File 'lib/x_twitter_scraper/client.rb', line 78 def trends @trends end |
#webhooks ⇒ XTwitterScraper::Resources::Webhooks (readonly)
Webhook endpoint management and delivery
71 72 73 |
# File 'lib/x_twitter_scraper/client.rb', line 71 def webhooks @webhooks end |
#x ⇒ XTwitterScraper::Resources::X (readonly)
74 75 76 |
# File 'lib/x_twitter_scraper/client.rb', line 74 def x @x end |