Class: Twilio::REST::Sync::V1::ServiceContext::SyncMapContext::SyncMapItemContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, map_sid, key) ⇒ SyncMapItemContext

Initialize the SyncMapItemContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Sync Service](www.twilio.com/docs/sync/api/service) with the Sync Map Item resource to fetch.

  • map_sid (String)

    The SID of the Sync Map with the Sync Map Item resource to fetch. Can be the Sync Map’s ‘sid` or its `unique_name`.

  • key (String)

    The ‘key` value of the Sync Map Item resource to fetch.



250
251
252
253
254
255
256
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 250

def initialize(version, service_sid, map_sid, key)
  super(version)

  # Path Solution
  @solution = {service_sid: service_sid, map_sid: map_sid, key: key, }
  @uri = "/Services/#{@solution[:service_sid]}/Maps/#{@solution[:map_sid]}/Items/#{@solution[:key]}"
end

Instance Method Details

#deleteBoolean

Deletes the SyncMapItemInstance

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise



282
283
284
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 282

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

#fetchSyncMapItemInstance

Fetch a SyncMapItemInstance

Returns:



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

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

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

  SyncMapItemInstance.new(
      @version,
      payload,
      service_sid: @solution[:service_sid],
      map_sid: @solution[:map_sid],
      key: @solution[:key],
  )
end

#inspectObject

Provide a detailed, user friendly representation



335
336
337
338
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 335

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

#to_sObject

Provide a user friendly representation



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

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

#update(data: :unset, ttl: :unset, item_ttl: :unset, collection_ttl: :unset) ⇒ SyncMapItemInstance

Update the SyncMapItemInstance

Parameters:

  • data (Hash) (defaults to: :unset)

    A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16KB in length.

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

    An alias for ‘item_ttl`. If both parameters are provided, this value is ignored.

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

    How long, in seconds, before the Map Item expires (time-to-live) and is deleted. Can be an integer from 0 to 31,536,000 (1 year). The default value is ‘0`, which means the Map Item does not expire. The Map Item might not be deleted immediately after it expires.

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

    How long, in seconds, before the Map Item’s parent Sync Map expires (time-to-live) and is deleted. Can be an integer from 0 to 31,536,000 (1 year). The default value is ‘0`, which means the parent Sync Map does not expire. This parameter can only be used when the Map Item’s ‘data` or `ttl` is updated in the same request. The Sync Map might not be deleted immediately after it expires.

Returns:



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 303

def update(data: :unset, ttl: :unset, item_ttl: :unset, collection_ttl: :unset)
  data = Twilio::Values.of({
      'Data' => Twilio.serialize_object(data),
      'Ttl' => ttl,
      'ItemTtl' => item_ttl,
      'CollectionTtl' => collection_ttl,
  })

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

  SyncMapItemInstance.new(
      @version,
      payload,
      service_sid: @solution[:service_sid],
      map_sid: @solution[:map_sid],
      key: @solution[:key],
  )
end