add gauge API
This commit is contained in:
parent
617c2ab725
commit
e1a6b72c44
8 changed files with 63 additions and 1 deletions
15
lib/camp_api/grist.ex
Normal file
15
lib/camp_api/grist.ex
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
15
lib/camp_api/grist/gauge.ex
Normal file
15
lib/camp_api/grist/gauge.ex
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue