Sha256: 365eab1d7f5633e59beec94d9fa3beebca9d621797c28a54e9bbb8fcf35b4874

Contents?: true

Size: 1.3 KB

Versions: 19

Compression:

Stored size: 1.3 KB

Contents

module SalesforceStreamer
  class SalesforceTopicManager
    attr_reader :push_topics

    def initialize(push_topics:)
      @push_topics = push_topics
      @client = SalesforceClient.new
    end

    def upsert_topics!
      Log.info 'Starting to upsert PushTopic definitions into Salesforce'
      @push_topics.each do |push_topic|
        Log.info push_topic.name
        Log.debug push_topic.attributes.to_json
        upsert(push_topic) if diff?(push_topic)
      end
    end

    private

    def diff?(push_topic)
      hashie = @client.find_push_topic_by_name(push_topic.name)
      unless hashie
        Log.info "New PushTopic #{push_topic.name}"
        return true
      end
      Log.debug "Remote PushTopic found with hash=#{hashie.to_h}"
      push_topic.id = hashie.Id
      return true unless push_topic.query.eql?(hashie.Query)
      return true unless push_topic.notify_for_fields.eql?(hashie.NotifyForFields)
      return true unless push_topic.api_version.to_s.eql?(hashie.ApiVersion.to_s)

      Log.info 'No differences detected'
      false
    end

    def upsert(push_topic)
      Log.info "Upserting PushTopic"
      if Configuration.instance.manage_topics?
        @client.upsert_push_topic(push_topic)
      else
        Log.info 'Skipping upsert because manage topics is off'
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
salesforce_streamer-2.12.1 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.12.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.11.2 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.11.1 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.11.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.10.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.9.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.8.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.6.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.5.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.4.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.4.0.rc1 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.3.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.2.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.1.1 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.1.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.0.0 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.0.0.rc2 lib/salesforce_streamer/salesforce_topic_manager.rb
salesforce_streamer-2.0.0.rc1 lib/salesforce_streamer/salesforce_topic_manager.rb