Class: Courier::BulkClient
- Inherits:
-
Object
- Object
- Courier::BulkClient
- Defined in:
- lib/trycourier/bulk/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #create_job(message:, request_options: nil) ⇒ Bulk::BulkCreateJobResponse
-
#get_job(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobResponse
Get a bulk job.
-
#get_users(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobUsersResponse
Get Bulk Job Users.
-
#ingest_users(job_id:, request:, request_options: nil) ⇒ Void
Ingest user data into a Bulk Job.
- #initialize(request_client:) ⇒ BulkClient constructor
-
#run_job(job_id:, request_options: nil) ⇒ Void
Run a bulk job.
Constructor Details
#initialize(request_client:) ⇒ BulkClient
17 18 19 20 |
# File 'lib/trycourier/bulk/client.rb', line 17 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
13 14 15 |
# File 'lib/trycourier/bulk/client.rb', line 13 def request_client @request_client end |
Instance Method Details
#create_job(message:, request_options: nil) ⇒ Bulk::BulkCreateJobResponse
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/trycourier/bulk/client.rb', line 31 def create_job(message:, request_options: nil) response = @request_client.conn.post("/bulk") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), message: }.compact end Bulk::BulkCreateJobResponse.from_json(json_object: response.body) end |
#get_job(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobResponse
Get a bulk job
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/trycourier/bulk/client.rb', line 96 def get_job(job_id:, request_options: nil) response = @request_client.conn.get("/bulk/#{job_id}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Bulk::BulkGetJobResponse.from_json(json_object: response.body) end |
#get_users(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobUsersResponse
Get Bulk Job Users
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/trycourier/bulk/client.rb', line 113 def get_users(job_id:, request_options: nil) response = @request_client.conn.get("/bulk/#{job_id}/users") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Bulk::BulkGetJobUsersResponse.from_json(json_object: response.body) end |
#ingest_users(job_id:, request:, request_options: nil) ⇒ Void
Ingest user data into a Bulk Job
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/trycourier/bulk/client.rb', line 55 def ingest_users(job_id:, request:, request_options: nil) @request_client.conn.post("/bulk/#{job_id}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact end end |
#run_job(job_id:, request_options: nil) ⇒ Void
Run a bulk job
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/trycourier/bulk/client.rb', line 76 def run_job(job_id:, request_options: nil) @request_client.conn.post("/bulk/#{job_id}/run") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end end |