Class: Skyfall::Jetstream::AccountMessage

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

Overview

Jetstream message sent when the status of an account changes. This can be:

  • an account being created, sending its initial state (should be active)

  • an account being deactivated or suspended

  • an account being restored back to an active state from deactivation/suspension

  • an account being deleted (the status returning :deleted)

Instance Attribute Summary

Attributes inherited from Message

#did, #json, #time_us, #type

Instance Method Summary collapse

Methods inherited from Message

new, #operation, #operations, #time, #unknown?

Constructor Details

#initialize(json) ⇒ AccountMessage

Returns a new instance of AccountMessage.

Parameters:

  • json (Hash)

    message JSON decoded from the websocket message

Raises:

  • (DecodeError)

    if the message doesn’t include required data



24
25
26
27
# File 'lib/skyfall/jetstream/account_message.rb', line 24

def initialize(json)
  raise DecodeError.new("Missing event details (account)") if json['account'].nil? || json['account']['active'].nil?
  super
end

Instance Method Details

#active?Boolean

Returns true if the account is active, false if it’s deactivated/suspended etc.

Returns:

  • (Boolean)

    true if the account is active, false if it’s deactivated/suspended etc.



30
31
32
# File 'lib/skyfall/jetstream/account_message.rb', line 30

def active?
  @json['account']['active']
end

#statusSymbol?

Returns for inactive accounts, specifies the exact state; nil for active accounts.

Returns:

  • (Symbol, nil)

    for inactive accounts, specifies the exact state; nil for active accounts



35
36
37
# File 'lib/skyfall/jetstream/account_message.rb', line 35

def status
  @json['account']['status']&.to_sym
end