Skip to content

Commit b8d8d28

Browse files
Merge pull request #141 from paulanthonywilson/use-httpoison-options
Allow request options to be configured for HTTPoison/hackney Twilio requests
2 parents d8621ca + 690aa76 commit b8d8d28

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/ex_twilio/api.ex

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ defmodule ExTwilio.Api do
184184
|> auth_header({Config.account_sid(), Config.auth_token()})
185185
end
186186

187+
def process_request_options(options) do
188+
Keyword.merge(options, Config.request_options())
189+
end
190+
187191
@spec format_data(data) :: binary
188192
def format_data(data) when is_map(data) do
189193
data

lib/ex_twilio/config.ex

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ defmodule ExTwilio.Config do
3535
"""
3636
def protocol, do: Application.get_env(:ex_twilio, :protocol) || "https"
3737

38+
@doc """
39+
Options added to HTTPoison requests
40+
"""
41+
def request_options, do: from_env(:ex_twilio, :request_options, [])
42+
3843
@doc """
3944
Returns the version of the API that ExTwilio is going to talk to. Set it in
4045
`mix.exs`:

test/ex_twilio/api_test.exs

+11-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule ExTwilio.ApiTest do
8888
end
8989

9090
###
91-
# HTTPotion API
91+
# HTTPoison API
9292
###
9393

9494
test ".process_request_headers adds the correct headers" do
@@ -98,6 +98,16 @@ defmodule ExTwilio.ApiTest do
9898
assert Keyword.keys(headers) == [:Authorization, :"Content-Type"]
9999
end
100100

101+
test ".process_request_options adds configured options if configured" do
102+
assert Api.process_request_options([]) == []
103+
104+
Application.put_env(:ex_twilio, :request_options, hackney: [pool: :mavis])
105+
assert Api.process_request_options([]) == [hackney: [pool: :mavis]]
106+
assert Api.process_request_options(bob: :sue) == [bob: :sue, hackney: [pool: :mavis]]
107+
after
108+
Application.delete_env(:ex_twilio, :request_options)
109+
end
110+
101111
test ".format_data converts data to a query string when passed a list" do
102112
assert "FieldName=value" == Api.format_data(field_name: "value")
103113
end

0 commit comments

Comments
 (0)