add gauge API

This commit is contained in:
Pierre de Lacroix 2026-01-22 19:26:40 +01:00
parent 617c2ab725
commit d2ec7b12a9
Signed by: lateralus23
GPG key ID: 53E0CEC29C24EF39
8 changed files with 67 additions and 1 deletions

21
lib/camp_api/grist.ex Normal file
View file

@ -0,0 +1,21 @@
defmodule CampApi.Grist do
@moduledoc false
@api_url "https://grist.interhacker.space/o/camp"
def get_records(doc, table) do
url = "#{@api_url}/api/docs/#{doc}/tables/#{table}/records"
request(:get, url)
end
defp request(method, url) do
Req.request(
method: method,
url: url,
headers: [
{"authorization", "Bearer " <> Application.fetch_env!(:camp_api, :grist)[:api_key]}
]
)
end
end

View file

@ -0,0 +1,14 @@
defmodule CampApi.Grist.Gauge do
@moduledoc false
alias CampApi.Grist
@gauge_doc "wpwHRjzfdR9A"
@gauge_table "Infos"
def get() do
{:ok, %{body: %{"records" => records}}} = Grist.get_records(@gauge_doc, @gauge_table)
length(records)
end
end