Class: Plivo::Resources::NumberInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::NumberInterface
- Defined in:
- lib/plivo/resources/numbers.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #add_number(numbers, carrier, region, options = nil) ⇒ Object
- #delete(number) ⇒ Object
- #each ⇒ Object
- #get(number) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ NumberInterface
constructor
A new instance of NumberInterface.
- #list(options = nil) ⇒ Object
- #update(number, options = nil) ⇒ Object
Methods included from Utils
GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ NumberInterface
Returns a new instance of NumberInterface.
194 195 196 197 198 199 |
# File 'lib/plivo/resources/numbers.rb', line 194 def initialize(client, resource_list_json = nil) @_name = 'Number' @_resource_type = Number @_identifier_string = 'number' super end |
Instance Method Details
#add_number(numbers, carrier, region, options = nil) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/plivo/resources/numbers.rb', line 296 def add_number(numbers, carrier, region, = nil) valid_param?(:carrier, carrier, [String, Symbol], true) valid_param?(:region, region, [String, Symbol], true) valid_param?(:numbers, numbers, Array, true) numbers.each do |number| valid_param?(:number, number, [Integer, String, Symbol], true) end params = { numbers: numbers.join(','), carrier: carrier, region: region } return perform_post(params) if .nil? if .key?(:subaccount) && valid_subaccount?([:subaccount], true) params[:subaccount] = [:subaccount] end %i[number_type app_id].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end perform_post(params) end |
#delete(number) ⇒ Object
340 341 342 343 |
# File 'lib/plivo/resources/numbers.rb', line 340 def delete(number) valid_param?(:number, number, [String, Symbol], true) Number.new(@_client, resource_id: number).delete end |
#each ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/plivo/resources/numbers.rb', line 279 def each offset = 0 loop do number_list = list(offset: offset) number_list[:objects].each { |number| yield number } offset += 20 return unless number_list.length == 20 end end |
#get(number) ⇒ Object
202 203 204 |
# File 'lib/plivo/resources/numbers.rb', line 202 def get(number) perform_get(number) end |
#list(options = nil) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/plivo/resources/numbers.rb', line 234 def list( = nil) return perform_list if .nil? valid_param?(:options, , Hash, true) params = {} %i[number_startswith subaccount alias tendlc_campaign_id tendlc_registration_status toll_free_sms_verification renewal_date renewal_date__lt renewal_date__lte renewal_date__gt renewal_date__gte cnam_lookup].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end if .key?(:services) && valid_param?(:services, [:services], [String, Symbol], true, %w[sms voice voice,sms]) params[:services] = [:services] end if .key?(:type) && valid_param?(:type, [:type], [String, Symbol], true, %w[local tollfree]) params[:type] = [:type] end %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer, Integer], true) 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 |