File: hmac_api_client.erl

package info (click to toggle)
rabbitmq-server 3.3.5-1.1
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 12,004 kB
  • sloc: erlang: 78,203; python: 3,187; xml: 2,843; makefile: 903; sh: 831; java: 660; perl: 64; ruby: 63
file content (34 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-module(hmac_api_client).

-export([
         fire/0
        ]).

-include("hmac_api.hrl").
-author("Hypernumbers Ltd <gordon@hypernumbers.com>").

fire() ->
    URL = "http://127.0.0.1:8080/some/page/yeah/",
    %% Dates SHOULD conform to Section 3.3 of RFC2616
    %% the examples from the RFC are:
    %% Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
    %% Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
    %% Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

    %% Dates can be conveniently generated using dh_date.erl
    %% https://github.com/daleharvey/dh_date
    %% which is largely compatible with
    %% http://uk.php.net/date

    %% You MIGHT find it convenient to insist on times in UTC only
    %% as it reduces the errors caused by summer time and other
    %% conversion issues
    Method = post,
    Headers = [{"content-type", "application/json"},
               {"date", "Sun, 10 Jul 2011 05:07:19"}],
    ContentType = "application/json",
    Body = "blah",
    HTTPAuthHeader = hmac_api_lib:sign(?privatekey, Method, URL,
                                       Headers, ContentType),
    httpc:request(Method, {URL, [HTTPAuthHeader | Headers],
                           ContentType, Body}, [], []).