z_model (zotonic_core v1.0.0-rc.17)

Call models, direct or via MQTT

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.

Types

model_callback/0

-type model_callback() :: m_get | m_post | m_delete.

model_name/0

-type model_name() :: binary() | atom().

opt_message/0

-type opt_message() :: mqtt_packet_map:mqtt_packet() | undefined.

path/0

-type path() :: [path_element()].

path_element/0

-type path_element() :: atom() | binary() | term().

verb/0

-type verb() :: get | post | delete.

Functions

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

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

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

-spec callback(model_name(), verb(), path(), mqtt_packet_map:mqtt_packet(), z:context()) ->
                  {ok, term()} | {error, term()}.

get_arg(Prop, Map, Context)

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

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.

payload_msg(Payload)

-spec payload_msg(Payload :: term()) -> opt_message().

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

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

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.