Class: Twilio::REST::Notify::V1::ServiceContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/notify/v1/service.rb,
lib/twilio-ruby/rest/notify/v1/service/binding.rb,
lib/twilio-ruby/rest/notify/v1/service/notification.rb

Defined Under Namespace

Classes: BindingContext, BindingInstance, BindingInstanceMetadata, BindingList, BindingListResponse, BindingPage, BindingPageMetadata, NotificationInstance, NotificationList, NotificationListResponse, NotificationPage, NotificationPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ServiceContext

Initialize the ServiceContext

Parameters:

  • version (Version)

    Version that contains the resource

  • sid (String)

    The Twilio-provided string that uniquely identifies the Service resource to update.



301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 301

def initialize(version, sid)
    super(version)
    

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

    # Dependents
    @notifications = nil
    @bindings = nil
end

Instance Method Details

#bindings(sid = :unset) ⇒ BindingList, BindingContext

Access the bindings

Returns:

Raises:

  • (ArgumentError)


540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 540

def bindings(sid=:unset)

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

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

    unless @bindings
        @bindings = BindingList.new(
            @version, service_sid: @solution[:sid], )
    end

 @bindings
end

#deleteBoolean

Delete the ServiceInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



316
317
318
319
320
321
322
323
324
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 316

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 ServiceInstanceMetadata

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 329

def 

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

#fetchServiceInstance

Fetch the ServiceInstance

Returns:



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 348

def fetch

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

#fetch_with_metadataServiceInstance

Fetch the ServiceInstanceMetadata

Returns:



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 367

def 

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

#inspectObject

Provide a detailed, user friendly representation



565
566
567
568
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 565

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

#notificationsNotificationList, NotificationContext

Access the notifications

Returns:



529
530
531
532
533
534
535
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 529

def notifications
  unless @notifications
    @notifications = NotificationList.new(
            @version, service_sid: @solution[:sid], )
  end
  @notifications
end

#to_sObject

Provide a user friendly representation



558
559
560
561
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 558

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

#update(friendly_name: :unset, apn_credential_sid: :unset, gcm_credential_sid: :unset, messaging_service_sid: :unset, facebook_messenger_page_id: :unset, default_apn_notification_protocol_version: :unset, default_gcm_notification_protocol_version: :unset, fcm_credential_sid: :unset, default_fcm_notification_protocol_version: :unset, log_enabled: :unset, alexa_skill_id: :unset, default_alexa_notification_protocol_version: :unset, delivery_callback_url: :unset, delivery_callback_enabled: :unset) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

    A descriptive string that you create to describe the resource. It can be up to 64 characters long.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for APN Bindings.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for GCM Bindings.

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

    The SID of the [Messaging Service](www.twilio.com/docs/sms/quickstart#messaging-services) to use for SMS Bindings. This parameter must be set in order to send SMS notifications.

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

    Deprecated.

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

    The protocol version to use for sending APNS notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

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

    The protocol version to use for sending GCM notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for FCM Bindings.

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

    The protocol version to use for sending FCM notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

  • log_enabled (Boolean) (defaults to: :unset)

    Whether to log notifications. Can be: true or false and the default is true.

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

    Deprecated.

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

    Deprecated.

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

    URL to send delivery status callback.

  • delivery_callback_enabled (Boolean) (defaults to: :unset)

    Callback configuration that enables delivery callbacks, default false

Returns:



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 406

def update(
    friendly_name: :unset, 
    apn_credential_sid: :unset, 
    gcm_credential_sid: :unset, 
    messaging_service_sid: :unset, 
    facebook_messenger_page_id: :unset, 
    default_apn_notification_protocol_version: :unset, 
    default_gcm_notification_protocol_version: :unset, 
    fcm_credential_sid: :unset, 
    default_fcm_notification_protocol_version: :unset, 
    log_enabled: :unset, 
    alexa_skill_id: :unset, 
    default_alexa_notification_protocol_version: :unset, 
    delivery_callback_url: :unset, 
    delivery_callback_enabled: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'ApnCredentialSid' => apn_credential_sid,
        'GcmCredentialSid' => gcm_credential_sid,
        'MessagingServiceSid' => messaging_service_sid,
        'FacebookMessengerPageId' => facebook_messenger_page_id,
        'DefaultApnNotificationProtocolVersion' => default_apn_notification_protocol_version,
        'DefaultGcmNotificationProtocolVersion' => default_gcm_notification_protocol_version,
        'FcmCredentialSid' => fcm_credential_sid,
        'DefaultFcmNotificationProtocolVersion' => default_fcm_notification_protocol_version,
        'LogEnabled' => log_enabled,
        'AlexaSkillId' => alexa_skill_id,
        'DefaultAlexaNotificationProtocolVersion' => default_alexa_notification_protocol_version,
        'DeliveryCallbackUrl' => delivery_callback_url,
        'DeliveryCallbackEnabled' => delivery_callback_enabled,
    })

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

#update_with_metadata(friendly_name: :unset, apn_credential_sid: :unset, gcm_credential_sid: :unset, messaging_service_sid: :unset, facebook_messenger_page_id: :unset, default_apn_notification_protocol_version: :unset, default_gcm_notification_protocol_version: :unset, fcm_credential_sid: :unset, default_fcm_notification_protocol_version: :unset, log_enabled: :unset, alexa_skill_id: :unset, default_alexa_notification_protocol_version: :unset, delivery_callback_url: :unset, delivery_callback_enabled: :unset) ⇒ ServiceInstance

Update the ServiceInstanceMetadata

Parameters:

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

    A descriptive string that you create to describe the resource. It can be up to 64 characters long.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for APN Bindings.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for GCM Bindings.

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

    The SID of the [Messaging Service](www.twilio.com/docs/sms/quickstart#messaging-services) to use for SMS Bindings. This parameter must be set in order to send SMS notifications.

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

    Deprecated.

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

    The protocol version to use for sending APNS notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

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

    The protocol version to use for sending GCM notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

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

    The SID of the [Credential](www.twilio.com/docs/notify/api/credential-resource) to use for FCM Bindings.

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

    The protocol version to use for sending FCM notifications. Can be overridden on a Binding by Binding basis when creating a [Binding](www.twilio.com/docs/notify/api/binding-resource) resource.

  • log_enabled (Boolean) (defaults to: :unset)

    Whether to log notifications. Can be: true or false and the default is true.

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

    Deprecated.

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

    Deprecated.

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

    URL to send delivery status callback.

  • delivery_callback_enabled (Boolean) (defaults to: :unset)

    Callback configuration that enables delivery callbacks, default false

Returns:



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 471

def (
  friendly_name: :unset, 
  apn_credential_sid: :unset, 
  gcm_credential_sid: :unset, 
  messaging_service_sid: :unset, 
  facebook_messenger_page_id: :unset, 
  default_apn_notification_protocol_version: :unset, 
  default_gcm_notification_protocol_version: :unset, 
  fcm_credential_sid: :unset, 
  default_fcm_notification_protocol_version: :unset, 
  log_enabled: :unset, 
  alexa_skill_id: :unset, 
  default_alexa_notification_protocol_version: :unset, 
  delivery_callback_url: :unset, 
  delivery_callback_enabled: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'ApnCredentialSid' => apn_credential_sid,
        'GcmCredentialSid' => gcm_credential_sid,
        'MessagingServiceSid' => messaging_service_sid,
        'FacebookMessengerPageId' => facebook_messenger_page_id,
        'DefaultApnNotificationProtocolVersion' => default_apn_notification_protocol_version,
        'DefaultGcmNotificationProtocolVersion' => default_gcm_notification_protocol_version,
        'FcmCredentialSid' => fcm_credential_sid,
        'DefaultFcmNotificationProtocolVersion' => default_fcm_notification_protocol_version,
        'LogEnabled' => log_enabled,
        'AlexaSkillId' => alexa_skill_id,
        'DefaultAlexaNotificationProtocolVersion' => default_alexa_notification_protocol_version,
        'DeliveryCallbackUrl' => delivery_callback_url,
        'DeliveryCallbackEnabled' => delivery_callback_enabled,
    })

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