Class: SurgeAPI::Resources::PhoneNumbers

Inherits:
Object
  • Object
show all
Defined in:
lib/surge_api/resources/phone_numbers.rb,
sig/surge_api/resources/phone_numbers.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ PhoneNumbers

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

Parameters:



185
186
187
# File 'lib/surge_api/resources/phone_numbers.rb', line 185

def initialize(client:)
  @client = client
end

Instance Method Details

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

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

List all phone numbers for an account with cursor-based pagination.

Parameters:

  • account_id (String)

    The account ID to list phone numbers 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:



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/surge_api/resources/phone_numbers.rb', line 70

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

#list_available_numbers(account_id, type:, after: nil, area_code: nil, before: nil, country: nil, request_options: {}) ⇒ SurgeAPI::Internal::Cursor<SurgeAPI::Models::PhoneNumberListAvailableNumbersResponse>

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

Browse purchasable phone numbers from Surge inventory before buying.

Pagination cursors are always null for now.

Parameters:

Returns:

See Also:



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

def list_available_numbers(, params)
  parsed, options = SurgeAPI::PhoneNumberListAvailableNumbersParams.dump_request(params)
  query = SurgeAPI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["accounts/%1$s/available_phone_numbers", ],
    query: query,
    page: SurgeAPI::Internal::Cursor,
    model: SurgeAPI::Models::PhoneNumberListAvailableNumbersResponse,
    options: options
  )
end

#purchase(account_id, area_code: nil, latitude: nil, longitude: nil, name: nil, phone_number: nil, type: nil, request_options: {}) ⇒ SurgeAPI::Models::PhoneNumber

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

Purchase a new phone number for the account. You can specify an exact phone number, search criteria, or let the system select a random number.

When phone_number is provided, all other search parameters are ignored.

Parameters:

  • account_id (String)

    The account for which the phone number should be created.

  • area_code (String)

    The desired area code for this phone number. If provided without type, the type

  • latitude (Float)

    Latitude to search for nearby phone numbers. Must be used with longitude. If pro

  • longitude (Float)

    Longitude to search for nearby phone numbers. Must be used with latitude. If pro

  • name (String)

    A human-readable name for the phone number. If not provided, defaults to the for

  • phone_number (String)

    The exact phone number to purchase in E.164 format. When provided, all other sea

  • type (Symbol, SurgeAPI::Models::PhoneNumberPurchaseParams::Type)

    Whether the phone number is local or toll-free. Can be omitted if area_code or l

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

Returns:

See Also:



151
152
153
154
155
156
157
158
159
160
# File 'lib/surge_api/resources/phone_numbers.rb', line 151

def purchase(, params = {})
  parsed, options = SurgeAPI::PhoneNumberPurchaseParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["accounts/%1$s/phone_numbers", ],
    body: parsed,
    model: SurgeAPI::PhoneNumber,
    options: options
  )
end

#release(id, request_options: {}) ⇒ SurgeAPI::Models::PhoneNumber

Releases a phone number from the account.

Parameters:

  • id (String)

    The ID of the phone number to release.

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

Returns:

See Also:



173
174
175
176
177
178
179
180
# File 'lib/surge_api/resources/phone_numbers.rb', line 173

def release(id, params = {})
  @client.request(
    method: :delete,
    path: ["phone_numbers/%1$s", id],
    model: SurgeAPI::PhoneNumber,
    options: params[:request_options]
  )
end

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

Retrieves a PhoneNumber object.

Parameters:

  • id (String)

    The ID of the phone number to retrieve.

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

Returns:

See Also:



17
18
19
20
21
22
23
24
# File 'lib/surge_api/resources/phone_numbers.rb', line 17

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

#update(id, campaign_id: nil, name: nil, request_options: {}) ⇒ SurgeAPI::Models::PhoneNumber

Updates a phone number's details.

Parameters:

  • id (String)

    The ID of the phone number to update.

  • campaign_id (String)

    Campaign ID to attach this number to (cpn_...).

  • name (String)

    A human-readable name for the phone number.

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

Returns:

See Also:



41
42
43
44
45
46
47
48
49
50
# File 'lib/surge_api/resources/phone_numbers.rb', line 41

def update(id, params = {})
  parsed, options = SurgeAPI::PhoneNumberUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["phone_numbers/%1$s", id],
    body: parsed,
    model: SurgeAPI::PhoneNumber,
    options: options
  )
end