Class: Courier::Resources::Bulk

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

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:



136
137
138
# File 'lib/courier/resources/bulk.rb', line 136

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.

Get Bulk Job Users

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:



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

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

Get a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

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

Returns:

See Also:



104
105
106
107
108
109
110
111
# File 'lib/courier/resources/bulk.rb', line 104

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

Run a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

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

Returns:

  • (nil)

See Also:



124
125
126
127
128
129
130
131
# File 'lib/courier/resources/bulk.rb', line 124

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