Class: XTwitterScraper::Resources::Extractions

Inherits:
Object
  • Object
show all
Defined in:
lib/x_twitter_scraper/resources/extractions.rb

Overview

Bulk data extraction (20 tool types)

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Extractions

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

Parameters:



172
173
174
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 172

def initialize(client:)
  @client = client
end

Instance Method Details

#estimate_cost(tool_type:, advanced_query: nil, exact_phrase: nil, exclude_words: nil, search_query: nil, target_community_id: nil, target_list_id: nil, target_space_id: nil, target_tweet_id: nil, target_username: nil, request_options: {}) ⇒ XTwitterScraper::Models::ExtractionEstimateCostResponse

Estimate extraction cost

Parameters:

  • tool_type (Symbol, XTwitterScraper::Models::ExtractionEstimateCostParams::ToolType)

    Identifier for the extraction tool used to run a job.

  • advanced_query (String)

    Raw advanced query string appended to the estimate (tweet_search_extractor)

  • exact_phrase (String)

    Exact phrase filter for search estimation

  • exclude_words (String)

    Words excluded from estimated search results

  • search_query (String)
  • target_community_id (String)
  • target_list_id (String)
  • target_space_id (String)
  • target_tweet_id (String)
  • target_username (String)
  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



92
93
94
95
96
97
98
99
100
101
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 92

def estimate_cost(params)
  parsed, options = XTwitterScraper::ExtractionEstimateCostParams.dump_request(params)
  @client.request(
    method: :post,
    path: "extractions/estimate",
    body: parsed,
    model: XTwitterScraper::Models::ExtractionEstimateCostResponse,
    options: options
  )
end

#export_results(id, format_: nil, request_options: {}) ⇒ StringIO

Export extraction results

Parameters:

Returns:

  • (StringIO)

See Also:



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 116

def export_results(id, params = {})
  parsed, options = XTwitterScraper::ExtractionExportResultsParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["extractions/%1$s/export", id],
    query: query.transform_keys(format_: "format"),
    headers: {"accept" => "application/octet-stream"},
    model: StringIO,
    options: options
  )
end

#list(after: nil, limit: nil, status: nil, tool_type: nil, request_options: {}) ⇒ XTwitterScraper::Models::ExtractionListResponse

List extraction jobs

Parameters:

Returns:

See Also:



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 51

def list(params = {})
  parsed, options = XTwitterScraper::ExtractionListParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "extractions",
    query: query.transform_keys(tool_type: "toolType"),
    model: XTwitterScraper::Models::ExtractionListResponse,
    options: options
  )
end

#retrieve(id, after: nil, limit: nil, request_options: {}) ⇒ XTwitterScraper::Models::ExtractionRetrieveResponse

Get extraction results

Parameters:

  • id (String)

    Extraction public ID (UUID)

  • after (String)

    Cursor for keyset pagination

  • limit (Integer)

    Maximum number of results to return (1-1000, default 100)

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

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 22

def retrieve(id, params = {})
  parsed, options = XTwitterScraper::ExtractionRetrieveParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["extractions/%1$s", id],
    query: query,
    model: XTwitterScraper::Models::ExtractionRetrieveResponse,
    options: options
  )
end

#run(tool_type:, advanced_query: nil, exact_phrase: nil, exclude_words: nil, search_query: nil, target_community_id: nil, target_list_id: nil, target_space_id: nil, target_tweet_id: nil, target_username: nil, request_options: {}) ⇒ XTwitterScraper::Models::ExtractionRunResponse

Run extraction

Parameters:

  • tool_type (Symbol, XTwitterScraper::Models::ExtractionRunParams::ToolType)

    Identifier for the extraction tool used to run a job.

  • advanced_query (String)

    Raw advanced search query appended as-is (tweet_search_extractor)

  • exact_phrase (String)

    Exact phrase to match (tweet_search_extractor)

  • exclude_words (String)

    Words to exclude from results (tweet_search_extractor)

  • search_query (String)
  • target_community_id (String)
  • target_list_id (String)
  • target_space_id (String)
  • target_tweet_id (String)
  • target_username (String)
  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



158
159
160
161
162
163
164
165
166
167
# File 'lib/x_twitter_scraper/resources/extractions.rb', line 158

def run(params)
  parsed, options = XTwitterScraper::ExtractionRunParams.dump_request(params)
  @client.request(
    method: :post,
    path: "extractions",
    body: parsed,
    model: XTwitterScraper::Models::ExtractionRunResponse,
    options: options
  )
end