./ct_report/coverage/mod_event_pusher_http_defaults.COVER.html

1 %%%----------------------------------------------------------------------
2 %%% File : mod_event_pusher_http_defaults.erl
3 %%% Author : Baibossynv Valery <baibossynov.valery@gmail.com>
4 %%% Purpose : Message passing via http
5 %%% Created : 23 Feb 2075 by Piotr Nosek
6 %%%----------------------------------------------------------------------
7
8 -module(mod_event_pusher_http_defaults).
9 -author("baibossynov.valery@gmail.com").
10
11 -behaviour(mod_event_pusher_http).
12
13 %% API
14 -export([should_make_req/6, prepare_body/7, prepare_headers/7]).
15
16 %% @doc This function determines whether to send http notification or not.
17 %% Can be reconfigured by creating a custom module implementing should_make_req/3
18 %% and adding it to mod_event_pusher_http settings as {callback_module}
19 %% Default behaviour is to send all chat messages with non-empty body.
20 should_make_req(_Acc, out, _Packet, _From, _To, _Opts) ->
21 38 false;
22 should_make_req(Acc, in, Packet, From, To, _Opts) ->
23 10 Type = exml_query:attr(Packet, <<"type">>, <<>>),
24 10 Body = exml_query:path(Packet, [{element, <<"body">>}, cdata], <<>>),
25 10 should_make_req_type(Acc, Type, Body, From, To).
26
27 should_make_req_type(_Acc, <<"chat">>, Body, _From, _To) when Body /= <<"">> ->
28 9 true;
29 should_make_req_type(_Acc, _, _, _, _) ->
30 1 false.
31
32 prepare_body(_Acc, _Dir, Host, Message, Sender, Receiver, _Opts) ->
33 9 cow_qs:qs([{<<"author">>, Sender},
34 {<<"server">>, Host}, {<<"receiver">>, Receiver}, {<<"message">>, Message}]).
35
36 prepare_headers(_Acc, _Dir, _Host, _Sender, _Receiver, _Message, _Opts) ->
37 19 [{<<"content-type">>, <<"application/x-www-form-urlencoded">>}].
Line Hits Source