class Twilio::REST::Conversations::V1::ServiceContext::ConversationList
Public Class Methods
Initialize the ConversationList
@param [Version] version Version
that contains the resource @param [String] chat_service_sid The unique ID of the {Conversation
Service}[https://www.twilio.com/docs/conversations/api/service-resource] this conversation belongs to.
@return [ConversationList] ConversationList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 22 def initialize(version, chat_service_sid: nil) 23 super(version) 24 25 # Path Solution 26 @solution = {chat_service_sid: chat_service_sid} 27 @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations" 28 end
Public Instance Methods
Create the ConversationInstance
@param [String] friendly_name The human-readable name of this conversation,
limited to 256 characters. Optional.
@param [String] unique_name An application-defined string that uniquely
identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL.
@param [String] attributes An optional string metadata field you can use to
store any data you wish. The string value must contain structurally valid JSON if specified. **Note** that if the attributes are not set "{}" will be returned.
@param [String] messaging_service_sid The unique ID of the {Messaging
Service}[https://www.twilio.com/docs/sms/services/api] this conversation belongs to.
@param [Time] date_created The date that this resource was created. @param [Time] date_updated The date that this resource was last updated. @param [conversation.State] state Current state of this conversation. Can be
either `active`, `inactive` or `closed` and defaults to `active`
@param [String] timers_inactive ISO8601 duration when conversation will be
switched to `inactive` state. Minimum value for this timer is 1 minute.
@param [String] timers_closed ISO8601 duration when conversation will be
switched to `closed` state. Minimum value for this timer is 10 minutes.
@param [conversation.WebhookEnabledType] x_twilio_webhook_enabled The
X-Twilio-Webhook-Enabled HTTP request header
@return [ConversationInstance] Created ConversationInstance
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 55 def create(friendly_name: :unset, unique_name: :unset, attributes: :unset, messaging_service_sid: :unset, date_created: :unset, date_updated: :unset, state: :unset, timers_inactive: :unset, timers_closed: :unset, x_twilio_webhook_enabled: :unset) 56 data = Twilio::Values.of({ 57 'FriendlyName' => friendly_name, 58 'UniqueName' => unique_name, 59 'Attributes' => attributes, 60 'MessagingServiceSid' => messaging_service_sid, 61 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created), 62 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated), 63 'State' => state, 64 'Timers.Inactive' => timers_inactive, 65 'Timers.Closed' => timers_closed, 66 }) 67 headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) 68 69 payload = @version.create('POST', @uri, data: data, headers: headers) 70 71 ConversationInstance.new(@version, payload, chat_service_sid: @solution[:chat_service_sid], ) 72 end
When passed a block, yields ConversationInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 112 def each 113 limits = @version.read_limits 114 115 page = self.page(page_size: limits[:page_size], ) 116 117 @version.stream(page, 118 limit: limits[:limit], 119 page_limit: limits[:page_limit]).each {|x| yield x} 120 end
Retrieve a single page of ConversationInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of ConversationInstance
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 146 def get_page(target_url) 147 response = @version.domain.request( 148 'GET', 149 target_url 150 ) 151 ConversationPage.new(@version, response, @solution) 152 end
Lists ConversationInstance
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/conversations/v1/service/conversation.rb 85 def list(limit: nil, page_size: nil) 86 self.stream(limit: limit, page_size: page_size).entries 87 end
Retrieve a single page of ConversationInstance
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 ConversationInstance
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 129 def page(page_token: :unset, page_number: :unset, page_size: :unset) 130 params = Twilio::Values.of({ 131 'PageToken' => page_token, 132 'Page' => page_number, 133 'PageSize' => page_size, 134 }) 135 136 response = @version.page('GET', @uri, params: params) 137 138 ConversationPage.new(@version, response, @solution) 139 end
Streams ConversationInstance
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/conversations/v1/service/conversation.rb 100 def stream(limit: nil, page_size: nil) 101 limits = @version.read_limits(limit, page_size) 102 103 page = self.page(page_size: limits[:page_size], ) 104 105 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 106 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/conversations/v1/service/conversation.rb 156 def to_s 157 '#<Twilio.Conversations.V1.ConversationList>' 158 end