lib/twilio-ruby/rest/ip_messaging/v1/service/channel/message.rb in twilio-ruby-5.0.0.rc9 vs lib/twilio-ruby/rest/ip_messaging/v1/service/channel/message.rb in twilio-ruby-5.0.0.rc10

- old
+ new

@@ -14,11 +14,10 @@ ## # Initialize the MessageList # @param [Version] version Version that contains the resource # @param [String] service_sid The service_sid # @param [String] channel_sid The sid - # @return [MessageList] MessageList def initialize(version, service_sid: nil, channel_sid: nil) super(version) # Path Solution @@ -32,11 +31,10 @@ ## # Retrieve a single page of MessageInstance records from the API. # Request is executed immediately. # @param [String] body The body # @param [String] from The from - # @return [MessageInstance] Newly created MessageInstance def create(body: nil, from: nil) data = { 'Body' => body, 'From' => from, @@ -49,12 +47,12 @@ ) return MessageInstance.new( @version, payload, - service_sid: @solution['service_sid'], - channel_sid: @solution['channel_sid'], + service_sid: @solution[:service_sid], + channel_sid: @solution[:channel_sid], ) end ## # Lists MessageInstance records from the API as a list. @@ -64,11 +62,10 @@ # guarantees to never return more than limit. Default is no limit # @param [Integer] page_size Number of records to fetch per request, when 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 @@ -83,11 +80,10 @@ # guarantees to never return more than limit. Default is no limit # @param [Integer] page_size Number of records to fetch per request, when 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 [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( @@ -123,11 +119,10 @@ # Retrieve a single page of MessageInstance records from the API. # Request is executed immediately. # @param [String] page_token PageToken provided by the API # @param [Integer] page_number Page Number, this value is simply for client state # @param [Integer] page_size Number of records to return, defaults to 50 - # @return [Page] Page of MessageInstance def page(page_token: nil, page_number: nil, page_size: nil) params = { 'PageToken' => page_token, 'Page' => page_number, @@ -154,11 +149,10 @@ # @param [Version] version Version that contains the resource # @param [Response] response Response from the API # @param [Hash] solution Path solution for the resource # @param [String] service_sid The service_sid # @param [String] channel_sid The sid - # @return [MessagePage] MessagePage def initialize(version, response, solution) super(version, response) # Path Solution @@ -166,18 +160,17 @@ end ## # Build an instance of MessageInstance # @param [Hash] payload Payload response from the API - # @return [MessageInstance] MessageInstance def get_instance(payload) return MessageInstance.new( @version, payload, - service_sid: @solution['service_sid'], - channel_sid: @solution['channel_sid'], + service_sid: @solution[:service_sid], + channel_sid: @solution[:channel_sid], ) end ## # Provide a user friendly representation @@ -191,11 +184,10 @@ # Initialize the MessageContext # @param [Version] version Version that contains the resource # @param [String] service_sid The service_sid # @param [String] channel_sid The channel_sid # @param [String] sid The sid - # @return [MessageContext] MessageContext def initialize(version, service_sid, channel_sid, sid) super(version) # Path Solution @@ -220,17 +212,50 @@ ) return MessageInstance.new( @version, payload, - service_sid: @solution['service_sid'], - channel_sid: @solution['channel_sid'], - sid: @solution['sid'], + service_sid: @solution[:service_sid], + channel_sid: @solution[:channel_sid], + sid: @solution[:sid], ) end ## + # Deletes the MessageInstance + # @return [Boolean] true if delete succeeds, true otherwise + def delete + return @version.delete('delete', @uri) + end + + ## + # Update the MessageInstance + # @param [String] body The body + # @param [Hash] attributes The attributes + # @return [MessageInstance] Updated MessageInstance + def update(body: nil, attributes: nil) + data = { + 'Body' => body, + 'Attributes' => attributes, + } + + payload = @version.update( + 'POST', + @uri, + data: data, + ) + + return MessageInstance.new( + @version, + payload, + service_sid: @solution[:service_sid], + channel_sid: @solution[:channel_sid], + sid: @solution[:sid], + ) + end + + ## # Provide a user friendly representation def to_s context = @solution.map {|k, v| "#{k}: #{v}"}.join(',') "#<Twilio.IpMessaging.V1.MessageContext #{context}>" end @@ -242,11 +267,10 @@ # @param [Version] version Version that contains the resource # @param [Hash] payload payload that contains response from Twilio # @param [String] service_sid The service_sid # @param [String] channel_sid The sid # @param [String] sid The sid - # @return [MessageInstance] MessageInstance def initialize(version, payload, service_sid: nil, channel_sid: nil, sid: nil) super(version) # Marshaled Properties @@ -274,11 +298,10 @@ ## # Generate an instance context for the instance, the context is capable of # performing various actions. All instance actions are proxied to the context # @param [Version] version Version that contains the resource - # @return [MessageContext] MessageContext for this MessageInstance def context unless @instance_context @instance_context = MessageContext.new( @version, @@ -332,17 +355,36 @@ ## # Fetch a MessageInstance # @return [MessageInstance] Fetched MessageInstance def fetch - @context.fetch() + context.fetch end ## + # Deletes the MessageInstance + # @return [Boolean] true if delete succeeds, true otherwise + def delete + context.delete + end + + ## + # Update the MessageInstance + # @param [String] body The body + # @param [Hash] attributes The attributes + # @return [MessageInstance] Updated MessageInstance + def update(body: nil, attributes: nil) + context.update( + body: body, + attributes: attributes, + ) + end + + ## # Provide a user friendly representation def to_s - context = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "<Twilio.IpMessaging.V1.MessageInstance #{context}>" + values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") + "<Twilio.IpMessaging.V1.MessageInstance #{values}>" end end end end end \ No newline at end of file