Sha256: 0fe9122da0a8852e9eda4f03a1d1575a86ab672b0c145c26aaa26ed1194e99b6

Contents?: true

Size: 1.44 KB

Versions: 11

Compression:

Stored size: 1.44 KB

Contents

class ForeignOffice::Busses::PubnubBus < ForeignOffice::Busses::GenericBus

  def self.config(config)
    self.publish_key = config[:publish_key]
    self.subscribe_key = config[:subscribe_key]
    self.secret_key = config[:secret_key]
  end

  def self.publish_key=(publish_key)
    @publish_key = publish_key
  end

  def self.publish_key
    @publish_key
  end

  def self.subscribe_key=(subscribe_key)
    @subscribe_key = subscribe_key
  end

  def self.subscribe_key
    @subscribe_key
  end

  def self.secret_key=(secret_key)
    @secret_key = secret_key
  end

  def self.secret_key
    @secret_key
  end

  def self.connection
    @pubnub ||= ::Pubnub.new(
      publish_key:    self.publish_key, # publish_key only required if publishing.
      subscribe_key:  self.subscribe_key, # required
      secret_key:     self.secret_key,
      ssl:            true
    )
  end

  def self.publish(message)
    channel = message[:channel]

    if browser_tab_id = message[:browser_tab_id]
      channel += "@#{browser_tab_id}" 
    end

    self.connection.publish(
      channel:  channel,
      message:  message,
      http_sync: true
    ) do |envelope|
      if '200' != envelope.status_code.to_s
        Rails.logger.error "ForeignOffice error esponse:"
        Rails.logger.error envelope.message
        Rails.logger.error envelope.channel
        Rails.logger.error envelope.status_code
        Rails.logger.error envelope.timetoken
      end
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foreign_office-0.17.6 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.5 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.4 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.3 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.2 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.17.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.16.6 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.16.5 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.16.4 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.16.3 lib/foreign_office/busses/pubnub_bus.rb