Class: Flashover

Inherits:
Object
  • Object
show all
Defined in:
lib/flashover.rb

Defined Under Namespace

Classes: Crypto, MaryPoppins

Constant Summary collapse

VERSION =
"0.0.6"
MESSAGE_TYPES =
[
  :sms,
  :phone,
  :email,
  :page_view,
  :generic,
  :backup,
  :notification
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, passphrase, salt) ⇒ Flashover

Returns a new instance of Flashover.



21
22
23
24
# File 'lib/flashover.rb', line 21

def initialize(redis, passphrase, salt)
  @redis = redis
  @crypto = Crypto.new(passphrase, salt)
end

Instance Attribute Details

#environment=(value) ⇒ Object

Sets the attribute environment

Parameters:

  • value

    the value to set the attribute environment to.



19
20
21
# File 'lib/flashover.rb', line 19

def environment=(value)
  @environment = value
end

#redisObject

Returns the value of attribute redis.



19
20
21
# File 'lib/flashover.rb', line 19

def redis
  @redis
end

Instance Method Details

#event(type, payload) ⇒ Object

‘type’ dictates the message pipeline payload is shoved down can be: -> :sms -> :phone_call -> :email -> :page_view -> :generic



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flashover.rb', line 33

def event(type, payload)
  begin
    @redis.publish(convert_symbol_to_channel(type), build_payload(payload))
    true
  rescue Errno::ETIMEDOUT => ex
    Bugsnag.notify(ex)
    logger "Flashover TIMEOUT @ #{Time.now.ctime}"
    false
  rescue => ex
    Bugsnag.notify(ex)
    logger "BANG @ Flashover#event => #{ex.class} -> '#{ex.message}'"
    false
  end
end

#listen(listening_channel = nil, &blk) ⇒ Object

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/flashover.rb', line 48

def listen(listening_channel = nil, &blk)
  raise MaryPoppins.new("block must have two args") unless blk.arity == 2

  @redis.subscribe(redis_message_types) do |on|
    on.message do |channel, message|
      channel = convert_channel_to_symbol(channel)
      if listening_channel
        yield(channel, parse_message(message)) if listening_channel == channel
      else
        yield(channel, parse_message(message))
      end
    end
  end
end