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:



183
184
185
186
187
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 183

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)



9
10
11
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 9

def join
  @join
end

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

X Community info, members, and tweets



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

def tweets
  @tweets
end

Instance Method Details

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

Create community

Parameters:

  • account (String)

    X account (@username or ID) creating the community

  • name (String)

    Community name

  • description (String)

    Community description

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

Returns:

See Also:



30
31
32
33
34
35
36
37
38
39
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 30

def create(params)
  parsed, options = XTwitterScraper::X::CommunityCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "x/communities",
    body: parsed,
    model: XTwitterScraper::Models::X::CommunityCreateResponse,
    options: options
  )
end

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

Delete community

Parameters:

  • id (String)

    Resource ID returned by the matching create or list endpoint.

  • account (String)

    X account (@username or ID) deleting the community

  • community_name (String)

    Community name for confirmation

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

Returns:

See Also:



56
57
58
59
60
61
62
63
64
65
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 56

def delete(id, params)
  parsed, options = XTwitterScraper::X::CommunityDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["x/communities/%1$s", id],
    body: parsed,
    model: XTwitterScraper::Models::X::CommunityDeleteResponse,
    options: options
  )
end

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

Get community name, description and member count

Parameters:

Returns:

See Also:



78
79
80
81
82
83
84
85
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 78

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, cursor: nil, page_size: 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

  • cursor (String)

    Pagination cursor

  • page_size (Integer)

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

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

Returns:

See Also:



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 105

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(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

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

List moderators of a community

Parameters:

  • id (String)

    Community ID for moderator lookup

  • cursor (String)

    Pagination cursor for community moderators

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

Returns:

See Also:



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 130

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,
    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:



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/x_twitter_scraper/resources/x/communities.rb', line 164

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