Class: Skyfall::Jetstream

Inherits:
Stream
  • Object
show all
Defined in:
lib/skyfall/jetstream.rb

Defined Under Namespace

Classes: AccountMessage, CommitMessage, IdentityMessage, Message, Operation, UnknownMessage

Constant Summary

Constants inherited from Stream

Stream::EVENTS, Stream::MAX_RECONNECT_INTERVAL

Instance Attribute Summary collapse

Attributes inherited from Stream

#auto_reconnect, #check_heartbeat, #heartbeat_interval, #heartbeat_timeout, #last_update, #user_agent

Instance Method Summary collapse

Methods inherited from Stream

#connect, #default_user_agent, #disconnect, #inspect, #inspectable_variables, #reconnect, #start_heartbeat_timer, #stop_heartbeat_timer, #version_string

Constructor Details

#initialize(server, params = {}) ⇒ Jetstream



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/skyfall/jetstream.rb', line 11

def initialize(server, params = {})
  require_relative 'jetstream/message'
  super(server)

  @root_url = @root_url.chomp('/')

  if URI(@root_url).path != ''
    raise ArgumentError, "Server parameter should not include any path"
  end

  @params = check_params(params)
  @cursor = @params.delete(:cursor)
end

Instance Attribute Details

#cursorObject

Returns the value of attribute cursor.



9
10
11
# File 'lib/skyfall/jetstream.rb', line 9

def cursor
  @cursor
end

Instance Method Details

#handle_message(msg) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/skyfall/jetstream.rb', line 25

def handle_message(msg)
  data = msg.data
  @handlers[:raw_message]&.call(data)

  if @handlers[:message]
    jet_message = Message.new(data)
    @cursor = jet_message.time_us
    @handlers[:message].call(jet_message)
  else
    @cursor = nil
  end
end