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

Class Method Summary collapse

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

Returns a new instance of Jetstream.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/skyfall/jetstream.rb', line 18

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.



16
17
18
# File 'lib/skyfall/jetstream.rb', line 16

def cursor
  @cursor
end

Class Method Details

.new(server, params = {}) ⇒ Object



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

def self.new(server, params = {})
  # to be removed in 0.6
  instance = self.allocate
  instance.send(:initialize, server, params)
  instance
end

Instance Method Details

#handle_message(msg) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/skyfall/jetstream.rb', line 32

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