Class: Plivo::Resources::Numbers
- Inherits:
-
Base::Resource
- Object
- Base::Resource
- Plivo::Resources::Numbers
- Defined in:
- lib/plivo/resources/powerpacks.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from Base::Resource
Instance Method Summary collapse
- #add(number, options = nil) ⇒ Object
- #buy_add_number(options = nil) ⇒ Object
- #count(options = nil) ⇒ Object
- #find(number, options = nil) ⇒ Object
-
#initialize(client, options = nil) ⇒ Numbers
constructor
A new instance of Numbers.
- #list(options = nil) ⇒ Object
- #remove(number, unrent = false) ⇒ 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, options = nil) ⇒ Numbers
Returns a new instance of Numbers.
359 360 361 362 363 |
# File 'lib/plivo/resources/powerpacks.rb', line 359 def initialize(client, = nil) @_name = 'Numbers' @_identifier_string = 'number_pool_id' super end |
Instance Method Details
#add(number, options = nil) ⇒ Object
467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/plivo/resources/powerpacks.rb', line 467 def add(number, = nil) if .nil? return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s , 'POST') end params = {} if .key?(:service) && valid_param?(:service, [:service], String, true) params[:service] = [:service] end perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s , 'POST', params) end |
#buy_add_number(options = nil) ⇒ Object
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/plivo/resources/powerpacks.rb', line 486 def buy_add_number( = nil) params = {} params[:rent] = true if .key?(:service) && valid_param?(:service, [:service], String, true) params[:service] = [:service] end if .key?(:number) return perform_custom_action_apiresponse('NumberPool/' + number_pool_id + '/Number/' + [:number].to_s , 'POST', params) end if .key?(:country_iso2).nil? raise_invalid_request('country_iso is cannot be empty') end params = {} %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 if .key?(:pattern) && valid_param?(:pattern, [:pattern], String, true) params[:starts_with] = [:pattern] end if .key?(:country_iso2) && valid_param?(:country_iso2, [:country_iso2], String, true) params[:country_iso] = [:country_iso2] end if .key?(:type) && valid_param?(:type, [:type], String, true) params[:type] = [:type] end response = perform_custom_action_apiresponse('PhoneNumber', 'GET', params, true) numbers = response['objects'][0]['number'] params[:rent] = true perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + numbers.to_s, 'POST', params) end |
#count(options = nil) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/plivo/resources/powerpacks.rb', line 405 def count( = nil) if .nil? response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number', 'GET') = response['meta'] return ['total_count'] end params = {} %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 if .key?(:pattern) && valid_param?(:pattern, [:pattern], String, true) params[:starts_with] = [:pattern] end if .key?(:country_iso2) && valid_param?(:country_iso2, [:country_iso2], String, true) params[:country_iso2] = [:country_iso2] end if .key?(:type) && valid_param?(:type, [:type], String, true) params[:type] = [:type] end if .key?(:service) && valid_param?(:service, [:service], String, true) params[:service] = [:service] end response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number', 'GET', params, true) = response['meta'] return ['total_count'] end |
#find(number, options = nil) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/plivo/resources/powerpacks.rb', line 453 def find(number, = nil) if .nil? return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s , 'GET') end params = {} if .key?(:service) && valid_param?(:service, [:service], String, true) params[:service] = [:service] end perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s , 'GET', params) end |
#list(options = nil) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/plivo/resources/powerpacks.rb', line 365 def list( = nil) return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number', 'GET') if .nil? params = {} %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 if .key?(:pattern) && valid_param?(:pattern, [:pattern], String, true) params[:starts_with] = [:pattern] end if .key?(:country_iso2) && valid_param?(:country_iso2, [:country_iso2], String, true) params[:country_iso2] = [:country_iso2] end if .key?(:type) && valid_param?(:type, [:type], String, true) params[:type] = [:type] end if .key?(:service) && valid_param?(:service, [:service], String, true) params[:service] = [:service] end perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number', 'GET', params, true) end |
#remove(number, unrent = false) ⇒ Object
481 482 483 484 |
# File 'lib/plivo/resources/powerpacks.rb', line 481 def remove(number, unrent= false) perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s , 'DELETE', { unrent: unrent }, false) end |