Current section

Files

Jump to
pixie lib pixie messages publish.ex
Raw

lib/pixie/messages/publish.ex

defmodule Pixie.Message.Publish do
defstruct channel: nil, data: nil, client_id: nil, id: nil, ext: nil
import Pixie.Utils.Message
@moduledoc """
Convert an incoming message publication into a struct.
Request
MUST include: * channel
* data
MAY include: * clientId
* id
* ext
This struct contains the following keys:
- `:channel` the channel the client wishes to publish the message to.
- `:data` an arbitrary value passed from the client via JSON as the
contents of the message. Usually a `List` or `Map`.
- `:client_id` the client ID generated by the server during handshake.
According to the Bayeux protocol this field is optional, however Pixie
will not accept publications from non-connected clients.
- `:ext` an arbitrary map of data the client sent for use in extensions
(usually authentication information, etc). Optional.
- `:id` a message ID generated by the client. Optional.
"""
@doc """
Convert the incoming message into a `Pixie.Message.Publish` by copying
only those fields we care about.
"""
def init %{}=message do
%Pixie.Message.Publish{}
|> get(message, :channel)
|> get(message, :data)
|> get(message, :client_id)
|> get(message, :id, Pixie.Utils.RandomId.generate)
|> get(message, :ext)
end
end