Class: Courier::AsyncBulkClient
- Inherits:
-
Object
- Object
- Courier::AsyncBulkClient
- 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:) ⇒ AsyncBulkClient constructor
-
#run_job(job_id:, request_options: nil) ⇒ Void
Run a bulk job.
Constructor Details
#initialize(request_client:) ⇒ AsyncBulkClient
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_client ⇒ Object (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
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..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 end |
#get_job(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobResponse
Get a bulk job
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..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 end |
#get_users(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobUsersResponse
Get Bulk Job Users
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..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 end |
#ingest_users(job_id:, request:, request_options: nil) ⇒ Void
Ingest user data into a Bulk Job
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..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 end |
#run_job(job_id:, request_options: nil) ⇒ Void
Run a bulk job
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..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 end |