Class: Courier::AsyncBulkClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/bulk/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncBulkClient

Parameters:



131
132
133
134
# File 'lib/trycourier/bulk/client.rb', line 131

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



127
128
129
# File 'lib/trycourier/bulk/client.rb', line 127

def request_client
  @request_client
end

Instance Method Details

#create_job(message:, request_options: nil) ⇒ Bulk::BulkCreateJobResponse

Parameters:

  • message (Hash)

    Request of type Bulk::InboundBulkMessage, as a Hash

    • :message (Hash)

    • :brand (String)

    • :data (Hash=> String)

    • :event (String)

    • :locale (Hash=> String)

    • :override (Object)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/trycourier/bulk/client.rb', line 145

def create_job(message:, request_options: nil)
  Async do
    response = @request_client.conn.post("/bulk") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request_options&.additional_body_parameters || {}), message: message }.compact
    end
    Bulk::BulkCreateJobResponse.from_json(json_object: response.body)
  end
end

#get_job(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobResponse

Get a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (RequestOptions) (defaults to: nil)

Returns:



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/trycourier/bulk/client.rb', line 216

def get_job(job_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/bulk/#{job_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Bulk::BulkGetJobResponse.from_json(json_object: response.body)
  end
end

#get_users(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobUsersResponse

Get Bulk Job Users

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (RequestOptions) (defaults to: nil)

Returns:



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/trycourier/bulk/client.rb', line 235

def get_users(job_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/bulk/#{job_id}/users") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Bulk::BulkGetJobUsersResponse.from_json(json_object: response.body)
  end
end

#ingest_users(job_id:, request:, request_options: nil) ⇒ Void

Ingest user data into a Bulk Job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request (Hash)

    Request of type Bulk::BulkIngestUsersParams, as a Hash

    • :users (Array<Bulk::InboundBulkMessageUser>)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:

  • (Void)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/trycourier/bulk/client.rb', line 171

def ingest_users(job_id:, request:, request_options: nil)
  Async do
    @request_client.conn.post("/bulk/#{job_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
  end
end

#run_job(job_id:, request_options: nil) ⇒ Void

Run a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:

  • (Void)


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/trycourier/bulk/client.rb', line 194

def run_job(job_id:, request_options: nil)
  Async do
    @request_client.conn.post("/bulk/#{job_id}/run") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
  end
end