Module: Jackal::Utils::Payload

Included in:
Carnivore::Http::PointBuilder::Endpoint, Callback, Jackal::Utils
Defined in:
lib/jackal/utils/payload.rb

Overview

Payload helper utilities

Instance Method Summary collapse

Instance Method Details

#new_payload(name, payload, *args) ⇒ Smash

Generate a new payload

Parameters:

  • name (String)
  • payload (Hash)
  • args (Object)

    extra arguments

Returns:

  • (Smash)


15
16
17
18
19
20
21
# File 'lib/jackal/utils/payload.rb', line 15

def new_payload(name, payload, *args)
  Smash.new(
    :name => name,
    :id => Carnivore.uuid,
    :data => payload
  )
end

#unpack(message) ⇒ Smash

Extract payload from message

Parameters:

  • message (Carnivore::Message)

Returns:

  • (Smash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jackal/utils/payload.rb', line 27

def unpack(message)
  if(message[:content])
    result = message[:content].to_smash
  else
    msg = message[:message].to_smash
    result = msg.fetch(:payload, msg)
  end
  if(respond_to?(:pre_formatters) && (pre_formatters && !pre_formatters.empty?))
    pre_formatters.each do |formatter|
      begin
        formatter.format(result)
      rescue => e
        error "Formatter error encountered (<#{formatter}>): #{e.class} - #{e}"
      end
    end
  end
  result
end