Class: Courier::Resources::Profiles

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/profiles.rb,
lib/courier/resources/profiles/lists.rb,
sig/courier/resources/profiles.rbs,
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.

Defined Under Namespace

Classes: Lists

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Profiles

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 Profiles.

Parameters:



155
156
157
158
# File 'lib/courier/resources/profiles.rb', line 155

def initialize(client:)
  @client = client
  @lists = Courier::Resources::Profiles::Lists.new(client: client)
end

Instance Attribute Details

#listsCourier::Resources::Profiles::Lists (readonly)

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



11
12
13
# File 'lib/courier/resources/profiles.rb', line 11

def lists
  @lists
end

Instance Method Details

#create(user_id, profile:, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::ProfileCreateResponse

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

Merges the supplied values into a user's profile, creating it if absent and leaving any key you omit untouched. Prefer this for everyday writes.

Parameters:

  • user_id (String)

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

  • profile (Hash{Symbol=>Object})

    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:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/courier/resources/profiles.rb', line 34

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

#delete(user_id, request_options: {}) ⇒ nil

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

Deletes a user's profile and stored contact details. List subscriptions and preferences are separate resources, so remove those too if required.

Parameters:

  • user_id (String)

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

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

Returns:

  • (nil)

See Also:



115
116
117
118
119
120
121
122
# File 'lib/courier/resources/profiles.rb', line 115

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

#replace(user_id, profile:, request_options: {}) ⇒ Courier::Models::ProfileReplaceResponse

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

Overwrites a user profile in full, removing any key absent from the request body. Use the patch endpoint when changing a single field.

Parameters:

  • user_id (String)

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

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

Returns:

See Also:



141
142
143
144
145
146
147
148
149
150
# File 'lib/courier/resources/profiles.rb', line 141

def replace(user_id, params)
  parsed, options = Courier::ProfileReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["profiles/%1$s", user_id],
    body: parsed,
    model: Courier::Models::ProfileReplaceResponse,
    options: options
  )
end

#retrieve(user_id, request_options: {}) ⇒ Courier::Models::ProfileRetrieveResponse

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

Returns a user's stored profile and preferences, including the email address, phone number, and push tokens Courier can reach them on.

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:



63
64
65
66
67
68
69
70
# File 'lib/courier/resources/profiles.rb', line 63

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

#update(user_id, patch:, request_options: {}) ⇒ nil

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

Applies a JSON Patch to a user profile, adding, removing, or replacing individual fields without sending the whole object.

Parameters:

Returns:

  • (nil)

See Also:



89
90
91
92
93
94
95
96
97
98
# File 'lib/courier/resources/profiles.rb', line 89

def update(user_id, params)
  parsed, options = Courier::ProfileUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["profiles/%1$s", user_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end