Class: Twilio::REST::Chat::V2::ServiceContext::UserContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/chat/v2/service/user.rb,
lib/twilio-ruby/rest/chat/v2/service/user/user_binding.rb,
lib/twilio-ruby/rest/chat/v2/service/user/user_channel.rb

Defined Under Namespace

Classes: UserBindingContext, UserBindingInstance, UserBindingList, UserBindingPage, UserChannelContext, UserChannelInstance, UserChannelList, UserChannelPage

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, sid) ⇒ UserContext

Initialize the UserContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Service](www.twilio.com/docs/chat/rest/service-resource) to fetch the User resource from.

  • sid (String)

    The SID of the User resource to fetch. This value can be either the sid or the identity of the User resource to fetch.



191
192
193
194
195
196
197
198
199
200
201
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 191

def initialize(version, service_sid, sid)
  super(version)

  # Path Solution
  @solution = {service_sid: service_sid, sid: sid, }
  @uri = "/Services/#{@solution[:service_sid]}/Users/#{@solution[:sid]}"

  # Dependents
  @user_channels = nil
  @user_bindings = nil
end

Instance Method Details

#deleteBoolean

Deletes the UserInstance

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise



221
222
223
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 221

def delete
  @version.delete('delete', @uri)
end

#fetchUserInstance

Fetch a UserInstance

Returns:



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 206

def fetch
  params = Twilio::Values.of({})

  payload = @version.fetch(
      'GET',
      @uri,
      params,
  )

  UserInstance.new(@version, payload, service_sid: @solution[:service_sid], sid: @solution[:sid], )
end

#inspectObject

Provide a detailed, user friendly representation



304
305
306
307
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 304

def inspect
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Chat.V2.UserContext #{context}>"
end

#to_sObject

Provide a user friendly representation



297
298
299
300
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 297

def to_s
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Chat.V2.UserContext #{context}>"
end

#update(role_sid: :unset, attributes: :unset, friendly_name: :unset) ⇒ UserInstance

Update the UserInstance

Parameters:

  • role_sid (String) (defaults to: :unset)

    The SID of the [Role](www.twilio.com/docs/chat/rest/role-resource) to assign to the User.

  • attributes (String) (defaults to: :unset)

    A valid JSON string that contains application-specific data.

  • friendly_name (String) (defaults to: :unset)

    A descriptive string that you create to describe the resource. It is often used for display purposes.

Returns:



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 235

def update(role_sid: :unset, attributes: :unset, friendly_name: :unset)
  data = Twilio::Values.of({
      'RoleSid' => role_sid,
      'Attributes' => attributes,
      'FriendlyName' => friendly_name,
  })

  payload = @version.update(
      'POST',
      @uri,
      data: data,
  )

  UserInstance.new(@version, payload, service_sid: @solution[:service_sid], sid: @solution[:sid], )
end

#user_bindings(sid = :unset) ⇒ UserBindingList, UserBindingContext

Access the user_bindings

Returns:

Raises:

  • (ArgumentError)


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 277

def user_bindings(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return UserBindingContext.new(@version, @solution[:service_sid], @solution[:sid], sid, )
  end

  unless @user_bindings
    @user_bindings = UserBindingList.new(
        @version,
        service_sid: @solution[:service_sid],
        user_sid: @solution[:sid],
    )
  end

  @user_bindings
end

#user_channels(channel_sid = :unset) ⇒ UserChannelList, UserChannelContext

Access the user_channels

Returns:

Raises:

  • (ArgumentError)


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/twilio-ruby/rest/chat/v2/service/user.rb', line 255

def user_channels(channel_sid=:unset)
  raise ArgumentError, 'channel_sid cannot be nil' if channel_sid.nil?

  if channel_sid != :unset
    return UserChannelContext.new(@version, @solution[:service_sid], @solution[:sid], channel_sid, )
  end

  unless @user_channels
    @user_channels = UserChannelList.new(
        @version,
        service_sid: @solution[:service_sid],
        user_sid: @solution[:sid],
    )
  end

  @user_channels
end