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:



158
159
160
# File 'lib/sentdm/resources/contacts.rb', line 158

def initialize(client:)
  @client = client
end

Instance Method Details

#create(phone_number: nil, test_mode: nil, idempotency_key: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseContact

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

  • test_mode (Boolean)

    Body param: Test mode flag - when true, the operation is simulated without side

  • idempotency_key (String)

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

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

Returns:

See Also:



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

def create(params = {})
  parsed, options = Sentdm::ContactCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @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::APIResponseContact,
    options: options
  )
end

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

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

Parameters:

Returns:

  • (nil)

See Also:



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/sentdm/resources/contacts.rb', line 143

def delete(id, params)
  parsed, options = Sentdm::ContactDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v3/contacts/%1$s", id],
    headers: {"content-type" => "*/*"},
    body: parsed[:body],
    model: NilClass,
    options: options
  )
end

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

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

Parameters:

  • page (Integer)

    Page number (1-indexed)

  • page_size (Integer)
  • channel (String, nil)

    Optional channel filter (sms, whatsapp)

  • phone (String, nil)

    Optional phone number filter (alternative to list view)

  • search (String, nil)

    Optional search term for filtering contacts

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

Returns:

See Also:



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/sentdm/resources/contacts.rb', line 117

def list(params)
  parsed, options = Sentdm::ContactListParams.dump_request(params)
  query = Sentdm::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v3/contacts",
    query: query.transform_keys(page_size: "pageSize"),
    model: Sentdm::Models::ContactListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Sentdm::Models::APIResponseContact

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

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

Returns:

See Also:



52
53
54
55
56
57
58
59
# File 'lib/sentdm/resources/contacts.rb', line 52

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["v3/contacts/%1$s", id],
    model: Sentdm::APIResponseContact,
    options: params[:request_options]
  )
end

#update(id, default_channel: nil, opt_out: nil, test_mode: nil, idempotency_key: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseContact

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

  • 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

  • test_mode (Boolean)

    Body param: Test mode flag - when true, the operation is simulated without side

  • idempotency_key (String)

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

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

Returns:

See Also:



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sentdm/resources/contacts.rb', line 84

def update(id, params = {})
  parsed, options = Sentdm::ContactUpdateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @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::APIResponseContact,
    options: options
  )
end