Class: Profit::MessageHandler

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/profit/message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, conn) ⇒ MessageHandler

Returns a new instance of MessageHandler.



10
11
12
# File 'lib/profit/message_handler.rb', line 10

def initialize(json, conn)
  @json, @conn = json, conn
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/profit/message_handler.rb', line 8

def text
  @text
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/profit/message_handler.rb', line 14

def run
  return succeed("Starting") if @json.empty?
  message_hash = JSON.parse(@json)
  key = message_hash.delete("metric_type")
  response = @conn.rpush key, message_hash.to_json
  if response == "OK"
    succeed response
  else
    fail response
  end
end