hunter/lib/hunter/client.ex

55 lines
1.3 KiB
Elixir
Raw Normal View History

2017-04-08 01:30:17 -04:00
defmodule Hunter.Client do
@moduledoc """
Defines a `Hunter` client
"""
2019-03-19 13:18:34 -04:00
alias Hunter.Config
2017-04-08 01:30:17 -04:00
@type t :: %__MODULE__{
2017-10-26 15:16:42 -04:00
base_url: String.t(),
bearer_token: String.t()
}
2017-04-08 01:30:17 -04:00
@derive [Poison.Encoder]
defstruct [:base_url, :bearer_token]
@doc """
Initializes a client
## Options
* `base_url` - URL of the instance you want to connect to
* `bearer_token` - [String] OAuth access token for your authenticated user
"""
2017-10-26 15:16:42 -04:00
@spec new(Keyword.t()) :: Hunter.Client.t()
2017-04-08 01:30:17 -04:00
def new(options \\ []) do
struct(Hunter.Client, options)
end
@doc """
User agent of the client
"""
2017-10-26 15:16:42 -04:00
@spec user_agent() :: String.t()
def user_agent do
2017-10-26 15:16:42 -04:00
"Hunter.Elixir/#{Hunter.version()}"
2017-04-08 01:30:17 -04:00
end
@doc """
Retrieve access token
## Parameters
* `app` - application details, see: `Hunter.Application.create_app/5` for more details.
* `username` - your account's email
* `password` - your password
* `base_url` - API base url, default: `https://mastodon.social`
"""
2017-10-26 15:16:42 -04:00
@spec log_in(Hunter.Application.t(), String.t(), String.t(), String.t()) :: Hunter.Client.t()
2019-03-19 14:16:09 -04:00
def log_in(app, username, password, base_url \\ "https://mastodon.social") do
2019-03-19 13:18:34 -04:00
base_url = base_url || Config.api_base_url()
Config.hunter_api().log_in(app, username, password, base_url)
end
2017-04-08 01:30:17 -04:00
end