class Twilio::REST::Proxy::V1::ServiceContext::SessionList
PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
Public Class Methods
Initialize the SessionList
@param [Version] version Version
that contains the resource @param [String] service_sid The SID of the
{Service}[https://www.twilio.com/docs/proxy/api/service] the session is associated with.
@return [SessionList] SessionList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/proxy/v1/service/session.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]}/Sessions" 30 end
Public Instance Methods
Create the SessionInstance
@param [String] unique_name An application-defined string that uniquely
identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
@param [Time] date_expiry The ISO 8601
date when the Session should expire. If this is value is present, it overrides the `ttl` value.
@param [String] ttl The time, in seconds, when the session will expire. The time
is measured from the last Session create or the Session's last Interaction.
@param [session.Mode] mode The Mode of the Session. Can be: `message-only`,
`voice-only`, or `voice-and-message` and the default value is `voice-and-message`.
@param [session.Status] status The initial status of the Session. Can be:
`open`, `in-progress`, `closed`, `failed`, or `unknown`. The default is `open` on create.
@param [Array] participants The Participant objects to include in the new
session.
@param [Boolean] fail_on_participant_conflict [Experimental] For accounts with
the ProxyAllowParticipantConflict account flag, setting to true enables per-request opt-in to allowing Proxy to reject a Session create (with Participants) request that could cause the same Identifier/ProxyIdentifier pair to be active in multiple Sessions. Depending on the context, this could be a 409 error (Twilio error code 80623) or a 400 error (Twilio error code 80604). If not provided, requests will be allowed to succeed and a Debugger notification (80802) will be emitted. Having multiple, active Participants with the same Identifier/ProxyIdentifier pair causes calls and messages from affected Participants to be routed incorrectly. Please note, the default behavior for accounts without the ProxyAllowParticipantConflict flag is to reject the request as described. This will eventually be the default for all accounts.
@return [SessionInstance] Created SessionInstance
# File lib/twilio-ruby/rest/proxy/v1/service/session.rb 143 def create(unique_name: :unset, date_expiry: :unset, ttl: :unset, mode: :unset, status: :unset, participants: :unset, fail_on_participant_conflict: :unset) 144 data = Twilio::Values.of({ 145 'UniqueName' => unique_name, 146 'DateExpiry' => Twilio.serialize_iso8601_datetime(date_expiry), 147 'Ttl' => ttl, 148 'Mode' => mode, 149 'Status' => status, 150 'Participants' => Twilio.serialize_list(participants) { |e| Twilio.serialize_object(e) }, 151 'FailOnParticipantConflict' => fail_on_participant_conflict, 152 }) 153 154 payload = @version.create('POST', @uri, data: data) 155 156 SessionInstance.new(@version, payload, service_sid: @solution[:service_sid], ) 157 end
When passed a block, yields SessionInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/proxy/v1/service/session.rb 70 def each 71 limits = @version.read_limits 72 73 page = self.page(page_size: limits[:page_size], ) 74 75 @version.stream(page, 76 limit: limits[:limit], 77 page_limit: limits[:page_limit]).each {|x| yield x} 78 end
Retrieve a single page of SessionInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of SessionInstance
# File lib/twilio-ruby/rest/proxy/v1/service/session.rb 104 def get_page(target_url) 105 response = @version.domain.request( 106 'GET', 107 target_url 108 ) 109 SessionPage.new(@version, response, @solution) 110 end
Lists SessionInstance
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/proxy/v1/service/session.rb 43 def list(limit: nil, page_size: nil) 44 self.stream(limit: limit, page_size: page_size).entries 45 end
Retrieve a single page of SessionInstance
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 SessionInstance
# File lib/twilio-ruby/rest/proxy/v1/service/session.rb 87 def page(page_token: :unset, page_number: :unset, page_size: :unset) 88 params = Twilio::Values.of({ 89 'PageToken' => page_token, 90 'Page' => page_number, 91 'PageSize' => page_size, 92 }) 93 94 response = @version.page('GET', @uri, params: params) 95 96 SessionPage.new(@version, response, @solution) 97 end
Streams SessionInstance
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/proxy/v1/service/session.rb 58 def stream(limit: nil, page_size: nil) 59 limits = @version.read_limits(limit, page_size) 60 61 page = self.page(page_size: limits[:page_size], ) 62 63 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 64 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/proxy/v1/service/session.rb 161 def to_s 162 '#<Twilio.Proxy.V1.SessionList>' 163 end