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.

Returns:

See Also:


111
112
113
# File 'lib/nexmo/numbers.rb', line 111

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.

Returns:

See Also:


132
133
134
# File 'lib/nexmo/numbers.rb', line 132

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):

  • :index (Integer)

    Page index.

  • :size (Integer)

    Page size.

  • :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

  • :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.

  • :application_id (String)

    The application that you want to return the numbers for.

Returns:

See Also:


46
47
48
# File 'lib/nexmo/numbers.rb', line 46

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:


90
91
92
# File 'lib/nexmo/numbers.rb', line 90

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.

  • :messages_callback_type (String)

    The SMS webhook type (always `app`). Must be used with the :messages_callback_value option.

  • :messages_callback_value (String)

    A Nexmo Application ID. Must be used with the :messages_callback_type option.

  • :voice_callback_type (String)

    The voice webhook type. 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:


188
189
190
# File 'lib/nexmo/numbers.rb', line 188

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