Class: Sentdm::Resources::Contacts

Inherits:
Object
  • Object
show all
Defined in:
lib/sentdm/resources/contacts.rb

Overview

Create, update, and manage customer contact lists

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Contacts

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

Parameters:



183
184
185
# File 'lib/sentdm/resources/contacts.rb', line 183

def initialize(client:)
  @client = client
end

Instance Method Details

#create(phone_number: nil, sandbox: nil, idempotency_key: nil, x_profile_id: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseOfContact

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

Creates a new contact by phone number and associates it with the authenticated customer.

Parameters:

  • phone_number (String)

    Body param: Phone number of the contact to create

  • sandbox (Boolean)

    Body param: Sandbox flag - when true, the operation is simulated without side ef

  • idempotency_key (String)

    Header param: Unique key to ensure idempotent request processing. Must be 1-255

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sentdm/resources/contacts.rb', line 28

def create(params = {})
  parsed, options = Sentdm::ContactCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key", x_profile_id: "x-profile-id"}
  @client.request(
    method: :post,
    path: "v3/contacts",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Sentdm::APIResponseOfContact,
    options: options
  )
end

#delete(id, body:, x_profile_id: nil, request_options: {}) ⇒ nil

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

Dissociates a contact from the authenticated customer. Inherited contacts cannot be deleted.

Parameters:

  • id (String)

    Path param: Contact ID from route parameter

  • body (Sentdm::Models::ContactDeleteParams::Body)

    Body param: Request to delete/dissociate a contact

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

  • (nil)

See Also:



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/sentdm/resources/contacts.rb', line 168

def delete(id, params)
  parsed, options = Sentdm::ContactDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v3/contacts/%1$s", id],
    headers: parsed.except(:body).transform_keys(x_profile_id: "x-profile-id"),
    body: parsed[:body],
    model: NilClass,
    options: options
  )
end

#list(page:, page_size:, channel: nil, phone: nil, search: nil, x_profile_id: nil, request_options: {}) ⇒ Sentdm::Models::ContactListResponse

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

Retrieves a paginated list of contacts for the authenticated customer. Supports filtering by search term, channel, or phone number.

Parameters:

  • page (Integer)

    Query param: Page number (1-indexed)

  • page_size (Integer)

    Query param: Number of items per page

  • channel (String, nil)

    Query param: Optional channel filter (sms, whatsapp)

  • phone (String, nil)

    Query param: Optional phone number filter (alternative to list view)

  • search (String, nil)

    Query param: Optional search term for filtering contacts

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/sentdm/resources/contacts.rb', line 135

def list(params)
  query_params = [:page, :page_size, :channel, :phone, :search]
  parsed, options = Sentdm::ContactListParams.dump_request(params)
  query = Sentdm::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "v3/contacts",
    query: query,
    headers: parsed.except(*query_params).transform_keys(x_profile_id: "x-profile-id"),
    model: Sentdm::Models::ContactListResponse,
    options: options
  )
end

#retrieve(id, x_profile_id: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseOfContact

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

Retrieves a specific contact by their unique identifier. Returns detailed contact information including phone formats, available channels, and opt-out status.

Parameters:

  • id (String)

    Contact ID from route parameter

  • x_profile_id (String)

    Profile UUID to scope the request to a child profile. Only organization API keys

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

Returns:

See Also:



59
60
61
62
63
64
65
66
67
68
# File 'lib/sentdm/resources/contacts.rb', line 59

def retrieve(id, params = {})
  parsed, options = Sentdm::ContactRetrieveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v3/contacts/%1$s", id],
    headers: parsed.transform_keys(x_profile_id: "x-profile-id"),
    model: Sentdm::APIResponseOfContact,
    options: options
  )
end

#update(id, channel_consent: nil, default_channel: nil, opt_out: nil, sandbox: nil, idempotency_key: nil, x_profile_id: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseOfContact

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

Updates a contact’s default channel and/or opt-out status. Inherited contacts cannot be updated.

Parameters:

  • id (String)

    Path param: Contact ID from route parameter

  • channel_consent (Hash{Symbol=>String}, nil)

    Body param: Consent status by channel. Keys: “sms”, “whatsapp”. Values: “opted_i

  • default_channel (String, nil)

    Body param: Default messaging channel: “sms” or “whatsapp”

  • opt_out (Boolean, nil)

    Body param: Whether the contact has opted out of messaging

  • sandbox (Boolean)

    Body param: Sandbox flag - when true, the operation is simulated without side ef

  • idempotency_key (String)

    Header param: Unique key to ensure idempotent request processing. Must be 1-255

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sentdm/resources/contacts.rb', line 97

def update(id, params = {})
  parsed, options = Sentdm::ContactUpdateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key", x_profile_id: "x-profile-id"}
  @client.request(
    method: :patch,
    path: ["v3/contacts/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Sentdm::APIResponseOfContact,
    options: options
  )
end