class Twilio::REST::Trunking::V1::TrunkContext::PhoneNumberList
Public Class Methods
Initialize the PhoneNumberList
@param [Version] version Version
that contains the resource @param [String] trunk_sid The SID of the Trunk that handles calls to the phone
number. If a `trunk_sid` is present, we ignore all of the voice URLs and voice applications and use those set on the Trunk. Setting a `trunk_sid` will automatically delete your `voice_application_sid` and vice versa.
@return [PhoneNumberList] PhoneNumberList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 23 def initialize(version, trunk_sid: nil) 24 super(version) 25 26 # Path Solution 27 @solution = {trunk_sid: trunk_sid} 28 @uri = "/Trunks/#{@solution[:trunk_sid]}/PhoneNumbers" 29 end
Public Instance Methods
Create the PhoneNumberInstance
@param [String] phone_number_sid The SID of the {Incoming Phone
Number}[https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource] that you want to associate with the trunk.
@return [PhoneNumberInstance] Created PhoneNumberInstance
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 37 def create(phone_number_sid: nil) 38 data = Twilio::Values.of({'PhoneNumberSid' => phone_number_sid, }) 39 40 payload = @version.create('POST', @uri, data: data) 41 42 PhoneNumberInstance.new(@version, payload, trunk_sid: @solution[:trunk_sid], ) 43 end
When passed a block, yields PhoneNumberInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 83 def each 84 limits = @version.read_limits 85 86 page = self.page(page_size: limits[:page_size], ) 87 88 @version.stream(page, 89 limit: limits[:limit], 90 page_limit: limits[:page_limit]).each {|x| yield x} 91 end
Retrieve a single page of PhoneNumberInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of PhoneNumberInstance
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 117 def get_page(target_url) 118 response = @version.domain.request( 119 'GET', 120 target_url 121 ) 122 PhoneNumberPage.new(@version, response, @solution) 123 end
Lists PhoneNumberInstance
records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. @param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Array] Array of up to limit results
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 56 def list(limit: nil, page_size: nil) 57 self.stream(limit: limit, page_size: page_size).entries 58 end
Retrieve a single page of PhoneNumberInstance
records from the API. Request
is executed immediately. @param [String] page_token PageToken provided by the API @param [Integer] page_number Page
Number, this value is simply for client state @param [Integer] page_size Number of records to return, defaults to 50 @return [Page] Page
of PhoneNumberInstance
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 100 def page(page_token: :unset, page_number: :unset, page_size: :unset) 101 params = Twilio::Values.of({ 102 'PageToken' => page_token, 103 'Page' => page_number, 104 'PageSize' => page_size, 105 }) 106 107 response = @version.page('GET', @uri, params: params) 108 109 PhoneNumberPage.new(@version, response, @solution) 110 end
Streams PhoneNumberInstance
records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached. @param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit.
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Enumerable] Enumerable that will yield up to limit results
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 71 def stream(limit: nil, page_size: nil) 72 limits = @version.read_limits(limit, page_size) 73 74 page = self.page(page_size: limits[:page_size], ) 75 76 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 77 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb 127 def to_s 128 '#<Twilio.Trunking.V1.PhoneNumberList>' 129 end