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

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 update.

  • map_sid (String)

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

  • key (String)

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



188
189
190
191
192
193
194
195
196
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 188

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

#delete(if_match: :unset) ⇒ Boolean

Delete the SyncMapItemInstance

Parameters:

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

    If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



201
202
203
204
205
206
207
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 201

def delete(
    if_match: :unset
)

    headers = Twilio::Values.of({ 'If-Match' => if_match, })
    @version.delete('DELETE', @uri, headers: headers)
end

#fetchSyncMapItemInstance

Fetch the SyncMapItemInstance

Returns:



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 212

def fetch

    payload = @version.fetch('GET', @uri)
    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



268
269
270
271
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 268

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

#to_sObject

Provide a user friendly representation



261
262
263
264
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 261

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, if_match: :unset) ⇒ SyncMapItemInstance

Update the SyncMapItemInstance

Parameters:

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

    A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB 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](www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.

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

    How long, [in seconds](www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item’s parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item’s ‘data` or `ttl` is updated in the same request.

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

    If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).

Returns:



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb', line 232

def update(
    data: :unset, 
    ttl: :unset, 
    item_ttl: :unset, 
    collection_ttl: :unset, 
    if_match: :unset
)

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

    headers = Twilio::Values.of({ 'If-Match' => if_match, })
    payload = @version.update('POST', @uri, data: data, headers: headers)
    SyncMapItemInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        map_sid: @solution[:map_sid],
        key: @solution[:key],
    )
end