mirror of
https://github.com/netfun2000/hipudding-teslamate.git
synced 2026-02-27 09:44:28 +08:00
* feat: endpoints by env * fix: typo * fix: useless env * fix: format * fix: distinct auth domain and url * format * fix: force issuer url if needed * feat: new streaming based on vin * fix refresh * revert * up * feat: no need for access token / refresh token if the TOKEN env var is present * feat: update login if token env var exists * feat: add ENV var to allow insecure wss * fix: remove TESLA_CN * fix(naming): TESLA_API_URL to TESLA_API_DOMAIN * feat: add an env var to allo invalid certs on WSS * doc: add API domains env vars description * fix: typo * feat: add env var to change log level * fix: APP_LOG_LEVEL * feat: add TOKEN documention and wording * fix: refacto insecure param * feat: naming and doc * fix: missing env var usage * fix: rebound variable issuer_url * fix: compilation warning on the issuer_url variable * fix: format code * fix: issuer_url assignments --------- Co-authored-by: Julien <julien@citio.digital>
35 lines
871 B
Elixir
35 lines
871 B
Elixir
defmodule TeslaMate.HTTP do
|
|
@pools %{
|
|
System.get_env("TESLA_API_HOST", "https://owner-api.teslamotors.com") => [size: 10],
|
|
"https://nominatim.openstreetmap.org" => [size: 3],
|
|
"https://api.github.com" => [size: 1],
|
|
:default => [size: 5]
|
|
}
|
|
|
|
@pool_timeout 10_000
|
|
|
|
def child_spec(_arg) do
|
|
Finch.child_spec(name: __MODULE__, pools: @pools)
|
|
end
|
|
|
|
def get(url, opts \\ []) do
|
|
{headers, opts} =
|
|
opts
|
|
|> Keyword.put_new(:pool_timeout, @pool_timeout)
|
|
|> Keyword.pop(:headers, [])
|
|
|
|
Finch.build(:get, url, headers, nil)
|
|
|> Finch.request(__MODULE__, opts)
|
|
end
|
|
|
|
def post(url, body \\ nil, opts \\ []) do
|
|
{headers, opts} =
|
|
opts
|
|
|> Keyword.put_new(:pool_timeout, @pool_timeout)
|
|
|> Keyword.pop(:headers, [])
|
|
|
|
Finch.build(:post, url, headers, body)
|
|
|> Finch.request(__MODULE__, opts)
|
|
end
|
|
end
|