Class: Nexmo::Numbers

Inherits:
Namespace
  • Object
show all
Defined in:
lib/nexmo/numbers.rb

Defined Under Namespace

Classes: ListResponse, Response

Instance Method Summary collapse

Instance Method Details

#buy(params) ⇒ Response

Request to purchase a specific inbound number.

Examples:

response = client.numbers.buy(country: 'GB', msisdn: '447700900000')

Parameters:

  • params (Hash)

Options Hash (params):

  • :country (required, String)

    The two character country code in ISO 3166-1 alpha-2 format.

  • :msisdn (required, String)

    An available inbound virtual number.

  • :target_api_key (String)

    If you’d like to perform an action on a subaccount, provide the ‘api_key` of that account here. If you’d like to perform an action on your own account, you do not need to provide this field.

Returns:

See Also:



119
120
121
# File 'lib/nexmo/numbers.rb', line 119

def buy(params)
  request('/number/buy', params: params, type: Post, response_class: Response)
end

#cancel(params) ⇒ Response

Cancel your subscription for a specific inbound number.

Examples:

response = client.numbers.cancel(country: 'GB', msisdn: '447700900000')

Parameters:

  • params (Hash)

Options Hash (params):

  • :country (required, String)

    The two character country code in ISO 3166-1 alpha-2 format.

  • :msisdn (required, String)

    An available inbound virtual number.

  • :target_api_key (String)

    If you’d like to perform an action on a subaccount, provide the ‘api_key` of that account here. If you’d like to perform an action on your own account, you do not need to provide this field.

Returns:

See Also:



144
145
146
# File 'lib/nexmo/numbers.rb', line 144

def cancel(params)
  request('/number/cancel', params: params, type: Post, response_class: Response)
end

#list(params = nil) ⇒ ListResponse

Retrieve all the inbound numbers associated with your Nexmo account.

Examples:

response = client.numbers.list
response.each do |item|
  puts "#{item.msisdn} #{item.country} #{item.type}"
end

Parameters:

  • params (Hash) (defaults to: nil)

Options Hash (params):

  • :application_id (String)

    The application that you want to return the numbers for.

  • :has_application (Boolean)

    Set this optional field to ‘true` to restrict your results to numbers associated with an application (any application). Set to `false` to find all numbers not associated with any application. Omit the field to avoid filtering on whether or not the number is assigned to an application.

  • :country (String)

    The two character country code to filter on (in ISO 3166-1 alpha-2 format).

  • :pattern (String)

    The number pattern you want to search for. Use in conjunction with :search_pattern.

  • :search_pattern (Integer)

    The strategy you want to use for matching:

    • ‘0` - Search for numbers that start with :pattern

    • ‘1` - Search for numbers that contain :pattern

    • ‘2` - Search for numbers that end with :pattern

  • :size (Integer)

    Page size.

  • :index (Integer)

    Page index.

Returns:

See Also:



50
51
52
# File 'lib/nexmo/numbers.rb', line 50

def list(params = nil)
  request('/account/numbers', params: params, response_class: ListResponse)
end

#search(params) ⇒ ListResponse

Retrieve inbound numbers that are available for the specified country.

Examples:

response = client.numbers.search(country: 'GB')
response.each do |item|
  puts "#{item.msisdn} #{item.type} #{item.cost}"
end

Parameters:

  • params (Hash)

Options Hash (params):

  • :country (required, String)

    The two character country code in ISO 3166-1 alpha-2 format.

  • :type (String)

    Set this parameter to filter the type of number, such as mobile or landline.

  • :pattern (String)

    The number pattern you want to search for. Use in conjunction with :search_pattern.

  • :search_pattern (Integer)

    The strategy you want to use for matching:

    • ‘0` - Search for numbers that start with :pattern

    • ‘1` - Search for numbers that contain :pattern

    • ‘2` - Search for numbers that end with :pattern

  • :features (String)

    Available features are ‘SMS` and `VOICE`. To look for numbers that support both, use a comma-separated value: `SMS,VOICE`.

  • :size (Integer)

    Page size.

  • :index (Integer)

    Page index.

Returns:

See Also:



94
95
96
# File 'lib/nexmo/numbers.rb', line 94

def search(params)
  request('/number/search', params: params, response_class: ListResponse)
end

#update(params) ⇒ Response

Change the behaviour of a number that you own.

Examples:

params = {
  country: 'GB',
  msisdn: '447700900000',
  voice_callback_type: 'app',
  voice_callback_value: application_id
}

response = client.numbers.update(params)

Parameters:

  • params (Hash)

Options Hash (params):

  • :country (required, String)

    The two character country code in ISO 3166-1 alpha-2 format.

  • :msisdn (required, String)

    An available inbound virtual number.

  • :mo_http_url (String)

    An URL-encoded URI to the webhook endpoint that handles inbound messages. Your webhook endpoint must be active before you make this request. Nexmo makes a ‘GET` request to the endpoint and checks that it returns a `200 OK` response. Set this parameter’s value to an empty string to remove the webhook.

  • :mo_smpp_sys_type (String)

    The associated system type for your SMPP client.

  • :voice_callback_type (String)

    Specify whether inbound voice calls on your number are handled by your Application configuration, or forwarded to a SIP or a telephone number. Must be used with the :voice_callback_value option.

  • :voice_callback_value (String)

    A SIP URI, telephone number or Application ID. Must be used with the :voice_callback_type option.

  • :voice_status_callback (String)

    A webhook URI for Nexmo to send a request to when a call ends.

Returns:

See Also:



192
193
194
# File 'lib/nexmo/numbers.rb', line 192

def update(params)
  request('/number/update', params: camelcase(params), type: Post, response_class: Response)
end