class Twilio::REST::Chat::V1::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/api/chat/rest/services] the resource is associated with.
@return [UserList] UserList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/chat/v1/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/api/chat/rest/v1/user] within the {Service}[https://www.twilio.com/docs/api/chat/rest/v1/service]. This value is often a username or email address. See the Identity documentation for more details.
@param [String] role_sid The SID of the
{Role}[https://www.twilio.com/docs/api/chat/rest/roles] assigned 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.
@return [UserInstance] Created UserInstance
# File lib/twilio-ruby/rest/chat/v1/service/user.rb 45 def create(identity: nil, role_sid: :unset, attributes: :unset, friendly_name: :unset) 46 data = Twilio::Values.of({ 47 'Identity' => identity, 48 'RoleSid' => role_sid, 49 'Attributes' => attributes, 50 'FriendlyName' => friendly_name, 51 }) 52 53 payload = @version.create('POST', @uri, data: data) 54 55 UserInstance.new(@version, payload, service_sid: @solution[:service_sid], ) 56 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/v1/service/user.rb 96 def each 97 limits = @version.read_limits 98 99 page = self.page(page_size: limits[:page_size], ) 100 101 @version.stream(page, 102 limit: limits[:limit], 103 page_limit: limits[:page_limit]).each {|x| yield x} 104 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/v1/service/user.rb 130 def get_page(target_url) 131 response = @version.domain.request( 132 'GET', 133 target_url 134 ) 135 UserPage.new(@version, response, @solution) 136 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/v1/service/user.rb 69 def list(limit: nil, page_size: nil) 70 self.stream(limit: limit, page_size: page_size).entries 71 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/v1/service/user.rb 113 def page(page_token: :unset, page_number: :unset, page_size: :unset) 114 params = Twilio::Values.of({ 115 'PageToken' => page_token, 116 'Page' => page_number, 117 'PageSize' => page_size, 118 }) 119 120 response = @version.page('GET', @uri, params: params) 121 122 UserPage.new(@version, response, @solution) 123 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/v1/service/user.rb 84 def stream(limit: nil, page_size: nil) 85 limits = @version.read_limits(limit, page_size) 86 87 page = self.page(page_size: limits[:page_size], ) 88 89 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 90 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/chat/v1/service/user.rb 140 def to_s 141 '#<Twilio.Chat.V1.UserList>' 142 end