Class: VoiceML::IncomingPhoneNumbersResource

Inherits:
BaseResource show all
Defined in:
lib/voiceml/resources/incoming_phone_numbers.rb

Overview

Operations on ‘/IncomingPhoneNumbers` — tenant-scoped DID lookup and routing.

Twilio-compatible: ‘sid` is the canonical `PN`-prefixed identifier, `phone_number` is the E.164 form. The standard lookup-by-number pattern (`list(phone_number: ’+1…‘)` returning a 0-or-1-row envelope, then `get(sid)`) is supported.

Constant Summary collapse

LIST_FIELDS =
{
  'PhoneNumber' => :phone_number,
  'Page'        => :page,
  'PageSize'    => :page_size,
  'PageToken'   => :page_token
}.freeze
CREATE_FIELDS =
{
  'PhoneNumber'         => :phone_number,
  'VoiceUrl'            => :voice_url,
  'VoiceMethod'         => :voice_method,
  'VoiceFallbackUrl'    => :voice_fallback_url,
  'VoiceFallbackMethod' => :voice_fallback_method,
  'FriendlyName'        => :friendly_name
}.freeze
UPDATE_FIELDS =
{
  'VoiceUrl'            => :voice_url,
  'VoiceMethod'         => :voice_method,
  'VoiceFallbackUrl'    => :voice_fallback_url,
  'VoiceFallbackMethod' => :voice_fallback_method,
  'FriendlyName'        => :friendly_name
}.freeze
LIST_TYPED_FIELDS =
{
  'PhoneNumber'  => :phone_number,
  'FriendlyName' => :friendly_name,
  'Beta'         => :beta,
  'Origin'       => :origin,
  'Page'         => :page,
  'PageSize'     => :page_size,
  'PageToken'    => :page_token
}.freeze

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from VoiceML::BaseResource

Instance Method Details

#create(phone_number:, voice_url: nil, voice_method: nil, voice_fallback_url: nil, voice_fallback_method: nil, friendly_name: nil) ⇒ VoiceML::IncomingPhoneNumber

Assign a DID to the authenticated tenant. Idempotent re-POSTing the same ‘phone_number:` rebinds the voice routing (matches Twilio update semantics).

Parameters:

  • phone_number (String)

    required. E.164 — leading ‘+`, 7-15 digits.

  • voice_url (String, nil) (defaults to: nil)

    inbound-voice handler URL.

  • voice_method (String, nil) (defaults to: nil)

    HTTP method for ‘voice_url` (`GET`/`POST`).

  • voice_fallback_url (String, nil) (defaults to: nil)

    fallback handler URL.

  • voice_fallback_method (String, nil) (defaults to: nil)

    HTTP method for ‘voice_fallback_url`.

  • friendly_name (String, nil) (defaults to: nil)

    display label (server may ignore in v0.5.x).

Returns:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 72

def create(phone_number:, voice_url: nil, voice_method: nil,
           voice_fallback_url: nil, voice_fallback_method: nil,
           friendly_name: nil)
  kwargs = {
    phone_number: phone_number,
    voice_url: voice_url, voice_method: voice_method,
    voice_fallback_url: voice_fallback_url,
    voice_fallback_method: voice_fallback_method,
    friendly_name: friendly_name
  }
  IncomingPhoneNumber.from_hash(
    @transport.request(:post, path('IncomingPhoneNumbers'),
                       form: form_params(CREATE_FIELDS, kwargs))
  )
end

#create_local(**kwargs) ⇒ VoiceML::IncomingPhoneNumber



122
123
124
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 122

def create_local(**kwargs)
  create_typed('Local', kwargs)
end

#create_mobile(**kwargs) ⇒ VoiceML::IncomingPhoneNumber



132
133
134
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 132

def create_mobile(**kwargs)
  create_typed('Mobile', kwargs)
end

#create_toll_free(**kwargs) ⇒ VoiceML::IncomingPhoneNumber



142
143
144
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 142

def create_toll_free(**kwargs)
  create_typed('TollFree', kwargs)
end

#delete(sid) ⇒ nil

Release a DID from the authenticated tenant. Idempotent — 204 even if already gone.

Returns:

  • (nil)


111
112
113
114
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 111

def delete(sid)
  @transport.request(:delete, path('IncomingPhoneNumbers', sid))
  nil
end

#get(sid) ⇒ VoiceML::IncomingPhoneNumber

Fetch a single DID by its ‘PN`-prefixed sid.



90
91
92
93
94
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 90

def get(sid)
  IncomingPhoneNumber.from_hash(
    @transport.request(:get, path('IncomingPhoneNumbers', sid))
  )
end

#list(phone_number: nil, page: nil, page_size: nil) ⇒ VoiceML::IncomingPhoneNumberList

List DIDs assigned to the authenticated tenant.

Parameters:

  • phone_number (String, nil) (defaults to: nil)

    exact-match E.164 filter. Returns a 0-or-1-row envelope when set — the standard twilio-ruby lookup pattern.

  • page (Integer, nil) (defaults to: nil)

    0-indexed page number.

  • page_size (Integer, nil) (defaults to: nil)

    page size (server-bounded).

Returns:



54
55
56
57
58
59
60
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 54

def list(phone_number: nil, page: nil, page_size: nil)
  kwargs = { phone_number: phone_number, page: page, page_size: page_size }
  IncomingPhoneNumberList.from_hash(
    @transport.request(:get, path('IncomingPhoneNumbers'),
                       params: form_params(LIST_FIELDS, kwargs))
  )
end

#list_local(**kwargs) ⇒ VoiceML::IncomingPhoneNumberList



117
118
119
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 117

def list_local(**kwargs)
  list_typed('Local', kwargs)
end

#list_mobile(**kwargs) ⇒ VoiceML::IncomingPhoneNumberList



127
128
129
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 127

def list_mobile(**kwargs)
  list_typed('Mobile', kwargs)
end

#list_toll_free(**kwargs) ⇒ VoiceML::IncomingPhoneNumberList



137
138
139
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 137

def list_toll_free(**kwargs)
  list_typed('TollFree', kwargs)
end

#update(sid, **opts) ⇒ VoiceML::IncomingPhoneNumber

Update voice routing on an assigned DID. Only set fields are touched.

Parameters:

  • sid (String)

    the ‘PN`-prefixed identifier.

  • opts (Hash)

    any of ‘voice_url:`, `voice_method:`, `voice_fallback_url:`, `voice_fallback_method:`, `friendly_name:`.

Returns:



102
103
104
105
106
107
# File 'lib/voiceml/resources/incoming_phone_numbers.rb', line 102

def update(sid, **opts)
  IncomingPhoneNumber.from_hash(
    @transport.request(:post, path('IncomingPhoneNumbers', sid),
                       form: form_params(UPDATE_FIELDS, opts))
  )
end