Class: XTwitterScraper::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/x_twitter_scraper/client.rb

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

Instance Attribute Summary collapse

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

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.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["X_TWITTER_SCRAPER_API_KEY"])

    Defaults to ‘ENV`

  • bearer_token (String, nil) (defaults to: ENV["X_TWITTER_SCRAPER_BEARER_TOKEN"])

    OAuth 2.1 access token Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["X_TWITTER_SCRAPER_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


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
# File 'lib/x_twitter_scraper/client.rb', line 136

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"

  @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
  )

  @account = XTwitterScraper::Resources::Account.new(client: self)
  @api_keys = XTwitterScraper::Resources::APIKeys.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)
  @integrations = XTwitterScraper::Resources::Integrations.new(client: self)
  @x = XTwitterScraper::Resources::X.new(client: self)
  @trends = XTwitterScraper::Resources::Trends.new(client: self)
  @bot = XTwitterScraper::Resources::Bot.new(client: self)
  @support = XTwitterScraper::Resources::Support.new(client: self)
  @credits = XTwitterScraper::Resources::Credits.new(client: self)
end

Instance Attribute Details

#accountXTwitterScraper::Resources::Account (readonly)

Account info & settings



27
28
29
# File 'lib/x_twitter_scraper/client.rb', line 27

def 
  @account
end

#api_keyString? (readonly)

Returns:

  • (String, nil)


19
20
21
# File 'lib/x_twitter_scraper/client.rb', line 19

def api_key
  @api_key
end

#api_keysXTwitterScraper::Resources::APIKeys (readonly)

API key management (session auth only)



31
32
33
# File 'lib/x_twitter_scraper/client.rb', line 31

def api_keys
  @api_keys
end

#bearer_tokenString? (readonly)

OAuth 2.1 access token

Returns:

  • (String, nil)


23
24
25
# File 'lib/x_twitter_scraper/client.rb', line 23

def bearer_token
  @bearer_token
end

#botXTwitterScraper::Resources::Bot (readonly)



86
87
88
# File 'lib/x_twitter_scraper/client.rb', line 86

def bot
  @bot
end

#composeXTwitterScraper::Resources::Compose (readonly)

Tweet composition, drafts, writing styles & radar



39
40
41
# File 'lib/x_twitter_scraper/client.rb', line 39

def compose
  @compose
end

#creditsXTwitterScraper::Resources::Credits (readonly)

Subscription & billing



93
94
95
# File 'lib/x_twitter_scraper/client.rb', line 93

def credits
  @credits
end

#draftsXTwitterScraper::Resources::Drafts (readonly)

Tweet composition, drafts, writing styles & radar



43
44
45
# File 'lib/x_twitter_scraper/client.rb', line 43

def drafts
  @drafts
end

#drawsXTwitterScraper::Resources::Draws (readonly)

Giveaway draws from tweet replies



67
68
69
# File 'lib/x_twitter_scraper/client.rb', line 67

def draws
  @draws
end

#eventsXTwitterScraper::Resources::Events (readonly)

Activity events from monitored accounts



59
60
61
# File 'lib/x_twitter_scraper/client.rb', line 59

def events
  @events
end

#extractionsXTwitterScraper::Resources::Extractions (readonly)

Bulk data extraction (20 tool types)



63
64
65
# File 'lib/x_twitter_scraper/client.rb', line 63

def extractions
  @extractions
end

#integrationsXTwitterScraper::Resources::Integrations (readonly)

Push notification integrations (Telegram)



75
76
77
# File 'lib/x_twitter_scraper/client.rb', line 75

def integrations
  @integrations
end

#monitorsXTwitterScraper::Resources::Monitors (readonly)

Real-time X account monitoring



55
56
57
# File 'lib/x_twitter_scraper/client.rb', line 55

def monitors
  @monitors
end

#radarXTwitterScraper::Resources::Radar (readonly)

Tweet composition, drafts, writing styles & radar



51
52
53
# File 'lib/x_twitter_scraper/client.rb', line 51

def radar
  @radar
end

#stylesXTwitterScraper::Resources::Styles (readonly)

Tweet composition, drafts, writing styles & radar



47
48
49
# File 'lib/x_twitter_scraper/client.rb', line 47

def styles
  @styles
end

#subscribeXTwitterScraper::Resources::Subscribe (readonly)

Subscription & billing



35
36
37
# File 'lib/x_twitter_scraper/client.rb', line 35

def subscribe
  @subscribe
end

#supportXTwitterScraper::Resources::Support (readonly)



89
90
91
# File 'lib/x_twitter_scraper/client.rb', line 89

def support
  @support
end

Trending topics by region



83
84
85
# File 'lib/x_twitter_scraper/client.rb', line 83

def trends
  @trends
end

#webhooksXTwitterScraper::Resources::Webhooks (readonly)

Webhook endpoint management & delivery



71
72
73
# File 'lib/x_twitter_scraper/client.rb', line 71

def webhooks
  @webhooks
end

#xXTwitterScraper::Resources::X (readonly)

X data lookups (subscription required)



79
80
81
# File 'lib/x_twitter_scraper/client.rb', line 79

def x
  @x
end