Class: Twilio::REST::Conversations::V1::ServiceContext::UserContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/service/user.rb,
lib/twilio-ruby/rest/conversations/v1/service/user/user_conversation.rb

Defined Under Namespace

Classes: UserConversationContext, UserConversationInstance, UserConversationList, UserConversationPage

Instance Method Summary collapse

Constructor Details

#initialize(version, chat_service_sid, sid) ⇒ UserContext

Initialize the UserContext

Parameters:

  • version (Version)

    Version that contains the resource

  • chat_service_sid (String)

    The SID of the Conversation Service to fetch the User resource from.

  • sid (String)

    The SID of the User resource to fetch. This value can be either the `sid` or the `identity` of the User resource to fetch.


186
187
188
189
190
191
192
193
194
195
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 186

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

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

  # Dependents
  @user_conversations = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the UserInstance

Parameters:

  • x_twilio_webhook_enabled (user.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise


232
233
234
235
236
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 232

def delete(x_twilio_webhook_enabled: :unset)
  headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })

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

#fetchUserInstance

Fetch the UserInstance

Returns:


241
242
243
244
245
246
247
248
249
250
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 241

def fetch
  payload = @version.fetch('GET', @uri)

  UserInstance.new(
      @version,
      payload,
      chat_service_sid: @solution[:chat_service_sid],
      sid: @solution[:sid],
  )
end

#inspectObject

Provide a detailed, user friendly representation


288
289
290
291
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 288

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

#to_sObject

Provide a user friendly representation


281
282
283
284
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 281

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

#update(friendly_name: :unset, attributes: :unset, role_sid: :unset, x_twilio_webhook_enabled: :unset) ⇒ UserInstance

Update the UserInstance

Parameters:

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

    The string that you assigned to describe the resource.

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

    The JSON Object string that stores application-specific data. If attributes have not been set, `{}` is returned.

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

    The SID of a service-level Role to assign to the user.

  • x_twilio_webhook_enabled (user.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:


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

def update(friendly_name: :unset, attributes: :unset, role_sid: :unset, x_twilio_webhook_enabled: :unset)
  data = Twilio::Values.of({
      'FriendlyName' => friendly_name,
      'Attributes' => attributes,
      'RoleSid' => role_sid,
  })
  headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })

  payload = @version.update('POST', @uri, data: data, headers: headers)

  UserInstance.new(
      @version,
      payload,
      chat_service_sid: @solution[:chat_service_sid],
      sid: @solution[:sid],
  )
end

#user_conversations(conversation_sid = :unset) ⇒ UserConversationList, UserConversationContext

Access the user_conversations

Returns:

Raises:

  • (ArgumentError)

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/twilio-ruby/rest/conversations/v1/service/user.rb', line 256

def user_conversations(conversation_sid=:unset)
  raise ArgumentError, 'conversation_sid cannot be nil' if conversation_sid.nil?

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

  unless @user_conversations
    @user_conversations = UserConversationList.new(
        @version,
        chat_service_sid: @solution[:chat_service_sid],
        user_sid: @solution[:sid],
    )
  end

  @user_conversations
end