Sha256: b245f4dd0cdb79cdfa3d9c267e84839ba2397e8432c4137b752d6b162900dc4b

Contents?: true

Size: 1.39 KB

Versions: 30

Compression:

Stored size: 1.39 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,
      error_callback: lambda { |msg| Rails.logger.error( msg.inspect )}
    )
  end

  def self.publish(message)
    message.symbolize_keys!
    self.connection.publish(
      channel:  message[: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

30 entries across 30 versions & 1 rubygems

Version Path
foreign_office-0.15.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.15.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.14.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.13.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.12.3 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.12.2 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.12.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.12.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.11.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.10.3 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.10.2 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.10.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.10.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.9.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.9.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.8.1 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.8.0 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.7.3 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.7.2 lib/foreign_office/busses/pubnub_bus.rb
foreign_office-0.7.1 lib/foreign_office/busses/pubnub_bus.rb