Class: Twilio::REST::Chat::V1::ServiceContext::ChannelContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/chat/v1/service/channel.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/invite.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/member.rb,
lib/twilio-ruby/rest/chat/v1/service/channel/message.rb

Defined Under Namespace

Classes: InviteContext, InviteInstance, InviteList, InvitePage, MemberContext, MemberInstance, MemberList, MemberPage, MessageContext, MessageInstance, MessageList, MessagePage

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, sid) ⇒ ChannelContext

Initialize the ChannelContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Service](www.twilio.com/docs/api/chat/rest/services) to update the resource from.

  • sid (String)

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



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 171

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

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

    # Dependents
    @members = nil
    @messages = nil
    @invites = nil
end

Instance Method Details

#deleteBoolean

Delete the ChannelInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



186
187
188
189
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 186

def delete

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

#fetchChannelInstance

Fetch the ChannelInstance

Returns:



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

def fetch

    payload = @version.fetch('GET', @uri)
    ChannelInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end

#inspectObject

Provide a detailed, user friendly representation



299
300
301
302
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 299

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

#invites(sid = :unset) ⇒ InviteList, InviteContext

Access the invites

Returns:

Raises:

  • (ArgumentError)


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

def invites(sid=:unset)

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

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

    unless @invites
        @invites = InviteList.new(
            @version, service_sid: @solution[:service_sid], channel_sid: @solution[:sid], )
    end

 @invites
end

#members(sid = :unset) ⇒ MemberList, MemberContext

Access the members

Returns:

Raises:

  • (ArgumentError)


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 236

def members(sid=:unset)

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

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

    unless @members
        @members = MemberList.new(
            @version, service_sid: @solution[:service_sid], channel_sid: @solution[:sid], )
    end

 @members
end

#messages(sid = :unset) ⇒ MessageList, MessageContext

Access the messages

Returns:

Raises:

  • (ArgumentError)


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 255

def messages(sid=:unset)

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

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

    unless @messages
        @messages = MessageList.new(
            @version, service_sid: @solution[:service_sid], channel_sid: @solution[:sid], )
    end

 @messages
end

#to_sObject

Provide a user friendly representation



292
293
294
295
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 292

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

#update(friendly_name: :unset, unique_name: :unset, attributes: :unset) ⇒ ChannelInstance

Update the ChannelInstance

Parameters:

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

    A descriptive string that you create to describe the resource. It can be up to 64 characters long.

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

    An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource’s ‘sid` in the URL. This value must be 64 characters or less in length and be unique within the Service.

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

    A valid JSON string that contains application-specific data.

Returns:



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/twilio-ruby/rest/chat/v1/service/channel.rb', line 211

def update(
    friendly_name: :unset, 
    unique_name: :unset, 
    attributes: :unset
)

    data = Twilio::Values.of({
        'FriendlyName' => friendly_name,
        'UniqueName' => unique_name,
        'Attributes' => attributes,
    })

    payload = @version.update('POST', @uri, data: data)
    ChannelInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        sid: @solution[:sid],
    )
end