-behaviour(ejabberd_config).
-export([start/1, stop/1, get/2, get/3, post/4, delete/2,
- request/6, with_retry/4, opt_type/1]).
+ put/4, patch/4, request/6, with_retry/4, opt_type/1]).
-include("logger.hrl").
request(Server, delete, Path, [], "application/json", <<>>).
post(Server, Path, Params, Content) ->
- Data = case catch jiffy:encode(Content) of
- {'EXIT', Reason} ->
- ?ERROR_MSG("HTTP content encodage failed:~n"
- "** Content = ~p~n"
- "** Err = ~p",
- [Content, Reason]),
- <<>>;
- Encoded ->
- Encoded
- end,
+ Data = encode_json(Content),
request(Server, post, Path, Params, "application/json", Data).
+put(Server, Path, Params, Content) ->
+ Data = encode_json(Content),
+ request(Server, put, Path, Params, "application/json", Data).
+
+patch(Server, Path, Params, Content) ->
+ Data = encode_json(Content),
+ request(Server, patch, Path, Params, "application/json", Data).
+
request(Server, Method, Path, Params, Mime, Data) ->
URI = url(Server, Path, Params),
Opts = [{connect_timeout, ?CONNECT_TIMEOUT},
%%% HTTP helpers
%%%----------------------------------------------------------------------
+encode_json(Content) ->
+ case catch jiffy:encode(Content) of
+ {'EXIT', Reason} ->
+ ?ERROR_MSG("HTTP content encodage failed:~n"
+ "** Content = ~p~n"
+ "** Err = ~p",
+ [Content, Reason]),
+ <<>>;
+ Encoded ->
+ Encoded
+ end.
+
base_url(Server, Path) ->
Tail = case iolist_to_binary(Path) of
<<$/, Ok/binary>> -> Ok;