Class: XTwitterScraper::Resources::X::Communities

Inherits:
Object
  • Object
show all
Defined in:
lib/x_twitter_scraper/resources/x/communities.rb,
lib/x_twitter_scraper/resources/x/communities/join.rb,
lib/x_twitter_scraper/resources/x/communities/tweets.rb,
sig/x_twitter_scraper/resources/x/communities.rbs,
sig/x_twitter_scraper/resources/x/communities/join.rbs,
sig/x_twitter_scraper/resources/x/communities/tweets.rbs

Defined Under Namespace

Classes: Join, Tweets

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Communities

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 Communities.

Parameters:



292
293
294
295
296
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 292

def initialize(client:)
  @client = client
  @join = XTwitterScraper::Resources::X::Communities::Join.new(client: client)
  @tweets = XTwitterScraper::Resources::X::Communities::Tweets.new(client: client)
end

Instance Attribute Details

#joinXTwitterScraper::Resources::X::Communities::Join (readonly)

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



13
14
15
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 13

def join
  @join
end

#tweetsXTwitterScraper::Resources::X::Communities::Tweets (readonly)

X Community info, members, and tweets



17
18
19
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 17

def tweets
  @tweets
end

Instance Method Details

#create(account:, name:, idempotency_key:, description: nil, request_options: {}) ⇒ XTwitterScraper::Models::X::CommunityCreateResponse

Some parameter documentations has been truncated, see Models::X::CommunityCreateParams for more details.

Create community

Parameters:

  • account (String)

    Body param: X account (@username or ID) creating the community

  • name (String)

    Body param: Community name

  • idempotency_key (String)

    Header param: Generate one unique value for each intended write. Reuse it only w

  • description (String)

    Body param: Community description

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

Returns:

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 39

def create(params)
  parsed, options = XTwitterScraper::X::CommunityCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "x/communities",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: XTwitterScraper::Models::X::CommunityCreateResponse,
    options: options
  )
end

#delete(id, account:, community_name:, idempotency_key:, request_options: {}) ⇒ XTwitterScraper::Models::X::CommunityDeleteResponse

Some parameter documentations has been truncated, see Models::X::CommunityDeleteParams for more details.

Delete community

Parameters:

  • id (String)

    Path param: Resource ID returned by the matching create or list endpoint.

  • account (String)

    Body param: X account (@username or ID) deleting the community

  • community_name (String)

    Body param: Community name for confirmation

  • idempotency_key (String)

    Header param: Generate one unique value for each intended write. Reuse it only w

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

Returns:

See Also:



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 72

def delete(id, params)
  parsed, options = XTwitterScraper::X::CommunityDeleteParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :delete,
    path: ["x/communities/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: XTwitterScraper::Models::X::CommunityDeleteResponse,
    options: options
  )
end

#retrieve_info(id, request_options: {}) ⇒ XTwitterScraper::Models::X::CommunityRetrieveInfoResponse

Get community name, description & member count

Parameters:

Returns:

See Also:



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

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

#retrieve_members(id, bio_contains: nil, cursor: nil, has_location: nil, has_website: nil, location_contains: nil, max_followers: nil, max_following: nil, max_statuses: nil, min_account_age_days: nil, min_followers: nil, min_following: nil, min_statuses: nil, page_size: nil, username_contains: nil, verified_only: nil, verified_type: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Some parameter documentations has been truncated, see Models::X::CommunityRetrieveMembersParams for more details.

List members of a community

Parameters:

  • id (String)

    Community ID for member lookup

  • bio_contains (String)

    Match any comma-separated or line-separated bio term, ignoring case.

  • cursor (String)

    Pagination cursor

  • has_location (Boolean)

    Only return profiles with a location.

  • has_website (Boolean)

    Only return profiles with a website.

  • location_contains (String)

    Match a location substring, ignoring case.

  • max_followers (Integer)

    Maximum follower count. Missing counts pass this maximum.

  • max_following (Integer)

    Maximum following count.

  • max_statuses (Integer)

    Maximum post count. maxPosts is also accepted.

  • min_account_age_days (Integer)

    Minimum account age in whole days.

  • min_followers (Integer)

    Minimum follower count. Filtering happens before billing.

  • min_following (Integer)

    Minimum following count.

  • min_statuses (Integer)

    Minimum post count. minPosts is also accepted.

  • page_size (Integer)

    Items per page (20-200, default 20). This is an upper bound for paid authenticat

  • username_contains (String)

    Match a username substring, ignoring case.

  • verified_only (Boolean)

    Only return verified profiles.

  • verified_type (String)

    Match the verification type exactly, ignoring case.

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

Returns:

See Also:



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
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 151

def retrieve_members(id, params = {})
  parsed, options = XTwitterScraper::X::CommunityRetrieveMembersParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/communities/%1$s/members", id],
    query: query.transform_keys(
      bio_contains: "bioContains",
      has_location: "hasLocation",
      has_website: "hasWebsite",
      location_contains: "locationContains",
      max_followers: "maxFollowers",
      max_following: "maxFollowing",
      max_statuses: "maxStatuses",
      min_account_age_days: "minAccountAgeDays",
      min_followers: "minFollowers",
      min_following: "minFollowing",
      min_statuses: "minStatuses",
      page_size: "pageSize",
      username_contains: "usernameContains",
      verified_only: "verifiedOnly",
      verified_type: "verifiedType"
    ),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_moderators(id, bio_contains: nil, cursor: nil, has_location: nil, has_website: nil, location_contains: nil, max_followers: nil, max_following: nil, max_statuses: nil, min_account_age_days: nil, min_followers: nil, min_following: nil, min_statuses: nil, username_contains: nil, verified_only: nil, verified_type: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Some parameter documentations has been truncated, see Models::X::CommunityRetrieveModeratorsParams for more details.

List moderators of a community

Parameters:

  • id (String)

    Community ID for moderator lookup

  • bio_contains (String)

    Match any comma-separated or line-separated bio term, ignoring case.

  • cursor (String)

    Pagination cursor for community moderators

  • has_location (Boolean)

    Only return profiles with a location.

  • has_website (Boolean)

    Only return profiles with a website.

  • location_contains (String)

    Match a location substring, ignoring case.

  • max_followers (Integer)

    Maximum follower count. Missing counts pass this maximum.

  • max_following (Integer)

    Maximum following count.

  • max_statuses (Integer)

    Maximum post count. maxPosts is also accepted.

  • min_account_age_days (Integer)

    Minimum account age in whole days.

  • min_followers (Integer)

    Minimum follower count. Filtering happens before billing.

  • min_following (Integer)

    Minimum following count.

  • min_statuses (Integer)

    Minimum post count. minPosts is also accepted.

  • username_contains (String)

    Match a username substring, ignoring case.

  • verified_only (Boolean)

    Only return verified profiles.

  • verified_type (String)

    Match the verification type exactly, ignoring case.

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

Returns:

See Also:



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 224

def retrieve_moderators(id, params = {})
  parsed, options = XTwitterScraper::X::CommunityRetrieveModeratorsParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/communities/%1$s/moderators", id],
    query: query.transform_keys(
      bio_contains: "bioContains",
      has_location: "hasLocation",
      has_website: "hasWebsite",
      location_contains: "locationContains",
      max_followers: "maxFollowers",
      max_following: "maxFollowing",
      max_statuses: "maxStatuses",
      min_account_age_days: "minAccountAgeDays",
      min_followers: "minFollowers",
      min_following: "minFollowing",
      min_statuses: "minStatuses",
      username_contains: "usernameContains",
      verified_only: "verifiedOnly",
      verified_type: "verifiedType"
    ),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#retrieve_search(community_id:, q:, cursor: nil, page_size: nil, query_type: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Some parameter documentations has been truncated, see Models::X::CommunityRetrieveSearchParams for more details.

Returns tweets, not community records. Requires a Community ID.

Parameters:

Returns:

See Also:



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 273

def retrieve_search(params)
  parsed, options = XTwitterScraper::X::CommunityRetrieveSearchParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "x/communities/search",
    query: query.transform_keys(
      community_id: "communityId",
      page_size: "pageSize",
      query_type: "queryType"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end