Sha256: 4e11a823643729764d11731586d9de6659fbeeaaf6cf731f328bbe8f68ce3695

Contents?: true

Size: 757 Bytes

Versions: 46

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true
require 'pusher-client'

module Dato
  module Watch
    class SiteChangeWatcher
      attr_reader :site_id

      PUSHER_API_KEY = '75e6ef0fe5d39f481626'

      def initialize(site_id)
        PusherClient.logger.level = Logger::WARN
        @site_id = site_id
        @socket = nil
      end

      def connect(&block)
        return if connected?

        @socket = PusherClient::Socket.new(PUSHER_API_KEY, secure: true)
        @socket.subscribe("site-#{site_id}")
        @socket.bind('site:change', &block)
        @socket.connect(true)

        self
      end

      def connected?
        @socket && @socket.connected
      end

      def disconnect!
        connected? && @socket.disconnect
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
dato-0.3.28 lib/dato/watch/site_change_watcher.rb
dato-0.3.27 lib/dato/watch/site_change_watcher.rb
dato-0.3.26 lib/dato/watch/site_change_watcher.rb
dato-0.3.25 lib/dato/watch/site_change_watcher.rb
dato-0.3.24 lib/dato/watch/site_change_watcher.rb
dato-0.3.23 lib/dato/watch/site_change_watcher.rb
dato-0.3.22 lib/dato/watch/site_change_watcher.rb
dato-0.3.21 lib/dato/watch/site_change_watcher.rb
dato-0.3.20 lib/dato/watch/site_change_watcher.rb
dato-0.3.19 lib/dato/watch/site_change_watcher.rb
dato-0.3.18 lib/dato/watch/site_change_watcher.rb
dato-0.3.17 lib/dato/watch/site_change_watcher.rb
dato-0.3.16 lib/dato/watch/site_change_watcher.rb
dato-0.3.15 lib/dato/watch/site_change_watcher.rb
dato-0.3.14 lib/dato/watch/site_change_watcher.rb
dato-0.3.13 lib/dato/watch/site_change_watcher.rb
dato-0.3.12 lib/dato/watch/site_change_watcher.rb
dato-0.3.9.1 lib/dato/watch/site_change_watcher.rb
dato-0.3.11 lib/dato/watch/site_change_watcher.rb
dato-0.3.10 lib/dato/watch/site_change_watcher.rb