Class: XTwitterScraper::Resources::X::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/x_twitter_scraper/resources/x/users.rb,
lib/x_twitter_scraper/resources/x/users/follow.rb

Overview

X data lookups (subscription required)

Defined Under Namespace

Classes: Follow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Users

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Users.

Parameters:



298
299
300
301
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 298

def initialize(client:)
  @client = client
  @follow = XTwitterScraper::Resources::X::Users::Follow.new(client: client)
end

Instance Attribute Details

#followXTwitterScraper::Resources::X::Users::Follow (readonly)

X write actions (tweets, likes, follows, DMs)



10
11
12
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 10

def follow
  @follow
end

Instance Method Details

#retrieve(id, request_options: {}) ⇒ XTwitterScraper::Models::X::UserProfile

Look up X user

Parameters:

Returns:

See Also:



23
24
25
26
27
28
29
30
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 23

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["x/users/%1$s", id],
    model: XTwitterScraper::X::UserProfile,
    options: params[:request_options]
  )
end

#retrieve_batch(ids:, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get multiple users by IDs

Parameters:

Returns:

See Also:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 43

def retrieve_batch(params)
  parsed, options = XTwitterScraper::X::UserRetrieveBatchParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "x/users/batch",
    query: query,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_followers(id, cursor: nil, page_size: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get user followers

Parameters:

  • id (String)

    User ID or username

  • cursor (String)

    Pagination cursor for followers list

  • page_size (Integer)

    Items per page (20-200, default 200)

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 70

def retrieve_followers(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveFollowersParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/followers", id],
    query: query.transform_keys(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_followers_you_know(id, cursor: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get followers you know for a user

Parameters:

  • id (String)

    User ID for followers-you-know lookup

  • cursor (String)

    Pagination cursor for followers-you-know

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 95

def retrieve_followers_you_know(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveFollowersYouKnowParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/followers-you-know", id],
    query: query,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_following(id, cursor: nil, page_size: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get users this user follows

Parameters:

  • id (String)

    User ID or username for following lookup

  • cursor (String)

    Pagination cursor for following list

  • page_size (Integer)

    Results per page (20-200, default 200)

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 122

def retrieve_following(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveFollowingParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/following", id],
    query: query.transform_keys(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_likes(id, cursor: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get tweets liked by a user

Parameters:

  • id (String)

    User ID

  • cursor (String)

    Pagination cursor for liked tweets

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 147

def retrieve_likes(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveLikesParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/likes", id],
    query: query,
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#retrieve_media(id, cursor: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get media tweets by a user

Parameters:

  • id (String)

    User ID for media lookup

  • cursor (String)

    Pagination cursor for media tweets

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 172

def retrieve_media(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveMediaParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/media", id],
    query: query,
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#retrieve_mentions(id, cursor: nil, since_time: nil, until_time: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get tweets mentioning a user

Parameters:

  • id (String)

    User ID or username for mentions lookup

  • cursor (String)

    Pagination cursor for mentions

  • since_time (String)

    Unix timestamp - return mentions after this time

  • until_time (String)

    Unix timestamp - return mentions before this time

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



201
202
203
204
205
206
207
208
209
210
211
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 201

def retrieve_mentions(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveMentionsParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/mentions", id],
    query: query.transform_keys(since_time: "sinceTime", until_time: "untilTime"),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#retrieve_search(q:, cursor: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Search users by name or username

Parameters:

  • q (String)

    User search query

  • cursor (String)

    Pagination cursor for user search

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



226
227
228
229
230
231
232
233
234
235
236
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 226

def retrieve_search(params)
  parsed, options = XTwitterScraper::X::UserRetrieveSearchParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "x/users/search",
    query: query,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_tweets(id, cursor: nil, include_parent_tweet: nil, include_replies: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get recent tweets by a user

Parameters:

  • id (String)

    X user ID or username

  • cursor (String)

    Pagination cursor for user tweets

  • include_parent_tweet (Boolean)

    Include parent tweet for replies

  • include_replies (Boolean)

    Include reply tweets

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 255

def retrieve_tweets(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveTweetsParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/tweets", id],
    query: query.transform_keys(
      include_parent_tweet: "includeParentTweet",
      include_replies: "includeReplies"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#retrieve_verified_followers(id, cursor: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get verified followers

Parameters:

  • id (String)

    User ID or username for verified followers

  • cursor (String)

    Pagination cursor for verified followers

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/x_twitter_scraper/resources/x/users.rb', line 283

def retrieve_verified_followers(id, params = {})
  parsed, options = XTwitterScraper::X::UserRetrieveVerifiedFollowersParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/users/%1$s/verified-followers", id],
    query: query,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end