Class: Courier::AsyncListsClient
- Inherits:
-
Object
- Object
- Courier::AsyncListsClient
- Defined in:
- lib/trycourier/lists/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
-
#add_subscribers(list_id:, request:, request_options: nil) ⇒ Void
Subscribes additional users to the list, without modifying existing subscriptions.
-
#delete(list_id:, request_options: nil) ⇒ Void
Delete a list by list ID.
-
#get(list_id:, request_options: nil) ⇒ Lists::List
Returns a list based on the list ID provided.
-
#get_subscribers(list_id:, cursor: nil, request_options: nil) ⇒ Lists::ListGetSubscriptionsResponse
Get the list’s subscriptions.
- #initialize(request_client:) ⇒ AsyncListsClient constructor
-
#list(cursor: nil, pattern: nil, request_options: nil) ⇒ Lists::ListGetAllResponse
Returns all of the lists, with the ability to filter based on a pattern.
-
#restore(list_id:, request_options: nil) ⇒ Void
Restore a previously deleted list.
-
#subscribe(list_id:, user_id:, preferences: nil, request_options: nil) ⇒ Void
Subscribe a user to an existing list (note: if the List does not exist, it will be automatically created).
-
#unsubscribe(list_id:, user_id:, request_options: nil) ⇒ Void
Delete a subscription to a list by list ID and user ID.
-
#update(list_id:, request:, request_options: nil) ⇒ Lists::List
Create or replace an existing list with the supplied values.
-
#update_subscribers(list_id:, request:, request_options: nil) ⇒ Void
Subscribes the users to the list, overwriting existing subscriptions.
Constructor Details
#initialize(request_client:) ⇒ AsyncListsClient
229 230 231 232 |
# File 'lib/trycourier/lists/client.rb', line 229 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.
225 226 227 |
# File 'lib/trycourier/lists/client.rb', line 225 def request_client @request_client end |
Instance Method Details
#add_subscribers(list_id:, request:, request_options: nil) ⇒ Void
Subscribes additional users to the list, without modifying existing subscriptions. If the list does not exist, it will be automatically created.
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/trycourier/lists/client.rb', line 394 def add_subscribers(list_id:, request:, request_options: nil) Async do @request_client.conn.post("/lists/#{list_id}/subscriptions") 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 |
#delete(list_id:, request_options: nil) ⇒ Void
Delete a list by list ID.
308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/trycourier/lists/client.rb', line 308 def delete(list_id:, request_options: nil) Async do @request_client.conn.delete("/lists/#{list_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 end end |
#get(list_id:, request_options: nil) ⇒ Lists::List
Returns a list based on the list ID provided.
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/trycourier/lists/client.rb', line 264 def get(list_id:, request_options: nil) Async do response = @request_client.conn.get("/lists/#{list_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 Lists::List.from_json(json_object: response.body) end end |
#get_subscribers(list_id:, cursor: nil, request_options: nil) ⇒ Lists::ListGetSubscriptionsResponse
Get the list’s subscriptions.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/trycourier/lists/client.rb', line 345 def get_subscribers(list_id:, cursor: nil, request_options: nil) Async do response = @request_client.conn.get("/lists/#{list_id}/subscriptions") 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 req.params = { **(&.additional_query_parameters || {}), "cursor": cursor }.compact end Lists::ListGetSubscriptionsResponse.from_json(json_object: response.body) end end |
#list(cursor: nil, pattern: nil, request_options: nil) ⇒ Lists::ListGetAllResponse
Returns all of the lists, with the ability to filter based on a pattern.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/trycourier/lists/client.rb', line 240 def list(cursor: nil, pattern: nil, request_options: nil) Async do response = @request_client.conn.get("/lists") 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 req.params = { **(&.additional_query_parameters || {}), "cursor": cursor, "pattern": pattern }.compact end Lists::ListGetAllResponse.from_json(json_object: response.body) end end |
#restore(list_id:, request_options: nil) ⇒ Void
Restore a previously deleted list.
326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/trycourier/lists/client.rb', line 326 def restore(list_id:, request_options: nil) Async do @request_client.conn.put("/lists/#{list_id}/restore") 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 end end |
#subscribe(list_id:, user_id:, preferences: nil, request_options: nil) ⇒ Void
Subscribe a user to an existing list (note: if the List does not exist, it will be automatically created).
421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/trycourier/lists/client.rb', line 421 def subscribe(list_id:, user_id:, preferences: nil, request_options: nil) Async do @request_client.conn.put("/lists/#{list_id}/subscriptions/#{user_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 req.body = { **(&.additional_body_parameters || {}), preferences: preferences }.compact end end end |
#unsubscribe(list_id:, user_id:, request_options: nil) ⇒ Void
Delete a subscription to a list by list ID and user ID.
441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/trycourier/lists/client.rb', line 441 def unsubscribe(list_id:, user_id:, request_options: nil) Async do @request_client.conn.delete("/lists/#{list_id}/subscriptions/#{user_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 end end |
#update(list_id:, request:, request_options: nil) ⇒ Lists::List
Create or replace an existing list with the supplied values.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/trycourier/lists/client.rb', line 288 def update(list_id:, request:, request_options: nil) Async do response = @request_client.conn.put("/lists/#{list_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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact end Lists::List.from_json(json_object: response.body) end end |
#update_subscribers(list_id:, request:, request_options: nil) ⇒ Void
Subscribes the users to the list, overwriting existing subscriptions. If the list does not exist, it will be automatically created.
370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/trycourier/lists/client.rb', line 370 def update_subscribers(list_id:, request:, request_options: nil) Async do @request_client.conn.put("/lists/#{list_id}/subscriptions") 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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact end end end |