Class: Twilio::REST::Sync::V1::ServiceContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/sync/v1/service.rb,
lib/twilio-ruby/rest/sync/v1/service/document.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_map.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_list.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_stream.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_list/sync_list_item.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_stream/stream_message.rb,
lib/twilio-ruby/rest/sync/v1/service/document/document_permission.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_permission.rb,
lib/twilio-ruby/rest/sync/v1/service/sync_list/sync_list_permission.rb

Defined Under Namespace

Classes: DocumentContext, DocumentInstance, DocumentList, DocumentPage, SyncListContext, SyncListInstance, SyncListList, SyncListPage, SyncMapContext, SyncMapInstance, SyncMapList, SyncMapPage, SyncStreamContext, SyncStreamInstance, SyncStreamList, SyncStreamPage

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 of the Service resource to update.



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 169

def initialize(version, sid)
    super(version)

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

    # Dependents
    @sync_streams = nil
    @sync_lists = nil
    @sync_maps = nil
    @documents = nil
end

Instance Method Details

#deleteBoolean

Delete the ServiceInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



185
186
187
188
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 185

def delete

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

#documents(sid = :unset) ⇒ DocumentList, DocumentContext

Access the documents

Returns:

Raises:

  • (ArgumentError)


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

def documents(sid=:unset)

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

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

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

 @documents
end

#fetchServiceInstance

Fetch the ServiceInstance

Returns:



193
194
195
196
197
198
199
200
201
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 193

def fetch

    payload = @version.fetch('GET', @uri)
    ServiceInstance.new(
        @version,
        payload,
        sid: @solution[:sid],
    )
end

#inspectObject

Provide a detailed, user friendly representation



327
328
329
330
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 327

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

#sync_lists(sid = :unset) ⇒ SyncListList, SyncListContext

Access the sync_lists

Returns:

Raises:

  • (ArgumentError)


264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 264

def sync_lists(sid=:unset)

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

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

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

 @sync_lists
end

#sync_maps(sid = :unset) ⇒ SyncMapList, SyncMapContext

Access the sync_maps

Returns:

Raises:

  • (ArgumentError)


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

def sync_maps(sid=:unset)

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

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

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

 @sync_maps
end

#sync_streams(sid = :unset) ⇒ SyncStreamList, SyncStreamContext

Access the sync_streams

Returns:

Raises:

  • (ArgumentError)


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

def sync_streams(sid=:unset)

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

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

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

 @sync_streams
end

#to_sObject

Provide a user friendly representation



320
321
322
323
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 320

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

#update(webhook_url: :unset, friendly_name: :unset, reachability_webhooks_enabled: :unset, acl_enabled: :unset, reachability_debouncing_enabled: :unset, reachability_debouncing_window: :unset, webhooks_from_rest_enabled: :unset) ⇒ ServiceInstance

Update the ServiceInstance

Parameters:

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

    The URL we should call when Sync objects are manipulated.

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

    A string that you assign to describe the resource.

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

    Whether the service instance should call ‘webhook_url` when client endpoints connect to Sync. The default is `false`.

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

    Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](www.twilio.com/docs/sync/api/sync-permissions) resource.

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

    Whether every ‘endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.

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

    The reachability event delay in milliseconds if ‘reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the webhook is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the webhook from being called.

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

    Whether the Service instance should call ‘webhook_url` when the REST API is used to update Sync objects. The default is `false`.

Returns:



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/twilio-ruby/rest/sync/v1/service.rb', line 213

def update(
    webhook_url: :unset, 
    friendly_name: :unset, 
    reachability_webhooks_enabled: :unset, 
    acl_enabled: :unset, 
    reachability_debouncing_enabled: :unset, 
    reachability_debouncing_window: :unset, 
    webhooks_from_rest_enabled: :unset
)

    data = Twilio::Values.of({
        'WebhookUrl' => webhook_url,
        'FriendlyName' => friendly_name,
        'ReachabilityWebhooksEnabled' => reachability_webhooks_enabled,
        'AclEnabled' => acl_enabled,
        'ReachabilityDebouncingEnabled' => reachability_debouncing_enabled,
        'ReachabilityDebouncingWindow' => reachability_debouncing_window,
        'WebhooksFromRestEnabled' => webhooks_from_rest_enabled,
    })

    payload = @version.update('POST', @uri, data: data)
    ServiceInstance.new(
        @version,
        payload,
        sid: @solution[:sid],
    )
end