Class: Twilio::REST::Proxy::V1::ServiceContext::SessionContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/proxy/v1/service/session.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/interaction.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/participant.rb,
lib/twilio-ruby/rest/proxy/v1/service/session/participant/message_interaction.rb

Defined Under Namespace

Classes: InteractionContext, InteractionInstance, InteractionInstanceMetadata, InteractionList, InteractionListResponse, InteractionPage, InteractionPageMetadata, ParticipantContext, ParticipantInstance, ParticipantInstanceMetadata, ParticipantList, ParticipantListResponse, ParticipantPage, ParticipantPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, sid) ⇒ SessionContext

Initialize the SessionContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the parent [Service](www.twilio.com/docs/proxy/api/service) of the resource to update.

  • sid (String)

    The Twilio-provided string that uniquely identifies the Session resource to update.



258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 258

def initialize(version, service_sid, sid)
    super(version)
    

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

    # Dependents
    @interactions = nil
    @participants = nil
end

Instance Method Details

#deleteBoolean

Delete the SessionInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



273
274
275
276
277
278
279
280
281
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 273

def delete

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    

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

#delete_with_metadataBoolean

Delete the SessionInstanceMetadata

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 286

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      session_instance = SessionInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      SessionInstanceMetadata.new(@version, session_instance, response.headers, response.status_code)
end

#fetchSessionInstance

Fetch the SessionInstance

Returns:



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 305

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    SessionInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataSessionInstance

Fetch the SessionInstanceMetadata

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 325

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    session_instance = SessionInstance.new(
        @version,
        response.body,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
    SessionInstanceMetadata.new(
        @version,
        session_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



468
469
470
471
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 468

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

#interactions(sid = :unset) ⇒ InteractionList, InteractionContext

Access the interactions

Returns:

Raises:

  • (ArgumentError)


424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 424

def interactions(sid=:unset)

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

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

    unless @interactions
        @interactions = InteractionList.new(
            @version, service_sid: @solution[:service_sid], session_sid: @solution[:sid], )
    end

 @interactions
end

#participants(sid = :unset) ⇒ ParticipantList, ParticipantContext

Access the participants

Returns:

Raises:

  • (ArgumentError)


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 443

def participants(sid=:unset)

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

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

    unless @participants
        @participants = ParticipantList.new(
            @version, service_sid: @solution[:service_sid], session_sid: @solution[:sid], )
    end

 @participants
end

#to_sObject

Provide a user friendly representation



461
462
463
464
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 461

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

#update(date_expiry: :unset, ttl: :unset, status: :unset) ⇒ SessionInstance

Update the SessionInstance

Parameters:

  • date_expiry (Time) (defaults to: :unset)

    The [ISO 8601](en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the ‘ttl` value.

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

    The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session’s last Interaction.

  • status (Status) (defaults to: :unset)

Returns:



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 354

def update(
  date_expiry: :unset, 
  ttl: :unset, 
  status: :unset
)

    data = Twilio::Values.of({
        'DateExpiry' => Twilio.serialize_iso8601_datetime(date_expiry),
        'Ttl' => ttl,
        'Status' => status,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.update('POST', @uri, data: data, headers: headers)
    SessionInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end

#update_with_metadata(date_expiry: :unset, ttl: :unset, status: :unset) ⇒ SessionInstance

Update the SessionInstanceMetadata

Parameters:

  • date_expiry (Time) (defaults to: :unset)

    The [ISO 8601](en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the ‘ttl` value.

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

    The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session’s last Interaction.

  • status (Status) (defaults to: :unset)

Returns:



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/twilio-ruby/rest/proxy/v1/service/session.rb', line 387

def (
  date_expiry: :unset, 
  ttl: :unset, 
  status: :unset
)

    data = Twilio::Values.of({
        'DateExpiry' => Twilio.serialize_iso8601_datetime(date_expiry),
        'Ttl' => ttl,
        'Status' => status,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    session_instance = SessionInstance.new(
        @version,
        response.body,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
    SessionInstanceMetadata.new(
        @version,
        session_instance,
        response.headers,
        response.status_code
    )
end