class Twilio::REST::Messaging::V1::ServiceContext::ShortCodeList
PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
Public Class Methods
Initialize the ShortCodeList
@param [Version] version Version
that contains the resource @param [String] service_sid The SID of the
{Service}[https://www.twilio.com/docs/chat/rest/service-resource] the resource is associated with.
@return [ShortCodeList] ShortCodeList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/messaging/v1/service/short_code.rb 24 def initialize(version, service_sid: nil) 25 super(version) 26 27 # Path Solution 28 @solution = {service_sid: service_sid} 29 @uri = "/Services/#{@solution[:service_sid]}/ShortCodes" 30 end
Public Instance Methods
Create the ShortCodeInstance
@param [String] short_code_sid The SID of the ShortCode resource being added to
the Service.
@return [ShortCodeInstance] Created ShortCodeInstance
# File lib/twilio-ruby/rest/messaging/v1/service/short_code.rb 37 def create(short_code_sid: nil) 38 data = Twilio::Values.of({'ShortCodeSid' => short_code_sid, }) 39 40 payload = @version.create('POST', @uri, data: data) 41 42 ShortCodeInstance.new(@version, payload, service_sid: @solution[:service_sid], ) 43 end
When passed a block, yields ShortCodeInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/messaging/v1/service/short_code.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 ShortCodeInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of ShortCodeInstance
# File lib/twilio-ruby/rest/messaging/v1/service/short_code.rb 117 def get_page(target_url) 118 response = @version.domain.request( 119 'GET', 120 target_url 121 ) 122 ShortCodePage.new(@version, response, @solution) 123 end
Lists ShortCodeInstance
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/messaging/v1/service/short_code.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 ShortCodeInstance
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 ShortCodeInstance
# File lib/twilio-ruby/rest/messaging/v1/service/short_code.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 ShortCodePage.new(@version, response, @solution) 110 end
Streams ShortCodeInstance
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/messaging/v1/service/short_code.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/messaging/v1/service/short_code.rb 127 def to_s 128 '#<Twilio.Messaging.V1.ShortCodeList>' 129 end