Class: Courier::Resources::Profiles::Lists

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/profiles/lists.rb,
sig/courier/resources/profiles/lists.rbs

Overview

Store the contact information Courier delivers to for each user — email, phone number, push tokens, and any custom data you send to.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Lists

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Lists.

Parameters:



100
101
102
# File 'lib/courier/resources/profiles/lists.rb', line 100

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(user_id, request_options: {}) ⇒ Courier::Models::Profiles::ListDeleteResponse

Some parameter documentations has been truncated, see Models::Profiles::ListDeleteParams for more details.

Removes every list subscription for a user at once. Their profile and preferences are untouched, so this only affects list-targeted sends.

Parameters:

  • user_id (String)

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

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



53
54
55
56
57
58
59
60
# File 'lib/courier/resources/profiles/lists.rb', line 53

def delete(user_id, params = {})
  @client.request(
    method: :delete,
    path: ["profiles/%1$s/lists", user_id],
    model: Courier::Models::Profiles::ListDeleteResponse,
    options: params[:request_options]
  )
end

#retrieve(user_id, cursor: nil, request_options: {}) ⇒ Courier::Models::Profiles::ListRetrieveResponse

Some parameter documentations has been truncated, see Models::Profiles::ListRetrieveParams for more details.

Returns the lists a user is subscribed to, with paging. Use it to check what a recipient will receive before sending to a list.

Parameters:

  • user_id (String)

    A unique identifier representing the user associated with the requested user pro

  • cursor (String, nil)

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

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/courier/resources/profiles/lists.rb', line 26

def retrieve(user_id, params = {})
  parsed, options = Courier::Profiles::ListRetrieveParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["profiles/%1$s/lists", user_id],
    query: query,
    model: Courier::Models::Profiles::ListRetrieveResponse,
    options: options
  )
end

#subscribe(user_id, lists:, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::Profiles::ListSubscribeResponse

Some parameter documentations has been truncated, see Models::Profiles::ListSubscribeParams for more details.

Subscribes a user to one or more lists, creating any list that does not yet exist. Optional preferences apply to each subscription.

Parameters:

  • user_id (String)

    Path param: A unique identifier representing the user associated with the reques

  • lists (Array<Courier::Models::SubscribeToListsRequestItem>)

    Body param

  • idempotency_key (String)

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String)

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/courier/resources/profiles/lists.rb', line 83

def subscribe(user_id, params)
  parsed, options = Courier::Profiles::ListSubscribeParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["profiles/%1$s/lists", user_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::Models::Profiles::ListSubscribeResponse,
    options: options
  )
end