Skip to content

Ada SDK

Install

git clone https://github.com/koke1997/timenow.git
cd timenow/sdk/ada
gprbuild -P timenow.gpr

Produces a static library in lib/.

Quick Start

with Timenow; use Timenow;
with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   C : Client := Create ("http://localhost:8090");
begin
   -- Solar time for London (returns raw JSON)
   Put_Line (Get_Solar (C, 51.5074, -0.1278));

   -- Social jetlag (returns typed record)
   declare
      J : Jetlag_Result := Get_Jetlag (C, 39.47, 75.99);
   begin
      Put_Line (J.Risk_Level (1 .. J.Risk_Level_Last));
   end;

   -- Health check
   Put_Line (Get_Health (C));
end Main;

Methods

Method Signature Returns API endpoint
Get_Solar (Self : Client; Lat, Lng : Float) String (JSON) GET /solar
Get_Jetlag (Self : Client; Lat, Lng : Float) Jetlag_Result GET /solar/jetlag
Get_Prayer (Self : Client; Lat, Lng : Float) String (JSON) GET /solar/prayer
Get_Almanac (Self : Client; Lat, Lng : Float) String (JSON) GET /solar/almanac
Get_Reform (Self : Client; Lat, Lng : Float) String (JSON) GET /solar/reform
Get_Health (Self : Client) String (JSON) GET /health
Get_Raw (Self : Client; Path : String) String (JSON) Any GET

Types

type Client is tagged record
   Base_URL : String (1 .. 256);
   URL_Last : Natural := 0;
end record;

type Jetlag_Result is record
   Risk_Level          : String (1 .. 32);
   Risk_Level_Last     : Natural := 0;
   Civil_Solar_Offset  : Float := 0.0;
   Weekly_Sleep_Loss   : Float := 0.0;
   Annual_Sleep_Loss_H : Float := 0.0;
end record;

Error Handling

The SDK shells out to curl and raises standard Ada exceptions on I/O failure. On HTTP errors, methods return an empty JSON object "{}".

begin
   Put_Line (Get_Solar (C, 999.0, 0.0));
exception
   when others =>
      Put_Line ("Request failed");
end;