z_model (zotonic_core v1.0.0-rc.10)

Call models, direct or via MQTT

Link to this section Summary

Functions

Find the model module in the module index. The model must be either an atom or a binary.
Called by the compiled templates for a model lookup. Any map in the path is taken as the model payload, and passed in the msg part of the model m_get call.

Link to this section Types

Link to this type

model_callback/0

-type model_callback() :: m_get | m_post | m_delete.
Link to this type

model_name/0

-type model_name() :: binary() | atom().
Link to this type

opt_message/0

-type opt_message() :: mqtt_packet_map:mqtt_packet() | undefined.
-type path() :: [path_element()].
Link to this type

path_element/0

-type path_element() :: atom() | binary() | term().
-type verb() :: get | post | delete.

Link to this section Functions

Link to this function

call(Model, Verb, Path, Msg, Context)

-spec call(model_name(), verb(), path(), opt_message(), z:context()) -> {ok, term()} | {error, term()}.
Link to this function

callback(Model, Verb, Path, Msg, Context)

-spec callback(model_name(), verb(), path(), mqtt_packet_map:mqtt_message(), z:context()) ->
            {ok, term()} | {error, term()}.
Link to this function

get_arg(Prop, Map, Context)

-spec get_arg(atom(), map() | undefined, z:context()) -> term() | undefined.
Link to this function

get_module(Name, Context)

-spec get_module(atom() | binary(), z:context()) -> {ok, module()} | {error, term()}.
Find the model module in the module index. The model must be either an atom or a binary.
Link to this function

payload_msg(Payload)

-spec payload_msg(Payload :: term()) -> opt_message().
Link to this function

publish(Model, Verb, Path, Msg, Context)

-spec publish(model_name(), verb(), path(), opt_message(), z:context()) ->
           {ok, term()} | {error, term()}.
Link to this function

template_get(Model, Path, Payload, Context)

-spec template_get(model_name(), path(), term(), z:context()) ->
                {ok, {term(), path()}} | {error, term()}.
Called by the compiled templates for a model lookup. Any map in the path is taken as the model payload, and passed in the msg part of the model m_get call.