Sha256: b845f86ad8519024ee61a373936ab98edf27375bbc6c1cf6838b87cfc0fa42b4

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module Twilio
  # 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)
  class AvailablePhoneNumbers < TwilioObject

    # The Search method handles the searching of both local and toll-free 
    # numbers. 
    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

    # 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
    def search_local(opts ={})
      opts = {:resource => 'Local'}.merge(opts)
      search(opts)
    end

    # The search_toll_free method searches for available toll-free numbers
    # Search Options
    #   :area_code
    #   :contains
    #   :page
    #   :page_size
    def search_toll_free(opts ={})
      opts = {:resource => 'TollFree'}.merge(opts)
      search(opts)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twilio-3.1.1 lib/twilio/available_phone_numbers.rb