lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb in twilio-ruby-5.4.2 vs lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb in twilio-ruby-5.4.3
- old
+ new
@@ -17,13 +17,11 @@
# @return [UserList] UserList
def initialize(version, service_sid: nil)
super(version)
# Path Solution
- @solution = {
- service_sid: service_sid
- }
+ @solution = {service_sid: service_sid}
@uri = "/Services/#{@solution[:service_sid]}/Users"
end
##
# Retrieve a single page of UserInstance records from the API.
@@ -45,15 +43,11 @@
'POST',
@uri,
data: data
)
- UserInstance.new(
- @version,
- payload,
- service_sid: @solution[:service_sid],
- )
+ UserInstance.new(@version, payload, service_sid: @solution[:service_sid],)
end
##
# Lists UserInstance records from the API as a list.
# Unlike stream(), this operation is eager and will load `limit` records into
@@ -64,14 +58,11 @@
# not set will use the default value of 50 records. If no page_size is defined
# but a limit is defined, stream() will attempt to read the limit with the most
# efficient page size, i.e. min(limit, 1000)
# @return [Array] Array of up to limit results
def list(limit: nil, page_size: nil)
- self.stream(
- limit: limit,
- page_size: page_size
- ).entries
+ self.stream(limit: limit, page_size: page_size).entries
end
##
# Streams UserInstance records from the API as an Enumerable.
# This operation lazily loads records as efficiently as possible until the limit
@@ -84,13 +75,11 @@
# efficient page size, i.e. min(limit, 1000)
# @return [Enumerable] Enumerable that will yield up to limit results
def stream(limit: nil, page_size: nil)
limits = @version.read_limits(limit, page_size)
- page = self.page(
- page_size: limits[:page_size],
- )
+ page = self.page(page_size: limits[:page_size],)
@version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
end
##
@@ -98,13 +87,11 @@
# This operation lazily loads records as efficiently as possible until the limit
# is reached.
def each
limits = @version.read_limits
- page = self.page(
- page_size: limits[:page_size],
- )
+ page = self.page(page_size: limits[:page_size],)
@version.stream(page,
limit: limits[:limit],
page_limit: limits[:page_limit]).each {|x| yield x}
end
@@ -167,15 +154,11 @@
##
# Build an instance of UserInstance
# @param [Hash] payload Payload response from the API
# @return [UserInstance] UserInstance
def get_instance(payload)
- UserInstance.new(
- @version,
- payload,
- service_sid: @solution[:service_sid],
- )
+ UserInstance.new(@version, payload, service_sid: @solution[:service_sid],)
end
##
# Provide a user friendly representation
def to_s
@@ -192,18 +175,16 @@
# @return [UserContext] UserContext
def initialize(version, service_sid, sid)
super(version)
# Path Solution
- @solution = {
- service_sid: service_sid,
- sid: sid,
- }
+ @solution = {service_sid: service_sid, sid: sid,}
@uri = "/Services/#{@solution[:service_sid]}/Users/#{@solution[:sid]}"
# Dependents
@user_channels = nil
+ @user_bindings = nil
end
##
# Fetch a UserInstance
# @return [UserInstance] Fetched UserInstance
@@ -214,16 +195,11 @@
'GET',
@uri,
params,
)
- UserInstance.new(
- @version,
- payload,
- service_sid: @solution[:service_sid],
- sid: @solution[:sid],
- )
+ UserInstance.new(@version, payload, service_sid: @solution[:service_sid], sid: @solution[:sid],)
end
##
# Deletes the UserInstance
# @return [Boolean] true if delete succeeds, true otherwise
@@ -248,16 +224,11 @@
'POST',
@uri,
data: data,
)
- UserInstance.new(
- @version,
- payload,
- service_sid: @solution[:service_sid],
- sid: @solution[:sid],
- )
+ UserInstance.new(@version, payload, service_sid: @solution[:service_sid], sid: @solution[:sid],)
end
##
# Access the user_channels
# @return [UserChannelList]
@@ -273,10 +244,32 @@
@user_channels
end
##
+ # Access the user_bindings
+ # @return [UserBindingList]
+ # @return [UserBindingContext] if sid was passed.
+ def user_bindings(sid=:unset)
+ raise ArgumentError, 'sid cannot be nil' if sid.nil?
+
+ if sid != :unset
+ return UserBindingContext.new(@version, @solution[:service_sid], @solution[:sid], sid,)
+ end
+
+ unless @user_bindings
+ @user_bindings = UserBindingList.new(
+ @version,
+ service_sid: @solution[:service_sid],
+ user_sid: @solution[:sid],
+ )
+ end
+
+ @user_bindings
+ end
+
+ ##
# Provide a user friendly representation
def to_s
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.IpMessaging.V2.UserContext #{context}>"
end
@@ -311,27 +304,20 @@
'url' => payload['url'],
}
# Context
@instance_context = nil
- @params = {
- 'service_sid' => service_sid,
- 'sid' => sid || @properties['sid'],
- }
+ @params = {'service_sid' => service_sid, 'sid' => sid || @properties['sid'],}
end
##
# Generate an instance context for the instance, the context is capable of
# performing various actions. All instance actions are proxied to the context
# @return [UserContext] UserContext for this UserInstance
def context
unless @instance_context
- @instance_context = UserContext.new(
- @version,
- @params['service_sid'],
- @params['sid'],
- )
+ @instance_context = UserContext.new(@version, @params['service_sid'], @params['sid'],)
end
@instance_context
end
##
@@ -437,21 +423,24 @@
# @param [String] role_sid The role_sid
# @param [String] attributes The attributes
# @param [String] friendly_name The friendly_name
# @return [UserInstance] Updated UserInstance
def update(role_sid: :unset, attributes: :unset, friendly_name: :unset)
- context.update(
- role_sid: role_sid,
- attributes: attributes,
- friendly_name: friendly_name,
- )
+ context.update(role_sid: role_sid, attributes: attributes, friendly_name: friendly_name,)
end
##
# Access the user_channels
# @return [user_channels] user_channels
def user_channels
context.user_channels
+ end
+
+ ##
+ # Access the user_bindings
+ # @return [user_bindings] user_bindings
+ def user_bindings
+ context.user_bindings
end
##
# Provide a user friendly representation
def to_s
\ No newline at end of file