Class: Octo::Message::Message

Inherits:
Object
  • Object
show all
Includes:
MessageParser
Defined in:
lib/octocore/message_parser.rb

Overview

To handle message abstraction

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageParser

#parse

Constructor Details

#initialize(msg) ⇒ Message

Converting Message hash in Octo compatible form

Parameters:

  • Message (Hash)

    Hash



86
87
88
# File 'lib/octocore/message_parser.rb', line 86

def initialize(msg)
  @message = msg
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



82
83
84
# File 'lib/octocore/message_parser.rb', line 82

def message
  @message
end

Instance Method Details

#eidString

To get enterprise id

Returns:

Raises:

  • (StandardError)


98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/octocore/message_parser.rb', line 98

def eid
  msg = to_json
  enterprise = msg['enterprise']
  raise StandardError, 'Parse Error' if enterprise.nil?

  eid = if enterprise.has_key?'custom_id'
          enterprise['custom_id']
        elsif enterprise.has_key?'customId'
          enterprise['customId']
        end

  eid
end

#to_hHash

To get hash message

Returns:

  • (Hash)

    Message Hash



92
93
94
# File 'lib/octocore/message_parser.rb', line 92

def to_h
  parse(@message)
end