Class: Courier::AsyncProfilesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/profiles/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncProfilesClient

Parameters:



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_clientObject (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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • profile (Hash{String => String})
  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request_options&.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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
  end
end

#delete_list_subscription(user_id:, request_options: nil) ⇒ Profiles::DeleteListSubscriptionResponse

Removes all list subscriptions for given user.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • cursor (String) (defaults to: nil)

    A unique identifier that allows for fetching the next set of message statuses.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.params = { **(request_options&.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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • profile (Hash{String => String})
  • request_options (RequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request_options&.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.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested profile.

  • request (Hash)

    Request of type Profiles::SubscribeToListsRequest, as a Hash

    • :lists (Array<Profiles::SubscribeToListsRequestListObject>)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
    Profiles::SubscribeToListsResponse.from_json(json_object: response.body)
  end
end