ExOvh v0.4.0 ExOvh.Client behaviour View Source
A behaviour for setting up an OVH client.
Example setting up the ExOvh
Client
Defining a client:
defmodule ExOvh do
@moduledoc :false
use ExOvh.Client, otp_app: :ex_ovh, client: __MODULE__
end
Configuring a client:
config :ex_ovh,
ovh: [
application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
endpoint: "ovh-eu",
api_version: "1.0"
],
# default hackney options to each request (optional)
hackney: [
connect_timeout: 20000,
recv_timeout: 100000
]
Example using the ExOvh
client
%HTTPipe.Request{ method: :get, url: "/me", params: %{}} |> ExOvh.request!()
%HTTPipe.Request{ method: :get, url: "/cloud/project", params: %{}} |> ExOvh.request!()
Example (2): Setting up an additional MyApp.MyClient
client.
Defining the MyApp.MyClient
defmodule MyApp.MyClient do
@moduledoc :false
use ExOvh.Client, otp_app: :my_app
end
Configuring the MyApp.MyClient
config :my_app, MyApp.MyClient,
ovh: [
application_key: System.get_env("MY_APP_MY_CLIENT_APPLICATION_KEY"),
application_secret: System.get_env("MY_APP_MY_CLIENT_APPLICATION_SECRET"),
consumer_key: System.get_env("MY_APP_MY_CLIENT_CONSUMER_KEY")
],
# default hackney options to each request (optional)
hackney: [
connect_timeout: 20000,
recv_timeout: 100000
]
Example using the MyApp.MyClient
client
%HTTPipe.Request{ method: :get, url: "/me", params: %{}} |> MyApp.MyClient.request!()
%ExOvh.Query{ method: :get, url: "/cloud/project", params: %{}} |> MyApp.MyClient.request!()
Link to this section Summary
Link to this section Callbacks
Link to this callback
prepare_request(arg0)
View Source
prepare_request(HTTPipe.Conn.t() | HTTPipe.Request.t()) :: HTTPipe.Conn.t()
Link to this callback
request(conn)
View Source
request(conn :: HTTPipe.Conn.t()) :: {:ok, HTTPipe.Conn.t()} | {:error, HTTPipe.Conn.t()}
Link to this callback
request!(conn)
View Source
request!(conn :: HTTPipe.Conn.t()) :: HTTPipe.Conn.t() | no_return()
Link to this callback
start_link(sup_opts)
View Source
start_link(sup_opts :: list()) :: {:ok, pid()} | {:error, atom()}