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, BindingList, BindingPage, NotificationInstance, NotificationList, NotificationPage

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.



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 199

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)


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

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



213
214
215
216
217
218
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 213

def delete

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    @version.delete('DELETE', @uri, headers: headers)
end

#fetchServiceInstance

Fetch the ServiceInstance

Returns:



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

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

#inspectObject

Provide a detailed, user friendly representation



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

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

#notificationsNotificationList, NotificationContext

Access the notifications

Returns:



300
301
302
303
304
305
306
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 300

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

#to_sObject

Provide a user friendly representation



329
330
331
332
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 329

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:



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/twilio-ruby/rest/notify/v1/service.rb', line 252

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