Class: Twilio::REST::IpMessaging::V2::ServiceContext::UserContext

Inherits:
Twilio::REST::InstanceContext show all
Defined in:
lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb,
lib/twilio-ruby/rest/ip_messaging/v2/service/user/user_binding.rb,
lib/twilio-ruby/rest/ip_messaging/v2/service/user/user_channel.rb

Defined Under Namespace

Classes: UserBindingContext, UserBindingInstance, UserBindingInstanceMetadata, UserBindingList, UserBindingListResponse, UserBindingPage, UserBindingPageMetadata, UserChannelContext, UserChannelInstance, UserChannelInstanceMetadata, UserChannelList, UserChannelListResponse, UserChannelPage, UserChannelPageMetadata

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)
  • sid (String)


242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 242

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

Delete the UserInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



257
258
259
260
261
262
263
264
265
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 257

def delete

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

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

#delete_with_metadataBoolean

Delete the UserInstanceMetadata

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 270

def 

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

#fetchUserInstance

Fetch the UserInstance

Returns:



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 289

def fetch

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

#fetch_with_metadataUserInstance

Fetch the UserInstanceMetadata

Returns:



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 309

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,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        user_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



456
457
458
459
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 456

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

#to_sObject

Provide a user friendly representation



449
450
451
452
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 449

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

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

Update the UserInstance

Parameters:

  • role_sid (String) (defaults to: :unset)
  • attributes (String) (defaults to: :unset)
  • friendly_name (String) (defaults to: :unset)
  • x_twilio_webhook_enabled (UserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 339

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

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

    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,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end

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

Update the UserInstanceMetadata

Parameters:

  • role_sid (String) (defaults to: :unset)
  • attributes (String) (defaults to: :unset)
  • friendly_name (String) (defaults to: :unset)
  • x_twilio_webhook_enabled (UserEnumWebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 374

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

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

    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,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        user_instance,
        response.headers,
        response.status_code
    )
end

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

Access the user_bindings

Returns:

Raises:

  • (ArgumentError)


431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 431

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)


412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb', line 412

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