-
Notifications
You must be signed in to change notification settings - Fork 209
/
hackney.ex
44 lines (33 loc) · 934 Bytes
/
hackney.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule Swoosh.ApiClient.Hackney do
@moduledoc """
Built-in hackney-based ApiClient.
"""
require Logger
@behaviour Swoosh.ApiClient
@user_agent {"User-Agent", "swoosh/#{Swoosh.version()}"}
@impl true
def init do
unless Code.ensure_loaded?(:hackney) do
Logger.error("""
Could not find hackney dependency.
Please add :hackney to your dependencies:
{:hackney, "~> 1.9"}
Or set your own Swoosh.ApiClient:
config :swoosh, :api_client, MyAPIClient
""")
raise "missing hackney dependency"
end
_ = Application.ensure_all_started(:hackney)
:ok
end
@impl true
def post(url, headers, body, %Swoosh.Email{} = email) do
hackney_options = email.private[:hackney_options] || email.private[:client_options] || []
:hackney.post(
url,
[@user_agent | headers],
body,
[:with_body | hackney_options]
)
end
end