Class: RelayGrid::Resources::Messages
- Inherits:
-
Object
- Object
- RelayGrid::Resources::Messages
- Defined in:
- lib/relaygrid/resources/messages.rb
Overview
The receive side: reading a recipient's inbox and marking messages off.
user_id is always your identifier for the user (the API's
external_user_id), never a RelayGrid internal id.
Instance Method Summary collapse
-
#get(id) ⇒ Hash
The message with its deliveries.
-
#initialize(client) ⇒ Messages
constructor
A new instance of Messages.
-
#mark_as_delivered(id) ⇒ Boolean
Confirm a push message reached the device.
-
#mark_as_seen(id, notification_channel_id: nil) ⇒ Hash
Mark a message read.
-
#new_for(user_id:) ⇒ Array<Hash>
Unseen messages for a recipient, newest first.
-
#render(id) ⇒ Hash
Rendered subject and body with the message's attributes substituted in.
Constructor Details
#initialize(client) ⇒ Messages
Returns a new instance of Messages.
10 11 12 |
# File 'lib/relaygrid/resources/messages.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#get(id) ⇒ Hash
Returns the message with its deliveries.
31 32 33 |
# File 'lib/relaygrid/resources/messages.rb', line 31 def get(id) @client.get("/api/v1/messages/#{id}")["message"] end |
#mark_as_delivered(id) ⇒ Boolean
Confirm a push message reached the device. Normally the browser/device does this over the websocket; this is the HTTP equivalent.
51 52 53 |
# File 'lib/relaygrid/resources/messages.rb', line 51 def mark_as_delivered(id) @client.patch("/api/v1/messages/#{id}/mark_as_delivered")["success"] == true end |
#mark_as_seen(id, notification_channel_id: nil) ⇒ Hash
Mark a message read. With a channel id, the matching delivery is marked opened (which is what drives open-rate analytics); without one, only the message's own seen flag is set.
40 41 42 43 44 45 |
# File 'lib/relaygrid/resources/messages.rb', line 40 def mark_as_seen(id, notification_channel_id: nil) body = {} body[:notification_channel_id] = notification_channel_id if notification_channel_id @client.patch("/api/v1/messages/#{id}/mark_as_seen", body: body)["message"] end |
#new_for(user_id:) ⇒ Array<Hash>
Unseen messages for a recipient, newest first. The polling counterpart
to RelayGrid.websocket, and what an inbox view renders.
20 21 22 23 24 25 26 27 |
# File 'lib/relaygrid/resources/messages.rb', line 20 def new_for(user_id:) body = @client.get( "/api/v1/messages/new_messages_for", params: { external_user_id: user_id.to_s } ) Array(body["messages"]) end |
#render(id) ⇒ Hash
Rendered subject and body with the message's attributes substituted in.
58 59 60 |
# File 'lib/relaygrid/resources/messages.rb', line 58 def render(id) @client.get("/api/v1/messages/#{id}/render_message") end |