Sha256: 8275e509c1ce58bc8b222a543048de64a584a81e2cdf7e3392d8a502571386cb

Contents?: true

Size: 758 Bytes

Versions: 8

Compression:

Stored size: 758 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

8 entries across 8 versions & 1 rubygems

Version Path
dato-0.6.18 lib/dato/watch/site_change_watcher.rb
dato-0.6.17 lib/dato/watch/site_change_watcher.rb
dato-0.6.16 lib/dato/watch/site_change_watcher.rb
dato-0.6.15 lib/dato/watch/site_change_watcher.rb
dato-0.6.14 lib/dato/watch/site_change_watcher.rb
dato-0.6.12 lib/dato/watch/site_change_watcher.rb
dato-0.6.11 lib/dato/watch/site_change_watcher.rb
dato-0.6.10 lib/dato/watch/site_change_watcher.rb