Class: Courier::ProfilesClient
- Inherits:
-
Object
- Object
- Courier::ProfilesClient
- 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:) ⇒ ProfilesClient 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:) ⇒ ProfilesClient
19 20 21 22 |
# File 'lib/trycourier/profiles/client.rb', line 19 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.
15 16 17 |
# File 'lib/trycourier/profiles/client.rb', line 15 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/trycourier/profiles/client.rb', line 47 def create(user_id:, profile:, request_options: nil) 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 |
#delete(user_id:, request_options: nil) ⇒ Void
Deletes the specified user profile.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/trycourier/profiles/client.rb', line 91 def delete(user_id:, request_options: nil) @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 |
#delete_list_subscription(user_id:, request_options: nil) ⇒ Profiles::DeleteListSubscriptionResponse
Removes all list subscriptions for given user.
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/trycourier/profiles/client.rb', line 150 def delete_list_subscription(user_id:, request_options: nil) 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 |
#get(user_id:, request_options: nil) ⇒ Profiles::ProfileGetResponse
Returns the specified user profile.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trycourier/profiles/client.rb', line 29 def get(user_id:, request_options: nil) 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 |
#get_list_subscriptions(user_id:, cursor: nil, request_options: nil) ⇒ Profiles::GetListSubscriptionsResponse
Returns the subscribed lists for a specified user.
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/trycourier/profiles/client.rb', line 108 def get_list_subscriptions(user_id:, cursor: nil, request_options: nil) 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 |
#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.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trycourier/profiles/client.rb', line 73 def replace(user_id:, profile:, request_options: nil) 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 |
#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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/trycourier/profiles/client.rb', line 128 def subscribe_to_lists(user_id:, request:, request_options: nil) 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 |