Class: SurgeAPI::Resources::Contacts

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

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:



124
125
126
# File 'lib/surge_api/resources/contacts.rb', line 124

def initialize(client:)
  @client = client
end

Instance Method Details

#create(account_id, phone_number:, email: nil, first_name: nil, last_name: nil, metadata: nil, request_options: {}) ⇒ SurgeAPI::Models::Contact

Creates a new Contact object.

Parameters:

  • account_id (String)

    The account for which the contact should be created.

  • phone_number (String)

    The contact’s phone number in E.164 format.

  • email (String)

    The contact’s email address.

  • first_name (String)

    The contact’s first name.

  • last_name (String)

    The contact’s last name.

  • metadata (Hash{Symbol=>String})

    Set of key-value pairs that will be stored with the object.

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

Returns:

See Also:



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

def create(, params)
  parsed, options = SurgeAPI::ContactCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["accounts/%1$s/contacts", ],
    body: parsed,
    model: SurgeAPI::Contact,
    options: options
  )
end

#list(account_id, after: nil, before: nil, request_options: {}) ⇒ SurgeAPI::Internal::Cursor<SurgeAPI::Models::Contact>

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

List all contacts for an account with cursor-based pagination.

Parameters:

  • account_id (String)

    The account ID to list contacts for.

  • after (String)

    Cursor for forward pagination. Use the next_cursor from a previous response.

  • before (String)

    Cursor for backward pagination. Use the previous_cursor from a previous response

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

Returns:

See Also:



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/surge_api/resources/contacts.rb', line 109

def list(, params = {})
  parsed, options = SurgeAPI::ContactListParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["accounts/%1$s/contacts", ],
    query: parsed,
    page: SurgeAPI::Internal::Cursor,
    model: SurgeAPI::Contact,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ SurgeAPI::Models::Contact

Retrieves a Contact object.

Parameters:

  • id (String)

    The ID of the contact to retrieve.

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

Returns:

See Also:



49
50
51
52
53
54
55
56
# File 'lib/surge_api/resources/contacts.rb', line 49

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

#update(id, phone_number:, email: nil, first_name: nil, last_name: nil, metadata: nil, request_options: {}) ⇒ SurgeAPI::Models::Contact

Updates the specified contact by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

Parameters:

  • id (String)

    The ID of the contact to update.

  • phone_number (String)

    The contact’s phone number in E.164 format.

  • email (String)

    The contact’s email address.

  • first_name (String)

    The contact’s first name.

  • last_name (String)

    The contact’s last name.

  • metadata (Hash{Symbol=>String})

    Set of key-value pairs that will be stored with the object.

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

Returns:

See Also:



80
81
82
83
84
85
86
87
88
89
# File 'lib/surge_api/resources/contacts.rb', line 80

def update(id, params)
  parsed, options = SurgeAPI::ContactUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["contacts/%1$s", id],
    body: parsed,
    model: SurgeAPI::Contact,
    options: options
  )
end