Class: XTwitterScraper::Resources::Drafts

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

Overview

Tweet composition, drafts, writing styles & radar

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Drafts

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

Parameters:



98
99
100
# File 'lib/x_twitter_scraper/resources/drafts.rb', line 98

def initialize(client:)
  @client = client
end

Instance Method Details

#create(text:, goal: nil, topic: nil, request_options: {}) ⇒ XTwitterScraper::Models::DraftDetail

Save a tweet draft

Parameters:

Returns:

See Also:



19
20
21
22
23
24
25
26
27
28
# File 'lib/x_twitter_scraper/resources/drafts.rb', line 19

def create(params)
  parsed, options = XTwitterScraper::DraftCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "drafts",
    body: parsed,
    model: XTwitterScraper::DraftDetail,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ nil

Delete a draft

Parameters:

Returns:

  • (nil)

See Also:



86
87
88
89
90
91
92
93
# File 'lib/x_twitter_scraper/resources/drafts.rb', line 86

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["drafts/%1$s", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#list(after_cursor: nil, limit: nil, request_options: {}) ⇒ XTwitterScraper::Models::DraftListResponse

List saved drafts

Parameters:

  • after_cursor (String)

    Cursor for pagination

  • limit (Integer)

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

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

Returns:

See Also:



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/x_twitter_scraper/resources/drafts.rb', line 63

def list(params = {})
  parsed, options = XTwitterScraper::DraftListParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "drafts",
    query: query.transform_keys(after_cursor: "afterCursor"),
    model: XTwitterScraper::Models::DraftListResponse,
    options: options
  )
end

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

Get draft by ID

Parameters:

Returns:

See Also:



41
42
43
44
45
46
47
48
# File 'lib/x_twitter_scraper/resources/drafts.rb', line 41

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