Class: XTwitterScraper::Resources::Draws

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

Overview

Giveaway draws from tweet replies

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Draws

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

Parameters:



115
116
117
# File 'lib/x_twitter_scraper/resources/draws.rb', line 115

def initialize(client:)
  @client = client
end

Instance Method Details

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

Export draw data

Parameters:

Returns:

  • (StringIO)

See Also:



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/x_twitter_scraper/resources/draws.rb', line 67

def export(id, params = {})
  parsed, options = XTwitterScraper::DrawExportParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["draws/%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, request_options: {}) ⇒ XTwitterScraper::Models::DrawListResponse

List draws

Parameters:

  • after (String)

    Cursor for keyset pagination

  • limit (Integer)

    Maximum number of items to return (1-100, default 50)

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

Returns:

See Also:



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

def list(params = {})
  parsed, options = XTwitterScraper::DrawListParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "draws",
    query: query,
    model: XTwitterScraper::Models::DrawListResponse,
    options: options
  )
end

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

Get draw details

Parameters:

Returns:

See Also:



18
19
20
21
22
23
24
25
# File 'lib/x_twitter_scraper/resources/draws.rb', line 18

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

#run(tweet_url:, backup_count: nil, filter_account_age_days: nil, filter_language: nil, filter_min_followers: nil, must_follow_username: nil, must_retweet: nil, required_hashtags: nil, required_keywords: nil, required_mentions: nil, unique_authors_only: nil, winner_count: nil, request_options: {}) ⇒ XTwitterScraper::Models::DrawRunResponse

Run giveaway draw

Parameters:

  • tweet_url (String)
  • backup_count (Integer)
  • filter_account_age_days (Integer)
  • filter_language (String)
  • filter_min_followers (Integer)
  • must_follow_username (String)
  • must_retweet (Boolean)
  • required_hashtags (Array<String>)
  • required_keywords (Array<String>)
  • required_mentions (Array<String>)
  • unique_authors_only (Boolean)
  • winner_count (Integer)
  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



101
102
103
104
105
106
107
108
109
110
# File 'lib/x_twitter_scraper/resources/draws.rb', line 101

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