aboutsummaryrefslogtreecommitdiff
path: root/src/rest.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2016-08-09 10:53:58 +0200
committerChristophe Romain <christophe.romain@process-one.net>2016-11-15 14:35:26 +0100
commit8df68266f2e0bf4cb0d1d51ec8a8372affadc8e5 (patch)
tree8a1b71099c957f01418b86f53a0f1f94e0fa6457 /src/rest.erl
parentapply string optimizations (diff)
Add missing verbs for RESTfull operation
Diffstat (limited to 'src/rest.erl')
-rw-r--r--src/rest.erl33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/rest.erl b/src/rest.erl
index e5c6fd963..091002fa5 100644
--- a/src/rest.erl
+++ b/src/rest.erl
@@ -28,7 +28,7 @@
-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").
@@ -71,18 +71,17 @@ delete(Server, Path) ->
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},
@@ -147,6 +146,18 @@ request(Server, Method, Path, Params, Mime, Data) ->
%%% 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;