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/user.rb,
lib/twilio-ruby/rest/notify/v1/service/binding.rb,
lib/twilio-ruby/rest/notify/v1/service/segment.rb,
lib/twilio-ruby/rest/notify/v1/service/notification.rb,
lib/twilio-ruby/rest/notify/v1/service/user/user_binding.rb,
lib/twilio-ruby/rest/notify/v1/service/user/segment_memberships.rb

Overview

PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.

Defined Under Namespace

Classes: BindingContext, BindingInstance, BindingList, BindingPage, NotificationInstance, NotificationList, NotificationPage, SegmentInstance, SegmentList, SegmentPage, UserContext, UserInstance, UserList, UserPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ServiceContext

Initialize the ServiceContext

Parameters:

  • version (Version)

    Version that contains the resource

  • sid (String)

    The sid



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 221

def initialize(version, sid)
  super(version)

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

  # Dependents
  @bindings = nil
  @notifications = nil
  @users = nil
  @segments = nil
end

Instance Method Details

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

Access the bindings

Returns:

Raises:

  • (ArgumentError)


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

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

Deletes the ServiceInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



238
239
240
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 238

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

#fetchServiceInstance

Fetch a ServiceInstance

Returns:



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 245

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

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

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

#notificationsNotificationList, NotificationContext

Access the notifications

Returns:



334
335
336
337
338
339
340
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 334

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

  @notifications
end

#segmentsSegmentList, SegmentContext

Access the segments

Returns:



364
365
366
367
368
369
370
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 364

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

  @segments
end

#to_sObject

Provide a user friendly representation



374
375
376
377
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 374

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) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

    Human-readable name for this service instance

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

    The SID of the default Credential to be used for APN Bindings

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

    The SID of the default Credential to be used for GCM Bindings

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

    The SID of the [Messaging Service](www.twilio.com/docs/api/rest/sending-messages#messaging-services) to be used for SMS Bindings. In order to send SMS notifications this parameter has to be set.

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

    The Page ID to be used to send for Facebook Messenger Bindings. It has to match the Page ID you configured when you [enabled Facebook Messaging](www.twilio.com/console/sms/settings) on your account. Facebook Messenger integration is in beta. You need to be in the beta program to be able to enable Facebook Messaging for your account.

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

    The version of the protocol to be used for sending APNS notifications. Can be overriden on a Binding by Binding basis when creating a Binding resource.

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

    The version of the protocol to be used for sending GCM notifications. Can be overriden on a Binding by Binding basis when creating a Binding resource.

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

    The SID of the default Credential to be used for FCM Bindings

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

    The version of the protocol to be used for sending FCM notifications. Can be overriden on a Binding by Binding basis when creating a Binding resource.

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

    The log_enabled

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

    The alexa_skill_id

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

    The default_alexa_notification_protocol_version

Returns:



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 287

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)
  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,
  })

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

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

#users(identity = :unset) ⇒ UserList, UserContext

Access the users

Returns:

Raises:

  • (ArgumentError)


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

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

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

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

  @users
end