Class: Courier::Resources::Bulk

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/bulk.rb,
sig/courier/resources/bulk.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Bulk

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

Parameters:



141
142
143
# File 'lib/courier/resources/bulk.rb', line 141

def initialize(client:)
  @client = client
end

Instance Method Details

#add_users(job_id, users:, request_options: {}) ⇒ nil

Ingest user data into a Bulk Job.

Important: For email-based bulk jobs, each user must include profile.email for provider routing to work correctly. The to.email field is not sufficient for email provider routing.

Parameters:

Returns:

  • (nil)

See Also:



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

def add_users(job_id, params)
  parsed, options = Courier::BulkAddUsersParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["bulk/%1$s", job_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#create_job(message:, request_options: {}) ⇒ Courier::Models::BulkCreateJobResponse

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

Creates a new bulk job for sending messages to multiple recipients.

Required: message.event (event ID or notification ID)

Optional (V2 format): message.template (notification ID) or message.content (Elemental content) can be provided to override the notification associated with the event.

Parameters:

Returns:

See Also:



54
55
56
57
58
59
60
61
62
63
# File 'lib/courier/resources/bulk.rb', line 54

def create_job(params)
  parsed, options = Courier::BulkCreateJobParams.dump_request(params)
  @client.request(
    method: :post,
    path: "bulk",
    body: parsed,
    model: Courier::Models::BulkCreateJobResponse,
    options: options
  )
end

#list_users(job_id, cursor: nil, request_options: {}) ⇒ Courier::Models::BulkListUsersResponse

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

Returns the users ingested into a bulk job with paging, each carrying the status Courier recorded for it and the id of the message it produced.

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • cursor (String, nil)

    A unique identifier that allows for fetching the next set of users added to the

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

Returns:

See Also:



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/courier/resources/bulk.rb', line 82

def list_users(job_id, params = {})
  parsed, options = Courier::BulkListUsersParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["bulk/%1$s/users", job_id],
    query: query,
    model: Courier::Models::BulkListUsersResponse,
    options: options
  )
end

#retrieve_job(job_id, request_options: {}) ⇒ Courier::Models::BulkRetrieveJobResponse

Returns a bulk job's message definition, its status — CREATED, PROCESSING, COMPLETED, or ERROR — and running counts of users received, messages enqueued, and failures. Poll it to follow a job through to completion.

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

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

Returns:

See Also:



107
108
109
110
111
112
113
114
# File 'lib/courier/resources/bulk.rb', line 107

def retrieve_job(job_id, params = {})
  @client.request(
    method: :get,
    path: ["bulk/%1$s", job_id],
    model: Courier::Models::BulkRetrieveJobResponse,
    options: params[:request_options]
  )
end

#run_job(job_id, request_options: {}) ⇒ nil

Starts processing a bulk job, sending to every user ingested into it. Returns 204 immediately; the job runs asynchronously, so poll the job to watch its status and counts.

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

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

Returns:

  • (nil)

See Also:



129
130
131
132
133
134
135
136
# File 'lib/courier/resources/bulk.rb', line 129

def run_job(job_id, params = {})
  @client.request(
    method: :post,
    path: ["bulk/%1$s/run", job_id],
    model: NilClass,
    options: params[:request_options]
  )
end