class CoinRail::Realtime::Client

Public Class Methods

new() click to toggle source
# File lib/coinrail/realtime/client.rb, line 24
def initialize
  @pubnub = Pubnub.new(subscribe_key: Realtime::PUBNUB_SUBSCRIBE_KEY)

  @callback = Pubnub::SubscribeCallback.new(
      message: ->(envelope) {
        channel_name = envelope.result[:data][:subscribed_channel].gsub('lightning_', '').downcase.to_sym
        message = envelope.result[:data][:message]
        send(channel_name).call(message) if send(channel_name)
      },
      presence: ->(envelope) {},
      status: ->(envelope) {}
  )

  @pubnub.add_listener(callback: @callback)
  @pubnub.subscribe(channels: Realtime::CHANNEL_NAMES)
end