ExOvh v0.2.0 ExOvh.Client behaviour
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"
],
httpoison: [
connect_timeout: 20000,
receive_timeout: 100000
]
Example using the ExOvh
client
%ExOvh.Query{ method: :get, uri: "/me", params: %{}} |> ExOvh.request!()
%ExOvh.Query{ method: :get, uri: "/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")
],
httpoison: [ # optional
connect_timeout: 20000,
receive_timeout: 100000
]
Example using the MyApp.MyClient
client
%ExOvh.Query{ method: :get, uri: "/me", params: %{}} |> MyApp.MyClient.request!()
%ExOvh.Query{ method: :get, uri: "/cloud/project", params: %{}} |> MyApp.MyClient.request!()
Summary
Callbacks
prepare_request(query, httpoison_opts)
prepare_request(query :: ExOvh.Query.t, httpoison_opts :: Keyword.t) :: ExOvh.Query.t | no_return
request(query, httpoison_opts)
request(query :: ExOvh.Query.t | ExOvh.HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, ExOvh.Response.t} | {:error, ExOvh.Response.t}
request!(query, httpoison_opts)
request!(query :: ExOvh.Query.t | ExOvh.HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, ExOvh.Response.t} | no_return