Class: Skyfall::Jetstream::Message

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Message

Returns a new instance of Message.



35
36
37
38
39
40
# File 'lib/skyfall/jetstream/message.rb', line 35

def initialize(json)
  @json = json
  @type = @json['kind'].to_sym
  @did = @json['did']
  @time_us = @json['time_us']
end

Instance Attribute Details

#didObject (readonly) Also known as: repo

Returns the value of attribute did.



13
14
15
# File 'lib/skyfall/jetstream/message.rb', line 13

def did
  @did
end

#jsonObject (readonly)

:nodoc: - consider this as semi-private API



18
19
20
# File 'lib/skyfall/jetstream/message.rb', line 18

def json
  @json
end

#time_usObject (readonly) Also known as: seq

Returns the value of attribute time_us.



13
14
15
# File 'lib/skyfall/jetstream/message.rb', line 13

def time_us
  @time_us
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/skyfall/jetstream/message.rb', line 13

def type
  @type
end

Class Method Details

.new(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/skyfall/jetstream/message.rb', line 20

def self.new(data)
  json = JSON.parse(data)

  message_class = case json['kind']
    when 'account'  then Jetstream::AccountMessage
    when 'commit'   then Jetstream::CommitMessage
    when 'identity' then Jetstream::IdentityMessage
    else Jetstream::UnknownMessage
  end

  message = message_class.allocate
  message.send(:initialize, json)
  message
end

Instance Method Details

#operationsObject



42
43
44
# File 'lib/skyfall/jetstream/message.rb', line 42

def operations
  []
end

#timeObject



46
47
48
# File 'lib/skyfall/jetstream/message.rb', line 46

def time
  @time ||= @json['time_us'] && Time.at(@json['time_us'] / 1_000_000.0)
end