Class: Courier::AsyncProfilesClient
- Inherits:
-
Object
- Object
- Courier::AsyncProfilesClient
- Defined in:
- lib/trycourier/profiles/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
-
#create(user_id:, profile:, request_options: nil) ⇒ Profiles::MergeProfileResponse
Merge the supplied values with an existing profile or create a new profile if one doesn’t already exist.
-
#delete(user_id:, request_options: nil) ⇒ Void
Deletes the specified user profile.
-
#delete_list_subscription(user_id:, request_options: nil) ⇒ Profiles::DeleteListSubscriptionResponse
Removes all list subscriptions for given user.
-
#get(user_id:, request_options: nil) ⇒ Profiles::ProfileGetResponse
Returns the specified user profile.
-
#get_list_subscriptions(user_id:, cursor: nil, request_options: nil) ⇒ Profiles::GetListSubscriptionsResponse
Returns the subscribed lists for a specified user.
- #initialize(request_client:) ⇒ AsyncProfilesClient constructor
-
#replace(user_id:, profile:, request_options: nil) ⇒ Profiles::ReplaceProfileResponse
When using ‘PUT`, be sure to include all the key-value pairs required by the recipient’s profile.
-
#subscribe_to_lists(user_id:, request:, request_options: nil) ⇒ Profiles::SubscribeToListsResponse
Subscribes the given user to one or more lists.
Constructor Details
#initialize(request_client:) ⇒ AsyncProfilesClient
168 169 170 171 |
# File 'lib/trycourier/profiles/client.rb', line 168 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.
164 165 166 |
# File 'lib/trycourier/profiles/client.rb', line 164 def request_client @request_client end |
Instance Method Details
#create(user_id:, profile:, request_options: nil) ⇒ Profiles::MergeProfileResponse
Merge the supplied values with an existing profile or create a new profile if one doesn’t already exist.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/trycourier/profiles/client.rb', line 198 def create(user_id:, profile:, request_options: nil) Async do response = @request_client.conn.post("/profiles/#{user_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 = { **(&.additional_body_parameters || {}), profile: profile }.compact end Profiles::MergeProfileResponse.from_json(json_object: response.body) end end |
#delete(user_id:, request_options: nil) ⇒ Void
Deletes the specified user profile.
246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/trycourier/profiles/client.rb', line 246 def delete(user_id:, request_options: nil) Async do @request_client.conn.delete("/profiles/#{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 |
#delete_list_subscription(user_id:, request_options: nil) ⇒ Profiles::DeleteListSubscriptionResponse
Removes all list subscriptions for given user.
311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/trycourier/profiles/client.rb', line 311 def delete_list_subscription(user_id:, request_options: nil) Async do response = @request_client.conn.delete("/profiles/#{user_id}/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 end Profiles::DeleteListSubscriptionResponse.from_json(json_object: response.body) end end |
#get(user_id:, request_options: nil) ⇒ Profiles::ProfileGetResponse
Returns the specified user profile.
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/trycourier/profiles/client.rb', line 178 def get(user_id:, request_options: nil) Async do response = @request_client.conn.get("/profiles/#{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 Profiles::ProfileGetResponse.from_json(json_object: response.body) end end |
#get_list_subscriptions(user_id:, cursor: nil, request_options: nil) ⇒ Profiles::GetListSubscriptionsResponse
Returns the subscribed lists for a specified user.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/trycourier/profiles/client.rb', line 265 def get_list_subscriptions(user_id:, cursor: nil, request_options: nil) Async do response = @request_client.conn.get("/profiles/#{user_id}/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 }.compact end Profiles::GetListSubscriptionsResponse.from_json(json_object: response.body) end end |
#replace(user_id:, profile:, request_options: nil) ⇒ Profiles::ReplaceProfileResponse
When using ‘PUT`, be sure to include all the key-value pairs required by the recipient’s profile. Any key-value pairs that exist in the profile but fail to be included in the ‘PUT` request will be removed from the profile. Remember, a `PUT` update is a full replacement of the data. For partial updates, use the [Patch](www.courier.com/docs/reference/profiles/patch/) request.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/trycourier/profiles/client.rb', line 226 def replace(user_id:, profile:, request_options: nil) Async do response = @request_client.conn.put("/profiles/#{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 || {}), profile: profile }.compact end Profiles::ReplaceProfileResponse.from_json(json_object: response.body) end end |
#subscribe_to_lists(user_id:, request:, request_options: nil) ⇒ Profiles::SubscribeToListsResponse
Subscribes the given user to one or more lists. If the list does not exist, it will be created.
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/trycourier/profiles/client.rb', line 287 def subscribe_to_lists(user_id:, request:, request_options: nil) Async do response = @request_client.conn.post("/profiles/#{user_id}/lists") 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 Profiles::SubscribeToListsResponse.from_json(json_object: response.body) end end |