class Twilio::REST::Chat::V1::ServiceContext::RoleList
Public Class Methods
Initialize the RoleList
@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 [RoleList] RoleList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/chat/v1/service/role.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]}/Roles" 28 end
Public Instance Methods
Create the RoleInstance
@param [String] friendly_name A descriptive string that you create to describe
the new resource. It can be up to 64 characters long.
@param [role.RoleType] type The type of role. Can be: `channel` for
{Channel}[https://www.twilio.com/docs/chat/api/channels] roles or `deployment` for {Service}[https://www.twilio.com/docs/chat/api/services] roles.
@param [Array] permission A permission that you grant to the new role.
Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. The values for this parameter depend on the role's `type` and are described in the documentation.
@return [RoleInstance] Created RoleInstance
# File lib/twilio-ruby/rest/chat/v1/service/role.rb 42 def create(friendly_name: nil, type: nil, permission: nil) 43 data = Twilio::Values.of({ 44 'FriendlyName' => friendly_name, 45 'Type' => type, 46 'Permission' => Twilio.serialize_list(permission) { |e| e }, 47 }) 48 49 payload = @version.create('POST', @uri, data: data) 50 51 RoleInstance.new(@version, payload, service_sid: @solution[:service_sid], ) 52 end
When passed a block, yields RoleInstance
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/role.rb 92 def each 93 limits = @version.read_limits 94 95 page = self.page(page_size: limits[:page_size], ) 96 97 @version.stream(page, 98 limit: limits[:limit], 99 page_limit: limits[:page_limit]).each {|x| yield x} 100 end
Retrieve a single page of RoleInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of RoleInstance
# File lib/twilio-ruby/rest/chat/v1/service/role.rb 126 def get_page(target_url) 127 response = @version.domain.request( 128 'GET', 129 target_url 130 ) 131 RolePage.new(@version, response, @solution) 132 end
Lists RoleInstance
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/role.rb 65 def list(limit: nil, page_size: nil) 66 self.stream(limit: limit, page_size: page_size).entries 67 end
Retrieve a single page of RoleInstance
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 RoleInstance
# File lib/twilio-ruby/rest/chat/v1/service/role.rb 109 def page(page_token: :unset, page_number: :unset, page_size: :unset) 110 params = Twilio::Values.of({ 111 'PageToken' => page_token, 112 'Page' => page_number, 113 'PageSize' => page_size, 114 }) 115 116 response = @version.page('GET', @uri, params: params) 117 118 RolePage.new(@version, response, @solution) 119 end
Streams RoleInstance
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/role.rb 80 def stream(limit: nil, page_size: nil) 81 limits = @version.read_limits(limit, page_size) 82 83 page = self.page(page_size: limits[:page_size], ) 84 85 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 86 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/chat/v1/service/role.rb 136 def to_s 137 '#<Twilio.Chat.V1.RoleList>' 138 end