Erlang SDK
Install
Add to your rebar.config dependencies:
Then: rebar3 compile
Quick Start
%% Start inets and ssl (required for httpc)
application:ensure_all_started(inets),
application:ensure_all_started(ssl),
%% Create client
Client = timenow:new("http://localhost:8090"),
%% Solar time for London
{ok, Solar} = timenow:get_solar(Client, 51.5074, -0.1278),
io:format("Solar time: ~s~n", [maps:get(<<"local_solar_time">>, Solar)]),
%% Social jetlag
{ok, Jetlag} = timenow:get_jetlag(Client, 39.47, 75.99),
io:format("Risk: ~s~n", [maps:get(<<"risk_level">>, Jetlag)]),
%% Health check
{ok, Health} = timenow:get_health(Client).
Functions
| Function | Signature | Returns | API endpoint |
|---|---|---|---|
new/0 | () | #client{} | — |
new/1 | (BaseUrl) | #client{} | — |
get_solar/3 | (Client, Lat, Lng) | {ok, Map} \| {error, Reason} | GET /solar |
get_jetlag/3 | (Client, Lat, Lng) | {ok, Map} \| {error, Reason} | GET /solar/jetlag |
get_prayer/3 | (Client, Lat, Lng) | {ok, Map} \| {error, Reason} | GET /solar/prayer |
get_almanac/3 | (Client, Lat, Lng) | {ok, Map} \| {error, Reason} | GET /solar/almanac |
get_reform/3 | (Client, Lat, Lng) | {ok, Map} \| {error, Reason} | GET /solar/reform |
get_health/1 | (Client) | {ok, Map} \| {error, Reason} | GET /health |
Types
All API functions return decoded JSON as Erlang maps.
Error Handling
Functions return {ok, Result} or {error, Reason} tuples:
case timenow:get_solar(Client, 999, 0) of
{ok, Result} ->
io:format("OK: ~p~n", [Result]);
{error, {http_error, Code, Body}} ->
io:format("HTTP ~p: ~s~n", [Code, Body]);
{error, Reason} ->
io:format("Error: ~p~n", [Reason])
end.
Dependencies: jsone for JSON parsing, built-in httpc for HTTP.