class Plivo::Resources::PhoneNumberInterface
Public Class Methods
Plivo::Base::ResourceInterface::new
# File lib/plivo/resources/numbers.rb, line 48 def initialize(client, resource_list_json = nil) @_name = 'PhoneNumber' @_resource_type = PhoneNumber @_identifier_string = 'number' super end
Public Instance Methods
# File lib/plivo/resources/numbers.rb, line 124 def buy(number, app_id = nil, verification_info = nil, cnam_lookup = nil) valid_param?(:number, number, [Integer, String, Symbol], true) PhoneNumber.new(@_client, resource_id: number).buy(app_id, verification_info, cnam_lookup) end
# File lib/plivo/resources/numbers.rb, line 114 def each(country_iso) offset = 0 loop do phone_number_list = search(country_iso, offset: offset) phone_number_list[:objects].each { |phone_number| yield phone_number } offset += 20 return unless number_list.length == 20 end end
@param [String] country_iso The ISO code A2 of the country ( BE for Belgium, DE for Germany, GB for United Kingdom, US for United States etc ). See the Wikipedia site for a list of ISOs for different countries. @param [Hash] options @option options [String] :type The type of number you are looking for. The possible number types are fixed, mobile and tollfree. Defaults to any if this field is not specified. type also accepts the value any, which will search for all 3 number types. @option options [String] :pattern Represents the pattern of the number to be searched. Adding a pattern will search for numbers which start with the country code + pattern. For eg. a pattern of 415 and a country_iso: US will search for numbers starting with 1415. @option options [String] :region This filter is only applicable when the type is fixed. If the type is not provided, it is assumed to be fixed. Region based filtering can be performed with the following terms:
- Exact names of the region: You could use region=Frankfurt if you were looking for a number in Frankfurt. Performed if the search term is three or more characters in length.
@option options [String] :services Filters out phone numbers according to the services you want from that number. The following values are valid:
- voice - If this option is selected, it ensures that the results have voice enabled numbers. These numbers may or may not be SMS enabled. - voice,sms - If this option is selected, it ensures that the results have both voice and sms enabled on the same number. - sms - If this option is selected, it ensures that the results have sms enabled numbers. These numbers may or may not be voice enabled. - By default, numbers that have either voice or sms or both enabled are returned.
@option options [String] :lata Numbers
can be searched using Local Access and Transport Area {en.wikipedia.org/wiki/Local_access_and_transport_area}. This filter is applicable only for country_iso US and CA. @option options [String] :rate_center Numbers
can be searched using Rate Center {en.wikipedia.org/wiki/Telephone_exchange}. This filter is application only for country_iso US and CA. @option options [String] :city Filter phone number based on the city name. This filter is only applicable when the type is Local @option options [Boolean] :eligible If set to true, lists only those numbers that you are eligible to buy at the moment. To list all numbers, ignore this option. @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20. @option options [Int] :offset Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
# File lib/plivo/resources/numbers.rb, line 72 def search(country_iso, options = nil) valid_param?(:country_iso, country_iso, [String, Symbol], true) unless country_iso.length == 2 raise_invalid_request('country_iso should be of length 2') end params = { country_iso: country_iso } return perform_list(params) if options.nil? %i[type pattern region services lata rate_center city].each do |param| if options.key?(param) && valid_param?(param, options[param], [String, Symbol], true) params[param] = options[param] end end %i[offset limit].each do |param| if options.key?(param) && valid_param?(param, options[param], [Integer, Integer], true) params[param] = options[param] end end %i[eligible].each do |param| if options.key?(param) && valid_param?(param, options[param], nil, true, [true, false]) params[param] = options[param] end end if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0) raise_invalid_request('The maximum number of results that can be '\ "fetched is 20. limit can't be more than 20 or less than 1") end if options.key?(:offset) && options[:offset] < 0 raise_invalid_request("Offset can't be negative") end perform_list(params) end