Class: Courier::Bulk
- Inherits:
-
Object
- Object
- Courier::Bulk
- Defined in:
- lib/trycourier/bulk.rb
Constant Summary collapse
- KEY =
"/bulk"
Instance Method Summary collapse
- #create_job(message:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
- #get_job(job_id:) ⇒ Object
- #get_job_users(job_id:, cursor: nil) ⇒ Object
- #ingest_job(job_id:, users:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
-
#initialize(session) ⇒ Bulk
constructor
A new instance of Bulk.
- #run_job(job_id:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
Constructor Details
#initialize(session) ⇒ Bulk
Returns a new instance of Bulk.
5 6 7 |
# File 'lib/trycourier/bulk.rb', line 5 def initialize(session) @session = session end |
Instance Method Details
#create_job(message:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/trycourier/bulk.rb', line 9 def create_job(message:, idempotency_key: nil, idempotency_expiry: nil) path = KEY.to_s payload = { "message": } headers = {} if idempotency_key headers["idempotency_key"] = idempotency_key end if idempotency_expiry headers["x-idempotency-expiration"] = idempotency_expiry end res = @session.send(path, "POST", body: payload, headers: headers) ErrorHandler.check_err(res) end |
#get_job(job_id:) ⇒ Object
61 62 63 64 65 |
# File 'lib/trycourier/bulk.rb', line 61 def get_job(job_id:) path = "#{KEY}/#{job_id}" res = @session.send(path, "GET") ErrorHandler.check_err(res) end |
#get_job_users(job_id:, cursor: nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/trycourier/bulk.rb', line 67 def get_job_users(job_id:, cursor: nil) path = "#{KEY}/#{job_id}/users" params = {} if cursor params["cursor"] = cursor end res = @session.send(path, "GET", params: params) ErrorHandler.check_err(res) end |
#ingest_job(job_id:, users:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/trycourier/bulk.rb', line 27 def ingest_job(job_id:, users:, idempotency_key: nil, idempotency_expiry: nil) path = "#{KEY}/#{job_id}" payload = { "users": users } headers = {} if idempotency_key headers["idempotency_key"] = idempotency_key end if idempotency_expiry headers["x-idempotency-expiration"] = idempotency_expiry end res = @session.send(path, "POST", body: payload, headers: headers) ErrorHandler.check_err(res) end |
#run_job(job_id:, idempotency_key: nil, idempotency_expiry: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/trycourier/bulk.rb', line 45 def run_job(job_id:, idempotency_key: nil, idempotency_expiry: nil) path = "#{KEY}/#{job_id}/run" payload = {} headers = {} if idempotency_key headers["idempotency_key"] = idempotency_key end if idempotency_expiry headers["x-idempotency-expiration"] = idempotency_expiry end res = @session.send(path, "POST", body: payload, headers: headers) ErrorHandler.check_err_non_json(res) end |