Class: Interapp::SendMessageService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, peer_identifier:) ⇒ SendMessageService

Returns a new instance of SendMessageService.



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

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

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#payloadObject (readonly)

Returns the value of attribute payload.



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

def payload
  @payload
end

#peerObject (readonly)

Returns the value of attribute peer.



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

def peer
  @peer
end

Instance Method Details

#performObject



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

def perform
  response = RestClient.post(peer.endpoint, message.payload, {
    content_type: 'application/json',
    "X-Interapp-Identifier" => Interapp.configuration.identifier,
    "X-Interapp-Signature" => message.signature
  })
  JSON.parse(response) if response
end