class Twilio::REST::Chat::V2::ServiceContext::UserList
Public Class Methods
Initialize the UserList
@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 User resource is associated with.
@return [UserList] UserList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 22 def initialize(version, service_sid: nil) 23 super(version) 24 25 # Path Solution 26 @solution = {service_sid: service_sid} 27 @uri = "/Services/#{@solution[:service_sid]}/Users" 28 end
Public Instance Methods
Create the UserInstance
@param [String] identity The `identity` value that uniquely identifies the new
resource's {User}[https://www.twilio.com/docs/chat/rest/user-resource] within the {Service}[https://www.twilio.com/docs/chat/rest/service-resource]. This value is often a username or email address. See the Identity documentation for more info.
@param [String] role_sid The SID of the
{Role}[https://www.twilio.com/docs/chat/rest/role-resource] to assign to the new User.
@param [String] attributes A valid JSON string that contains
application-specific data.
@param [String] friendly_name A descriptive string that you create to describe
the new resource. This value is often used for display purposes.
@param [user.WebhookEnabledType] x_twilio_webhook_enabled The
X-Twilio-Webhook-Enabled HTTP request header
@return [UserInstance] Created UserInstance
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 47 def create(identity: nil, role_sid: :unset, attributes: :unset, friendly_name: :unset, x_twilio_webhook_enabled: :unset) 48 data = Twilio::Values.of({ 49 'Identity' => identity, 50 'RoleSid' => role_sid, 51 'Attributes' => attributes, 52 'FriendlyName' => friendly_name, 53 }) 54 headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, }) 55 56 payload = @version.create('POST', @uri, data: data, headers: headers) 57 58 UserInstance.new(@version, payload, service_sid: @solution[:service_sid], ) 59 end
When passed a block, yields UserInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 99 def each 100 limits = @version.read_limits 101 102 page = self.page(page_size: limits[:page_size], ) 103 104 @version.stream(page, 105 limit: limits[:limit], 106 page_limit: limits[:page_limit]).each {|x| yield x} 107 end
Retrieve a single page of UserInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of UserInstance
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 133 def get_page(target_url) 134 response = @version.domain.request( 135 'GET', 136 target_url 137 ) 138 UserPage.new(@version, response, @solution) 139 end
Lists UserInstance
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/chat/v2/service/user.rb 72 def list(limit: nil, page_size: nil) 73 self.stream(limit: limit, page_size: page_size).entries 74 end
Retrieve a single page of UserInstance
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 UserInstance
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 116 def page(page_token: :unset, page_number: :unset, page_size: :unset) 117 params = Twilio::Values.of({ 118 'PageToken' => page_token, 119 'Page' => page_number, 120 'PageSize' => page_size, 121 }) 122 123 response = @version.page('GET', @uri, params: params) 124 125 UserPage.new(@version, response, @solution) 126 end
Streams UserInstance
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/chat/v2/service/user.rb 87 def stream(limit: nil, page_size: nil) 88 limits = @version.read_limits(limit, page_size) 89 90 page = self.page(page_size: limits[:page_size], ) 91 92 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 93 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/chat/v2/service/user.rb 143 def to_s 144 '#<Twilio.Chat.V2.UserList>' 145 end