Class: Interapp::ReceiveMessageService

Inherits:
Object
  • Object
show all
Defined in:
app/services/interapp/receive_message_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload:, peer_identifier:, signature:) ⇒ ReceiveMessageService

Returns a new instance of ReceiveMessageService.



5
6
7
8
9
# File 'app/services/interapp/receive_message_service.rb', line 5

def initialize(payload:, peer_identifier:, signature:)
  find_peer(peer_identifier)
  @message = Message.new(payload: payload, peer: @peer, signature: signature)
  @data = JSON.load(@message.payload)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'app/services/interapp/receive_message_service.rb', line 3

def data
  @data
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'app/services/interapp/receive_message_service.rb', line 3

def message
  @message
end

#peerObject (readonly)

Returns the value of attribute peer.



3
4
5
# File 'app/services/interapp/receive_message_service.rb', line 3

def peer
  @peer
end

#return_valueObject (readonly)

Returns the value of attribute return_value.



3
4
5
# File 'app/services/interapp/receive_message_service.rb', line 3

def return_value
  @return_value
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
# File 'app/services/interapp/receive_message_service.rb', line 11

def perform
  if @message.verify
    @return_value = Interapp.configuration.handler.call(data, message.peer.identifier)
  else
    raise Interapp::SignatureInvalidError
  end
rescue OpenSSL::ASN1::ASN1Error
  raise Interapp::SignatureInvalidError
end