Set default values for API base url and home
parent
48790cf79d
commit
d0a069b68c
|
@ -631,7 +631,7 @@ defmodule Hunter do
|
|||
* `base_url` - API base url, default: `https://mastodon.social`
|
||||
|
||||
"""
|
||||
defdelegate log_in(app, username, password, base_url \\ "https://mastodon.social"), to: Hunter.Client
|
||||
defdelegate log_in(app, username, password, base_url \\ nil), to: Hunter.Client
|
||||
|
||||
@doc """
|
||||
Returns Hunter version
|
||||
|
|
|
@ -56,7 +56,7 @@ defmodule Hunter.Application do
|
|||
@spec create_app(String.t, String.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t | no_return
|
||||
def create_app(name, redirect_uri \\ "urn:ietf:wg:oauth:2.0:oob", scopes \\ ["read"], website \\ nil, options \\ []) do
|
||||
save? = Keyword.get(options, :save?, false)
|
||||
base_url = Keyword.get(options, :api_base_url, "https://mastodon.social")
|
||||
base_url = Keyword.get(options, :api_base_url, Hunter.Config.api_base_url())
|
||||
|
||||
app = @hunter_api.create_app(name, redirect_uri, scopes, website, base_url)
|
||||
|
||||
|
@ -75,14 +75,14 @@ defmodule Hunter.Application do
|
|||
"""
|
||||
@spec load_credentials(String.t) :: Hunter.Application.t
|
||||
def load_credentials(name) do
|
||||
"~/.hunter/apps/#{name}.json"
|
||||
|> Path.expand()
|
||||
Hunter.Config.home()
|
||||
|> Path.join("apps/#{name}.json")
|
||||
|> File.read!()
|
||||
|> Poison.decode!(as: %Hunter.Application{})
|
||||
end
|
||||
|
||||
defp save_credentials(name, app) do
|
||||
home = Path.expand("~/.hunter/apps")
|
||||
home = Path.join(Hunter.Config.home(), "apps")
|
||||
|
||||
unless File.exists?(home), do: File.mkdir_p!(home)
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ defmodule Hunter.Client do
|
|||
|
||||
"""
|
||||
@spec log_in(Hunter.Application.t, String.t, String.t, String.t) :: Hunter.Client.t
|
||||
def log_in(app, username, password, base_url \\ "https://mastodon.social") do
|
||||
@hunter_api.log_in(app, username, password, base_url)
|
||||
def log_in(app, username, password, base_url \\ nil) do
|
||||
@hunter_api.log_in(app, username, password, base_url || Hunter.Config.api_base_url())
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,17 @@ defmodule Hunter.Config do
|
|||
@moduledoc false
|
||||
|
||||
@hunter_api Application.get_env(:hunter, :hunter_api, Hunter.Api.HTTPClient)
|
||||
@api_base_url "https://mastodon.social"
|
||||
|
||||
def hunter_api() do
|
||||
@hunter_api
|
||||
end
|
||||
|
||||
def api_base_url() do
|
||||
@api_base_url
|
||||
end
|
||||
|
||||
def home() do
|
||||
Path.expand(System.get_env("HUNTER_HOME") || "~/.hunter")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue