Class: Twilio::REST::Conversations::V1::ServiceContext::UserContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/service/user.rb,
lib/twilio-ruby/rest/conversations/v1/service/user/user_conversation.rb

Defined Under Namespace

Classes: UserConversationContext, UserConversationInstance, UserConversationInstanceMetadata, UserConversationList, UserConversationListResponse, UserConversationPage, UserConversationPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, chat_service_sid, sid) ⇒ UserContext

Initialize the UserContext

Parameters:

  • version (Version)

    Version that contains the resource

  • chat_service_sid (String)

    The SID of the [Conversation Service](www.twilio.com/docs/conversations/api/service-resource) the User resource is associated with.

  • sid (String)

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



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 250

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

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

    # Dependents
    @user_conversations = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the UserInstance

Parameters:

  • x_twilio_webhook_enabled (ServiceUserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 265

def delete(
  x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    

    @version.delete('DELETE', @uri, headers: headers)
end

#delete_with_metadata(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the UserInstanceMetadata

Parameters:

  • x_twilio_webhook_enabled (ServiceUserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 281

def (
  x_twilio_webhook_enabled: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      user_instance = UserInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      UserInstanceMetadata.new(@version, user_instance, response.headers, response.status_code)
end

#fetchUserInstance

Fetch the UserInstance

Returns:



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 302

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    UserInstance.new(
        @version,
        payload,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataUserInstance

Fetch the UserInstanceMetadata

Returns:



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 322

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    user_instance = UserInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
    UserInstanceMetadata.new(
        @version,
        user_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



450
451
452
453
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 450

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

#to_sObject

Provide a user friendly representation



443
444
445
446
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 443

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

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

Update the UserInstance

Parameters:

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

    The string that you assigned to describe the resource.

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

    The JSON Object string that stores application-specific data. If attributes have not been set, ‘{}` is returned.

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

    The SID of a service-level [Role](www.twilio.com/docs/conversations/api/role-resource) to assign to the user.

  • x_twilio_webhook_enabled (ServiceUserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 352

def update(
  friendly_name: :unset, 
  attributes: :unset, 
  role_sid: :unset, 
  x_twilio_webhook_enabled: :unset
)

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

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
    
    
    payload = @version.update('POST', @uri, data: data, headers: headers)
    UserInstance.new(
        @version,
        payload,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
end

#update_with_metadata(friendly_name: :unset, attributes: :unset, role_sid: :unset, x_twilio_webhook_enabled: :unset) ⇒ UserInstance

Update the UserInstanceMetadata

Parameters:

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

    The string that you assigned to describe the resource.

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

    The JSON Object string that stores application-specific data. If attributes have not been set, ‘{}` is returned.

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

    The SID of a service-level [Role](www.twilio.com/docs/conversations/api/role-resource) to assign to the user.

  • x_twilio_webhook_enabled (ServiceUserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 387

def (
  friendly_name: :unset, 
  attributes: :unset, 
  role_sid: :unset, 
  x_twilio_webhook_enabled: :unset
)

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

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    user_instance = UserInstance.new(
        @version,
        response.body,
        chat_service_sid: @solution[:chat_service_sid],
        sid: @solution[:sid],
    )
    UserInstanceMetadata.new(
        @version,
        user_instance,
        response.headers,
        response.status_code
    )
end

#user_conversations(conversation_sid = :unset) ⇒ UserConversationList, UserConversationContext

Access the user_conversations

Returns:

Raises:

  • (ArgumentError)


425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 425

def user_conversations(conversation_sid=:unset)

    raise ArgumentError, 'conversation_sid cannot be nil' if conversation_sid.nil?

    if conversation_sid != :unset
        return UserConversationContext.new(@version, @solution[:chat_service_sid], @solution[:sid],conversation_sid )
    end

    unless @user_conversations
        @user_conversations = UserConversationList.new(
            @version, chat_service_sid: @solution[:chat_service_sid], user_sid: @solution[:sid], )
    end

 @user_conversations
end