Module: SelfSDK::Messages

Defined in:
lib/messages/base.rb,
lib/messages/chat.rb,
lib/messages/fact.rb,
lib/messages/message.rb,
lib/messages/chat_join.rb,
lib/messages/attestation.rb,
lib/messages/chat_invite.rb,
lib/messages/chat_remove.rb,
lib/messages/chat_message.rb,
lib/messages/fact_request.rb,
lib/messages/fact_response.rb,
lib/messages/chat_message_read.rb,
lib/messages/document_sign_resp.rb,
lib/messages/chat_message_delivered.rb

Defined Under Namespace

Classes: Attestation, Base, Chat, ChatInvite, ChatJoin, ChatMessage, ChatMessageDelivered, ChatMessageRead, ChatRemove, DocumentSignResponse, Fact, FactRequest, FactResponse

Class Method Summary collapse

Class Method Details

.parse(input, messaging, original = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/messages/message.rb', line 17

def self.parse(input, messaging, original=nil)
  envelope = nil
  body = if input.is_a? String
            input
         else
            envelope = input
            issuer = input.sender.split(":")
            messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
         end

  jwt = JSON.parse(body, symbolize_names: true)
  payload = JSON.parse(messaging.jwt.decode(jwt[:payload]), symbolize_names: true)

  case payload[:typ]
  when SelfSDK::Messages::FactRequest::MSG_TYPE
    m = FactRequest.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::FactResponse::MSG_TYPE
    m = FactResponse.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessage::MSG_TYPE
    m = ChatMessage.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessageDelivered::MSG_TYPE
    m = ChatMessageDelivered.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessageRead::MSG_TYPE
    m = ChatMessageRead.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatInvite::MSG_TYPE
    m = ChatInvite.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatRemove::MSG_TYPE
    m = ChatRemove.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatJoin::MSG_TYPE
    m = ChatJoin.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::DocumentSignResponse::MSG_TYPE
    m = DocumentSignResponse.new(messaging)
    m.parse(body, envelope)
  else
    raise StandardError.new("Invalid message type #{payload[:typ]}.")
  end
  return m
end