Class: Plivo::Resources::PhoneNumberInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::PhoneNumberInterface
- Defined in:
- lib/plivo/resources/numbers.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #buy(number, app_id = nil, verification_info = nil) ⇒ Object
- #each(country_iso) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ PhoneNumberInterface
constructor
A new instance of PhoneNumberInterface.
- #search(country_iso, options = nil) ⇒ Object
Methods included from Utils
expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ PhoneNumberInterface
Returns a new instance of PhoneNumberInterface.
42 43 44 45 46 47 |
# File 'lib/plivo/resources/numbers.rb', line 42 def initialize(client, resource_list_json = nil) @_name = 'PhoneNumber' @_resource_type = PhoneNumber @_identifier_string = 'number' super end |
Instance Method Details
#buy(number, app_id = nil, verification_info = nil) ⇒ Object
117 118 119 120 121 |
# File 'lib/plivo/resources/numbers.rb', line 117 def buy(number, app_id = nil, verification_info = nil) valid_param?(:number, number, [Integer, String, Symbol], true) PhoneNumber.new(@_client, resource_id: number).buy(app_id, verification_info) end |
#each(country_iso) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/plivo/resources/numbers.rb', line 107 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 |
#search(country_iso, options = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/plivo/resources/numbers.rb', line 65 def search(country_iso, = 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 .nil? %i[type pattern region services lata rate_center].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer, Integer], true) params[param] = [param] end end %i[eligible].each do |param| if .key?(param) && valid_param?(param, [param], nil, true, [true, false]) params[param] = [param] end end if .key?(:limit) && ([:limit] > 20 || [: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 .key?(:offset) && [:offset] < 0 raise_invalid_request("Offset can't be negative") end perform_list(params) end |