Class: Twilio::REST::Events::V1::SubscriptionContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/events/v1/subscription.rb,
lib/twilio-ruby/rest/events/v1/subscription/subscribed_event.rb

Defined Under Namespace

Classes: SubscribedEventContext, SubscribedEventInstance, SubscribedEventList, SubscribedEventPage

Instance Method Summary collapse

Constructor Details

#initialize(version, sid) ⇒ SubscriptionContext

Initialize the SubscriptionContext

Parameters:

  • version (Version)

    Version that contains the resource

  • sid (String)

    A 34 character string that uniquely identifies this Subscription.



176
177
178
179
180
181
182
183
184
185
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 176

def initialize(version, sid)
    super(version)

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

    # Dependents
    @subscribed_events = nil
end

Instance Method Details

#deleteBoolean

Delete the SubscriptionInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



189
190
191
192
193
194
195
196
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 189

def delete

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

#fetchSubscriptionInstance

Fetch the SubscriptionInstance

Returns:



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 201

def fetch

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

#inspectObject

Provide a detailed, user friendly representation



278
279
280
281
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 278

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

#subscribed_events(type = :unset) ⇒ SubscribedEventList, SubscribedEventContext

Access the subscribed_events

Returns:

Raises:

  • (ArgumentError)


253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 253

def subscribed_events(type=:unset)

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

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

    unless @subscribed_events
        @subscribed_events = SubscribedEventList.new(
            @version, subscription_sid: @solution[:sid], )
    end

 @subscribed_events
end

#to_sObject

Provide a user friendly representation



271
272
273
274
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 271

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

#update(description: :unset, sink_sid: :unset, receive_events_from_subaccounts: :unset) ⇒ SubscriptionInstance

Update the SubscriptionInstance

Parameters:

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

    A human readable description for the Subscription.

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

    The SID of the sink that events selected by this subscription should be sent to. Sink must be active for the subscription to be created.

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

    Receive events from all children accounts in the parent account subscription.

Returns:



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/twilio-ruby/rest/events/v1/subscription.rb', line 223

def update(
    description: :unset, 
    sink_sid: :unset, 
    receive_events_from_subaccounts: :unset
)

    data = Twilio::Values.of({
        'Description' => description,
        'SinkSid' => sink_sid,
        'ReceiveEventsFromSubaccounts' => receive_events_from_subaccounts,
    })

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