12 |
7u83 |
1 |
-module(hmac_api_client).
|
|
|
2 |
|
|
|
3 |
-export([
|
|
|
4 |
fire/0
|
|
|
5 |
]).
|
|
|
6 |
|
|
|
7 |
-include("hmac_api.hrl").
|
|
|
8 |
-author("Hypernumbers Ltd <gordon@hypernumbers.com>").
|
|
|
9 |
|
|
|
10 |
fire() ->
|
|
|
11 |
URL = "http://127.0.0.1:8080/some/page/yeah/",
|
|
|
12 |
%% Dates SHOULD conform to Section 3.3 of RFC2616
|
|
|
13 |
%% the examples from the RFC are:
|
|
|
14 |
%% Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
|
|
|
15 |
%% Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
|
|
|
16 |
%% Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
|
|
17 |
|
|
|
18 |
%% Dates can be conveniently generated using dh_date.erl
|
|
|
19 |
%% https://github.com/daleharvey/dh_date
|
|
|
20 |
%% which is largely compatible with
|
|
|
21 |
%% http://uk.php.net/date
|
|
|
22 |
|
|
|
23 |
%% You MIGHT find it convenient to insist on times in UTC only
|
|
|
24 |
%% as it reduces the errors caused by summer time and other
|
|
|
25 |
%% conversion issues
|
|
|
26 |
Method = post,
|
|
|
27 |
Headers = [{"content-type", "application/json"},
|
|
|
28 |
{"date", "Sun, 10 Jul 2011 05:07:19"}],
|
|
|
29 |
ContentType = "application/json",
|
|
|
30 |
Body = "blah",
|
|
|
31 |
HTTPAuthHeader = hmac_api_lib:sign(?privatekey, Method, URL,
|
|
|
32 |
Headers, ContentType),
|
|
|
33 |
httpc:request(Method, {URL, [HTTPAuthHeader | Headers],
|
|
|
34 |
ContentType, Body}, [], []).
|