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

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/proxy/v1/service.rb,
lib/twilio-ruby/rest/proxy/v1/service/session.rb,
lib/twilio-ruby/rest/proxy/v1/service/phone_number.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: PhoneNumberContext, PhoneNumberInstance, PhoneNumberList, PhoneNumberPage, SessionContext, SessionInstance, SessionList, SessionPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ ServiceContext

Initialize the ServiceContext



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 182

def initialize(version, sid)
    super(version)

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

    # Dependents
    @sessions = nil
    @phone_numbers = nil
end

Instance Method Details

#deleteBoolean

Delete the ServiceInstance



196
197
198
199
200
201
202
203
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 196

def delete

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

#fetchServiceInstance

Fetch the ServiceInstance



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 208

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



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

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

#phone_numbers(sid = :unset) ⇒ PhoneNumberList, PhoneNumberContext

Access the phone_numbers

Raises:

  • (ArgumentError)


294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 294

def phone_numbers(sid=:unset)

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

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

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

 @phone_numbers
end

#sessions(sid = :unset) ⇒ SessionList, SessionContext

Access the sessions

Raises:

  • (ArgumentError)


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 275

def sessions(sid=:unset)

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

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

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

 @sessions
end

#to_sObject

Provide a user friendly representation



312
313
314
315
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 312

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

#update(unique_name: :unset, default_ttl: :unset, callback_url: :unset, geo_match_level: :unset, number_selection_behavior: :unset, intercept_callback_url: :unset, out_of_session_callback_url: :unset, chat_instance_sid: :unset) ⇒ ServiceInstance

Update the ServiceInstance



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/twilio-ruby/rest/proxy/v1/service.rb', line 235

def update(
    unique_name: :unset, 
    default_ttl: :unset, 
    callback_url: :unset, 
    geo_match_level: :unset, 
    number_selection_behavior: :unset, 
    intercept_callback_url: :unset, 
    out_of_session_callback_url: :unset, 
    chat_instance_sid: :unset
)

    data = Twilio::Values.of({
        'UniqueName' => unique_name,
        'DefaultTtl' => default_ttl,
        'CallbackUrl' => callback_url,
        'GeoMatchLevel' => geo_match_level,
        'NumberSelectionBehavior' => number_selection_behavior,
        'InterceptCallbackUrl' => intercept_callback_url,
        'OutOfSessionCallbackUrl' => out_of_session_callback_url,
        'ChatInstanceSid' => chat_instance_sid,
    })

    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