Skip to content

Commit 5d44c38

Browse files
authored
Merge pull request #5 from scripbox/task/accept-httpoison-options
Accept HTTPoison options from configuration
2 parents 762ee3f + 9846b08 commit 5d44c38

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

config/config.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use Mix.Config
1010

1111
# You can configure your application as:
1212
#
13-
# config :snowplow_elixir_tracker, key: :value
13+
# config :snowplow_tracker, key: :value
1414
#
1515
# and access this configuration in your application as:
1616
#
17-
# Application.get_env(:snowplow_elixir_tracker, :key)
17+
# Application.get_env(:snowplow_tracker, :key)
1818
#
1919
# You can also configure a 3rd-party app:
2020
#
@@ -28,3 +28,9 @@ use Mix.Config
2828
# here (which is why it is important to import them last).
2929
#
3030
# import_config "#{Mix.env}.exs"
31+
32+
config :snowplow_tracker,
33+
default_options: [
34+
timeout: 5000,
35+
recv_timeout: 2000
36+
]

lib/snowplow_tracker/emitter.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ defmodule SnowplowTracker.Emitter do
4040
emitter.request_type
4141
)
4242

43-
with {:ok, response} <- Request.get(url, [recv_timeout: 50000]),
43+
with {:ok, response} <- Request.get(url, [], default_options()),
4444
{:ok, body} <- Response.parse(response) do
4545
{:ok, body}
4646
else
4747
{:error, error} ->
4848
raise Errors.ApiError, Kernel.inspect(error)
4949
end
5050
end
51+
52+
defp default_options do
53+
Application.get_env(:snowplow_tracker, :default_options) || []
54+
end
5155
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule SnowplowTracker.MixProject do
44
def project do
55
[
66
app: :snowplow_tracker,
7-
version: "0.1.0",
7+
version: "0.1.1",
88
elixir: "~> 1.6",
99
start_permanent: Mix.env() == :prod,
1010
test_coverage: [tool: ExCoveralls],

test/snowplow_tracker/emitter_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule SnowplowTracker.EmitterTest do
77

88
defmacro with_request_mock(block) do
99
quote do
10-
with_mock Request, get: fn (url, opts) -> RequestMock.get(url, opts) end do
10+
with_mock Request, get: fn url, headers, opts -> RequestMock.get(url, headers, opts) end do
1111
unquote(block)
1212
end
1313
end

test/snowplow_tracker_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule SnowplowTrackerTest do
1313

1414
defmacro with_request_mock(block) do
1515
quote do
16-
with_mock Request, get: fn (url, opts) -> RequestMock.get(url, opts) end do
16+
with_mock Request, get: fn url, headers, opts -> RequestMock.get(url, headers, opts) end do
1717
unquote(block)
1818
end
1919
end

test/support/request_mock.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule SnowplowTracker.RequestMock do
22
require HTTPoison
33

4-
def get(_, _) do
4+
def get(_url, _headers, _options) do
55
send(self(), "request sent")
66
{:ok, %HTTPoison.Response{status_code: 200, body: "response"}}
77
end

0 commit comments

Comments
 (0)