class Twilio::REST::Preview::Understand::AssistantContext::TaskContext::SampleList
PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
Public Class Methods
Initialize the SampleList
@param [Version] version Version
that contains the resource @param [String] assistant_sid The unique ID of the Assistant. @param [String] task_sid The unique ID of the Task associated with this Sample. @return [SampleList] SampleList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 24 def initialize(version, assistant_sid: nil, task_sid: nil) 25 super(version) 26 27 # Path Solution 28 @solution = {assistant_sid: assistant_sid, task_sid: task_sid} 29 @uri = "/Assistants/#{@solution[:assistant_sid]}/Tasks/#{@solution[:task_sid]}/Samples" 30 end
Public Instance Methods
Create the SampleInstance
@param [String] language An ISO language-country string of the sample. @param [String] tagged_text The text example of how end-users may express this
task. The sample may contain Field tag blocks.
@param [String] source_channel The communication channel the sample was
captured. It can be: *voice*, *sms*, *chat*, *alexa*, *google-assistant*, or *slack*. If not included the value will be null
@return [SampleInstance] Created SampleInstance
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 125 def create(language: nil, tagged_text: nil, source_channel: :unset) 126 data = Twilio::Values.of({ 127 'Language' => language, 128 'TaggedText' => tagged_text, 129 'SourceChannel' => source_channel, 130 }) 131 132 payload = @version.create('POST', @uri, data: data) 133 134 SampleInstance.new( 135 @version, 136 payload, 137 assistant_sid: @solution[:assistant_sid], 138 task_sid: @solution[:task_sid], 139 ) 140 end
When passed a block, yields SampleInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 72 def each 73 limits = @version.read_limits 74 75 page = self.page(page_size: limits[:page_size], ) 76 77 @version.stream(page, 78 limit: limits[:limit], 79 page_limit: limits[:page_limit]).each {|x| yield x} 80 end
Retrieve a single page of SampleInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of SampleInstance
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 108 def get_page(target_url) 109 response = @version.domain.request( 110 'GET', 111 target_url 112 ) 113 SamplePage.new(@version, response, @solution) 114 end
Lists SampleInstance
records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. @param [String] language An ISO language-country string of the sample. @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/preview/understand/assistant/task/sample.rb 44 def list(language: :unset, limit: nil, page_size: nil) 45 self.stream(language: language, limit: limit, page_size: page_size).entries 46 end
Retrieve a single page of SampleInstance
records from the API. Request
is executed immediately. @param [String] language An ISO language-country string of the sample. @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 SampleInstance
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 90 def page(language: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 91 params = Twilio::Values.of({ 92 'Language' => language, 93 'PageToken' => page_token, 94 'Page' => page_number, 95 'PageSize' => page_size, 96 }) 97 98 response = @version.page('GET', @uri, params: params) 99 100 SamplePage.new(@version, response, @solution) 101 end
Streams SampleInstance
records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached. @param [String] language An ISO language-country string of the sample. @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/preview/understand/assistant/task/sample.rb 60 def stream(language: :unset, limit: nil, page_size: nil) 61 limits = @version.read_limits(limit, page_size) 62 63 page = self.page(language: language, page_size: limits[:page_size], ) 64 65 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 66 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/preview/understand/assistant/task/sample.rb 144 def to_s 145 '#<Twilio.Preview.Understand.SampleList>' 146 end