Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/knock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ defmodule Knock do
```elixir
config :my_app, Knock,
adapter: Tesla.Adapter.Finch,
json_client: JSX
json_client: JSX,
middleware_callback: &MyApp.Tesla.middleware_callback/1
```

You can read more about the availble adapters in the [Tesla documentation](https://hexdocs.pm/tesla/readme.html#adapters)
Expand Down
2 changes: 2 additions & 0 deletions lib/knock/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ defmodule Knock.Api do
] ++ maybe_idempotency_key_header(Map.new(opts))}
]

middleware = (config.middleware_callback || & &1).(middleware)

Tesla.client(middleware, config.adapter)
end

Expand Down
8 changes: 5 additions & 3 deletions lib/knock/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Knock.Client do
defstruct host: "https://api.knock.app",
api_key: nil,
adapter: Tesla.Adapter.Hackney,
json_client: Jason
json_client: Jason,
middleware_callback: nil

@typedoc """
Describes a Knock client
Expand All @@ -23,7 +24,8 @@ defmodule Knock.Client do
host: String.t(),
api_key: String.t(),
adapter: atom(),
json_client: atom()
json_client: atom(),
middleware_callback: ([atom()] -> [atom()])
}

@doc """
Expand All @@ -36,7 +38,7 @@ defmodule Knock.Client do
raise Knock.ApiKeyMissingError
end

opts = Keyword.take(opts, [:host, :api_key, :adapter, :json_client])
opts = Keyword.take(opts, [:host, :api_key, :adapter, :json_client, :middleware_callback])
struct!(__MODULE__, opts)
end
end