Class: Twilio::AvailablePhoneNumbers

Inherits:
TwilioObject show all
Defined in:
lib/twilio/available_phone_numbers.rb

Overview

An AvailablePhoneNumbers resources represents the available phone numbers that Twilio can provide you based on your search criteria. The valid query terms are outlined in the search methods. Example:

Twilio.connect('my_twilio_sid', 'my_auth_token')
Twilio.AvailablePhoneNumbers.search_local(:area_code => 541)

Instance Method Summary collapse

Methods inherited from TwilioObject

#connected?, #initialize, method_missing

Constructor Details

This class inherits a constructor from Twilio::TwilioObject

Instance Method Details

#search(opts = {}) ⇒ Object

The Search method handles the searching of both local and toll-free numbers.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/twilio/available_phone_numbers.rb', line 12

def search(opts={})
  iso_country_code = opts[:iso_country_code] || 'US'
  resource = opts.delete(:resource)

  params = {
    :AreaCode => opts[:area_code],
    :InPostalCode => opts[:postal_code],
    :InRegion => opts[:in_region],
    :Contains => opts[:contains],
    :NearLatLong => opts[:near_lat_long],
    :NearNumber => opts[:near_number],
    :InLata => opts[:in_lata],
    :InRateCenter => opts[:in_rate_center],
    :Distance => opts[:distance],
    :Page => opts[:page],
    :PageSize => opts[:page_size]
  }.reject {|k,v| v == nil} unless opts.empty?
  
  Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}", :query => params)
end

#search_local(opts = {}) ⇒ Object

The search_local method searches for numbers in local areas (i.e. state, zip, etc..) Search Options:

:area_code
:postal_code
:in_region
:contains
:near_lat_long
:near_number
:in_lata
:in_rate_center
:distance
:page
:page_size


46
47
48
49
# File 'lib/twilio/available_phone_numbers.rb', line 46

def search_local(opts ={})
  opts = {:resource => 'Local'}.merge(opts)
  search(opts)
end

#search_toll_free(opts = {}) ⇒ Object

The search_toll_free method searches for available toll-free numbers Search Options

:area_code
:contains
:page
:page_size


57
58
59
60
# File 'lib/twilio/available_phone_numbers.rb', line 57

def search_toll_free(opts ={})
  opts = {:resource => 'TollFree'}.merge(opts)
  search(opts)
end