## # This code was generated by # \ / _ _ _| _ _ # | (_)\/(_)(_|\/| |(/_ v1.0.0 # / / # # frozen_string_literal: true module Twilio module REST class Events < Domain class V1 < Version ## # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution. class SinkList < ListResource ## # Initialize the SinkList # @param [Version] version Version that contains the resource # @return [SinkList] SinkList def initialize(version) super(version) # Path Solution @solution = {} @uri = "/Sinks" end ## # Create the SinkInstance # @param [String] description A human readable description for the Sink **This # value should not contain PII.** # @param [Hash] sink_configuration The information required for Twilio to connect # to the provided Sink encoded as JSON. # @param [sink.SinkType] sink_type The Sink type. Can only be "kinesis" or # "webhook" currently. # @return [SinkInstance] Created SinkInstance def create(description: nil, sink_configuration: nil, sink_type: nil) data = Twilio::Values.of({ 'Description' => description, 'SinkConfiguration' => Twilio.serialize_object(sink_configuration), 'SinkType' => sink_type, }) payload = @version.create('POST', @uri, data: data) SinkInstance.new(@version, payload, ) end ## # Lists SinkInstance records from the API as a list. # Unlike stream(), this operation is eager and will load `limit` records into # memory before returning. # @param [Boolean] in_use A boolean query parameter filtering the results to # return sinks used/not used by a subscription. # @param [String] status A String query parameter filtering the results by status # `initialized`, `validating`, `active` or `failed`. # @param [Integer] limit Upper limit for the number of records to return. stream() # 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(in_use: :unset, status: :unset, limit: nil, page_size: nil) self.stream(in_use: in_use, status: status, limit: limit, page_size: page_size).entries end ## # Streams SinkInstance records from the API as an Enumerable. # This operation lazily loads records as efficiently as possible until the limit # is reached. # @param [Boolean] in_use A boolean query parameter filtering the results to # return sinks used/not used by a subscription. # @param [String] status A String query parameter filtering the results by status # `initialized`, `validating`, `active` or `failed`. # @param [Integer] limit Upper limit for the number of records to return. stream() # 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(in_use: :unset, status: :unset, limit: nil, page_size: nil) limits = @version.read_limits(limit, page_size) page = self.page(in_use: in_use, status: status, page_size: limits[:page_size], ) @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) end ## # When passed a block, yields SinkInstance records from the API. # 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], ) @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]).each {|x| yield x} end ## # Retrieve a single page of SinkInstance records from the API. # Request is executed immediately. # @param [Boolean] in_use A boolean query parameter filtering the results to # return sinks used/not used by a subscription. # @param [String] status A String query parameter filtering the results by status # `initialized`, `validating`, `active` or `failed`. # @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 SinkInstance def page(in_use: :unset, status: :unset, page_token: :unset, page_number: :unset, page_size: :unset) params = Twilio::Values.of({ 'InUse' => in_use, 'Status' => status, 'PageToken' => page_token, 'Page' => page_number, 'PageSize' => page_size, }) response = @version.page('GET', @uri, params: params) SinkPage.new(@version, response, @solution) end ## # Retrieve a single page of SinkInstance records from the API. # Request is executed immediately. # @param [String] target_url API-generated URL for the requested results page # @return [Page] Page of SinkInstance def get_page(target_url) response = @version.domain.request( 'GET', target_url ) SinkPage.new(@version, response, @solution) end ## # Provide a user friendly representation def to_s '#' end end ## # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution. class SinkPage < Page ## # Initialize the SinkPage # @param [Version] version Version that contains the resource # @param [Response] response Response from the API # @param [Hash] solution Path solution for the resource # @return [SinkPage] SinkPage def initialize(version, response, solution) super(version, response) # Path Solution @solution = solution end ## # Build an instance of SinkInstance # @param [Hash] payload Payload response from the API # @return [SinkInstance] SinkInstance def get_instance(payload) SinkInstance.new(@version, payload, ) end ## # Provide a user friendly representation def to_s '' end end ## # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution. class SinkContext < InstanceContext ## # Initialize the SinkContext # @param [Version] version Version that contains the resource # @param [String] sid A 34 character string that uniquely identifies this Sink. # @return [SinkContext] SinkContext def initialize(version, sid) super(version) # Path Solution @solution = {sid: sid, } @uri = "/Sinks/#{@solution[:sid]}" # Dependents @sink_test = nil @sink_validate = nil end ## # Fetch the SinkInstance # @return [SinkInstance] Fetched SinkInstance def fetch payload = @version.fetch('GET', @uri) SinkInstance.new(@version, payload, sid: @solution[:sid], ) end ## # Delete the SinkInstance # @return [Boolean] true if delete succeeds, false otherwise def delete @version.delete('DELETE', @uri) end ## # Update the SinkInstance # @param [String] description A human readable description for the Sink **This # value should not contain PII.** # @return [SinkInstance] Updated SinkInstance def update(description: nil) data = Twilio::Values.of({'Description' => description, }) payload = @version.update('POST', @uri, data: data) SinkInstance.new(@version, payload, sid: @solution[:sid], ) end ## # Access the sink_test # @return [SinkTestList] # @return [SinkTestContext] def sink_test unless @sink_test @sink_test = SinkTestList.new(@version, sid: @solution[:sid], ) end @sink_test end ## # Access the sink_validate # @return [SinkValidateList] # @return [SinkValidateContext] def sink_validate unless @sink_validate @sink_validate = SinkValidateList.new(@version, sid: @solution[:sid], ) end @sink_validate end ## # Provide a user friendly representation def to_s context = @solution.map {|k, v| "#{k}: #{v}"}.join(',') "#" end ## # Provide a detailed, user friendly representation def inspect context = @solution.map {|k, v| "#{k}: #{v}"}.join(',') "#" end end ## # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution. class SinkInstance < InstanceResource ## # Initialize the SinkInstance # @param [Version] version Version that contains the resource # @param [Hash] payload payload that contains response from Twilio # @param [String] sid A 34 character string that uniquely identifies this Sink. # @return [SinkInstance] SinkInstance def initialize(version, payload, sid: nil) super(version) # Marshaled Properties @properties = { 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']), 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']), 'description' => payload['description'], 'sid' => payload['sid'], 'sink_configuration' => payload['sink_configuration'], 'sink_type' => payload['sink_type'], 'status' => payload['status'], 'url' => payload['url'], 'links' => payload['links'], } # Context @instance_context = nil @params = {'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 [SinkContext] SinkContext for this SinkInstance def context unless @instance_context @instance_context = SinkContext.new(@version, @params['sid'], ) end @instance_context end ## # @return [Time] The date this Sink was created def date_created @properties['date_created'] end ## # @return [Time] The date this Sink was updated def date_updated @properties['date_updated'] end ## # @return [String] Sink Description def description @properties['description'] end ## # @return [String] A string that uniquely identifies this Sink. def sid @properties['sid'] end ## # @return [Hash] JSON Sink configuration. def sink_configuration @properties['sink_configuration'] end ## # @return [sink.SinkType] Sink type. def sink_type @properties['sink_type'] end ## # @return [sink.Status] The Status of this Sink def status @properties['status'] end ## # @return [String] The URL of this resource. def url @properties['url'] end ## # @return [String] Nested resource URLs. def links @properties['links'] end ## # Fetch the SinkInstance # @return [SinkInstance] Fetched SinkInstance def fetch context.fetch end ## # Delete the SinkInstance # @return [Boolean] true if delete succeeds, false otherwise def delete context.delete end ## # Update the SinkInstance # @param [String] description A human readable description for the Sink **This # value should not contain PII.** # @return [SinkInstance] Updated SinkInstance def update(description: nil) context.update(description: description, ) end ## # Access the sink_test # @return [sink_test] sink_test def sink_test context.sink_test end ## # Access the sink_validate # @return [sink_validate] sink_validate def sink_validate context.sink_validate end ## # Provide a user friendly representation def to_s values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") "" end ## # Provide a detailed, user friendly representation def inspect values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") "" end end end end end end