Getting Started (Advanced)
Installation
- Add
:ex_hubic
to the dependencies.
defp deps() do
[{:ex_hubic, "~> 0.1.0"}]
end
Configuration
Note: The configuration assumes that the environment variables such as MY_APP_HUBIC_CLIENT_CLIENT_ID
are already created.
Configuring httpoison
is optional. The options added for httpoison
will be applied as opts to all HTTPoison requests.
config :my_app, MyApp.HubicClient,
hubic: [
client_id: System.get_env("MY_APP_HUBIC_CLIENT_CLIENT_ID"),
client_secret: System.get_env("MY_APP_HUBIC_CLIENT_CLIENT_SECRET"),
refresh_token: System.get_env("MY_APP_HUBIC_CLIENT_REFRESH_TOKEN"),
redirect_uri: System.get_env("MY_APP_HUBIC_CLIENT_REDIRECT_URI") || "http://localhost:4000/"
],
httpoison: [
connect_timeout: 30000, # 30 seconds
receive_timeout: (60000 * 30) # 30 minutes
]
- Add the client to your project.
defmodule MyApp.HubicClient do
@moduledoc :false
use ExHubic.Client, otp_app: :my_app, client: __MODULE__
end
- Add the client as a supervisor directly to the supervision tree of your application.
def start(_type, _args) do
import Supervisor.Spec, warn: false
spec1 = [supervisor(MyApp.Endpoint, [])]
spec2 = [supervisor(MyApp.HubicClient, [])]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(spec1 ++ spec2, opts)
end