PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/hmac_api/hmac_api_client.erl

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