Sha256: 426d7f9d86e4bf038d07c1d02d6047ddf9e91ee5a9efe3788820ff394d42ff9f

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module SalesforceStreamer
  # Models the PushTopic object for both Restforce and Streamer
  class PushTopic
    attr_accessor :id
    attr_reader :name, :description, :notify_for_fields, :query,
      :handler, :handler_constant, :api_version

    def initialize(data:)
      @handler = data['handler']
      @static_replay = data.dig('replay')&.to_i || -1
      @name = data.dig('salesforce', 'name')
      @api_version = data.dig('salesforce', 'api_version') || '41.0'
      @description = data.dig('salesforce', 'description') || @name
      @notify_for_fields = data.dig('salesforce', 'notify_for_fields') || 'Referenced'
      @query = strip_spaces(data.dig('salesforce', 'query'))
      validate!
    end

    def replay
      ReplayPersistence.retrieve(name) || @static_replay
    end

    def to_s
      "PushTopic id=#{id} name=#{name} handler=#{handler} " \
        "replay=#{replay} notify_for_fields=#{notify_for_fields} " \
        "description=#{description} api_version=#{api_version} query=#{query}"
    end

    private

    def validate!
      fail(PushTopicNameTooLongError, @name) if @name.size > 25

      @handler_constant = Object.const_get(@handler)
      true
    rescue NameError, TypeError => e
      message = 'handler=' + @handler.to_s + ' exception=' + e.to_s
      raise(PushTopicHandlerMissingError, message)
    end

    def strip_spaces(str)
      fail(NilQueryError, @name) unless str

      str.gsub(/\s+/, ' ')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
salesforce_streamer-1.1.3 lib/salesforce_streamer/push_topic.rb
salesforce_streamer-1.1.1 lib/salesforce_streamer/push_topic.rb