Class: OpenWire::InboundMessage

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

Overview

Parsed open-wire/1 inbound envelope.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ InboundMessage

Returns a new instance of InboundMessage.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/open_wire/envelope.rb', line 9

def initialize(payload)
  @raw = payload.is_a?(Hash) ? payload : {}
  @id = @raw["id"]
  @channel = @raw["channel"]
  @installation_id = @raw["installation_id"]
  @created_at = @raw["created_at"]
  thread = @raw["thread"] || {}
  @thread_id = thread["id"]
  from = @raw["from"] || {}
  @from_id = from["id"]
  @from_kind = from["kind"]
  to = @raw["to"] || {}
  @to_id = to["id"]
  @to_kind = to["kind"]
  @body = @raw["body"] || {}
  @text = (@body["text"] || "").to_s
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def body
  @body
end

#channelObject (readonly)

Returns the value of attribute channel.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def channel
  @channel
end

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def created_at
  @created_at
end

#from_idObject (readonly)

Returns the value of attribute from_id.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def from_id
  @from_id
end

#from_kindObject (readonly)

Returns the value of attribute from_kind.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def from_kind
  @from_kind
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def id
  @id
end

#installation_idObject (readonly)

Returns the value of attribute installation_id.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def installation_id
  @installation_id
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def raw
  @raw
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def text
  @text
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def thread_id
  @thread_id
end

#to_idObject (readonly)

Returns the value of attribute to_id.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def to_id
  @to_id
end

#to_kindObject (readonly)

Returns the value of attribute to_kind.



6
7
8
# File 'lib/open_wire/envelope.rb', line 6

def to_kind
  @to_kind
end

Instance Method Details

#dm?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/open_wire/envelope.rb', line 27

def dm?
  to_kind.to_s == "dm"
end

#protocolObject



31
32
33
# File 'lib/open_wire/envelope.rb', line 31

def protocol
  @raw["protocol"]
end

#to_hObject



39
40
41
# File 'lib/open_wire/envelope.rb', line 39

def to_h
  @raw
end

#typeObject



35
36
37
# File 'lib/open_wire/envelope.rb', line 35

def type
  @raw["type"]
end