Class: Courier::ListsClient
- Inherits:
-
Object
- Object
- Courier::ListsClient
- 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:) ⇒ ListsClient 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:) ⇒ ListsClient
18 19 20 21 |
# File 'lib/trycourier/lists/client.rb', line 18 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.
14 15 16 |
# File 'lib/trycourier/lists/client.rb', line 14 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.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/trycourier/lists/client.rb', line 169 def add_subscribers(list_id:, request:, request_options: nil) @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 |
#delete(list_id:, request_options: nil) ⇒ Void
Delete a list by list ID.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/trycourier/lists/client.rb', line 91 def delete(list_id:, request_options: nil) @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 |
#get(list_id:, request_options: nil) ⇒ Lists::List
Returns a list based on the list ID provided.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trycourier/lists/client.rb', line 51 def get(list_id:, request_options: nil) 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 |
#get_subscribers(list_id:, cursor: nil, request_options: nil) ⇒ Lists::ListGetSubscriptionsResponse
Get the list’s subscriptions.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/trycourier/lists/client.rb', line 124 def get_subscribers(list_id:, cursor: nil, request_options: nil) 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 |
#list(cursor: nil, pattern: nil, request_options: nil) ⇒ Lists::ListGetAllResponse
Returns all of the lists, with the ability to filter based on a pattern.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trycourier/lists/client.rb', line 29 def list(cursor: nil, pattern: nil, request_options: nil) 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 |
#restore(list_id:, request_options: nil) ⇒ Void
Restore a previously deleted list.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/trycourier/lists/client.rb', line 107 def restore(list_id:, request_options: nil) @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 |
#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).
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/trycourier/lists/client.rb', line 194 def subscribe(list_id:, user_id:, preferences: nil, request_options: nil) @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 |
#unsubscribe(list_id:, user_id:, request_options: nil) ⇒ Void
Delete a subscription to a list by list ID and user ID.
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/trycourier/lists/client.rb', line 212 def unsubscribe(list_id:, user_id:, request_options: nil) @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 |
#update(list_id:, request:, request_options: nil) ⇒ Lists::List
Create or replace an existing list with the supplied values.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trycourier/lists/client.rb', line 73 def update(list_id:, request:, request_options: nil) 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 |
#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.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/trycourier/lists/client.rb', line 147 def update_subscribers(list_id:, request:, request_options: nil) @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 |