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
-type model_callback() :: m_get | m_post | m_delete.
-type opt_message() :: mqtt_packet_map:mqtt_packet() | undefined.
-type path() :: [path_element()].
-type verb() :: get | post | delete.
Functions
-spec call(model_name(), verb(), path(), opt_message(), z:context()) -> {ok, term()} | {error, term()}.
-spec callback(model_name(), verb(), path(), mqtt_packet_map:mqtt_packet(), z:context()) -> {ok, term()} | {error, term()}.
Find the model module in the module index. The model must be either an atom or a binary.
-spec payload_msg(Payload :: term()) -> opt_message().
-spec publish(model_name(), verb(), path(), opt_message(), z:context()) -> {ok, term()} | {error, term()}.
-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.