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