Class: Twilio::REST::Notify::V1::ServiceContext::UserContext

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

Overview

PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.

Defined Under Namespace

Classes: SegmentMembershipContext, SegmentMembershipInstance, SegmentMembershipList, SegmentMembershipPage, UserBindingContext, UserBindingInstance, UserBindingList, UserBindingPage

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, identity) ⇒ UserContext

Initialize the UserContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The service_sid

  • identity (String)

    The identity



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

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

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

  # Dependents
  @bindings = nil
  @segment_memberships = nil
end

Instance Method Details

#bindings(sid = :unset) ⇒ UserBindingList, UserBindingContext

Access the bindings

Returns:

Raises:

  • (ArgumentError)


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/twilio-ruby/rest/notify/v1/service/user.rb', line 229

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

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

  unless @bindings
    @bindings = UserBindingList.new(
        @version,
        service_sid: @solution[:service_sid],
        identity: @solution[:identity],
    )
  end

  @bindings
end

#deleteBoolean

Deletes the UserInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



201
202
203
# File 'lib/twilio-ruby/rest/notify/v1/service/user.rb', line 201

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

#fetchUserInstance

Fetch a UserInstance

Returns:



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

def fetch
  params = Twilio::Values.of({})

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

  UserInstance.new(
      @version,
      payload,
      service_sid: @solution[:service_sid],
      identity: @solution[:identity],
  )
end

#segment_memberships(segment = :unset) ⇒ SegmentMembershipList, SegmentMembershipContext

Access the segment_memberships

Returns:

Raises:

  • (ArgumentError)


251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/twilio-ruby/rest/notify/v1/service/user.rb', line 251

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

  if segment != :unset
    return SegmentMembershipContext.new(
        @version,
        @solution[:service_sid],
        @solution[:identity],
        segment,
    )
  end

  unless @segment_memberships
    @segment_memberships = SegmentMembershipList.new(
        @version,
        service_sid: @solution[:service_sid],
        identity: @solution[:identity],
    )
  end

  @segment_memberships
end

#to_sObject

Provide a user friendly representation



276
277
278
279
# File 'lib/twilio-ruby/rest/notify/v1/service/user.rb', line 276

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