class Twilio::REST::Autopilot::V1::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 SID of the
{Assistant}[https://www.twilio.com/docs/autopilot/api/assistant] that is the parent of the Task associated with the resource.
@param [String] task_sid The SID of the
{Task}[https://www.twilio.com/docs/autopilot/api/task] associated with the resource.
@return [SampleList] SampleList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/autopilot/v1/assistant/task/sample.rb 28 def initialize(version, assistant_sid: nil, task_sid: nil) 29 super(version) 30 31 # Path Solution 32 @solution = {assistant_sid: assistant_sid, task_sid: task_sid} 33 @uri = "/Assistants/#{@solution[:assistant_sid]}/Tasks/#{@solution[:task_sid]}/Samples" 34 end
Public Instance Methods
Create the SampleInstance
@param [String] language The {ISO
language-country}[https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html] string that specifies the language used for the new sample. For example: `en-US`.
@param [String] tagged_text The text example of how end users might express the
task. The sample can contain {Field tag blocks}[https://www.twilio.com/docs/autopilot/api/task-sample#field-tagging].
@param [String] source_channel The communication channel from which the new
sample was captured. Can be: `voice`, `sms`, `chat`, `alexa`, `google-assistant`, `slack`, or null if not included.
@return [SampleInstance] Created SampleInstance
# File lib/twilio-ruby/rest/autopilot/v1/assistant/task/sample.rb 139 def create(language: nil, tagged_text: nil, source_channel: :unset) 140 data = Twilio::Values.of({ 141 'Language' => language, 142 'TaggedText' => tagged_text, 143 'SourceChannel' => source_channel, 144 }) 145 146 payload = @version.create('POST', @uri, data: data) 147 148 SampleInstance.new( 149 @version, 150 payload, 151 assistant_sid: @solution[:assistant_sid], 152 task_sid: @solution[:task_sid], 153 ) 154 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/autopilot/v1/assistant/task/sample.rb 80 def each 81 limits = @version.read_limits 82 83 page = self.page(page_size: limits[:page_size], ) 84 85 @version.stream(page, 86 limit: limits[:limit], 87 page_limit: limits[:page_limit]).each {|x| yield x} 88 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/autopilot/v1/assistant/task/sample.rb 118 def get_page(target_url) 119 response = @version.domain.request( 120 'GET', 121 target_url 122 ) 123 SamplePage.new(@version, response, @solution) 124 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 The {ISO
language-country}[https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html] string that specifies the language used for the sample. For example: `en-US`.
@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/autopilot/v1/assistant/task/sample.rb 50 def list(language: :unset, limit: nil, page_size: nil) 51 self.stream(language: language, limit: limit, page_size: page_size).entries 52 end
Retrieve a single page of SampleInstance
records from the API. Request
is executed immediately. @param [String] language The {ISO
language-country}[https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html] string that specifies the language used for the sample. For example: `en-US`.
@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/autopilot/v1/assistant/task/sample.rb 100 def page(language: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 101 params = Twilio::Values.of({ 102 'Language' => language, 103 'PageToken' => page_token, 104 'Page' => page_number, 105 'PageSize' => page_size, 106 }) 107 108 response = @version.page('GET', @uri, params: params) 109 110 SamplePage.new(@version, response, @solution) 111 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 The {ISO
language-country}[https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html] string that specifies the language used for the sample. For example: `en-US`.
@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/autopilot/v1/assistant/task/sample.rb 68 def stream(language: :unset, limit: nil, page_size: nil) 69 limits = @version.read_limits(limit, page_size) 70 71 page = self.page(language: language, page_size: limits[:page_size], ) 72 73 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 74 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/autopilot/v1/assistant/task/sample.rb 158 def to_s 159 '#<Twilio.Autopilot.V1.SampleList>' 160 end