Skip to content

Commit 270ff6d

Browse files
authored
Merge pull request #18 from primait/ISSUE-17
Add HTTP timeout option
2 parents 26c3622 + 3dcd5ba commit 270ff6d

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

config/config.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use Mix.Config
44

55
config :sparkpost, api_endpoint: "https://api.sparkpost.com/api/v1/"
66
config :sparkpost, api_key: "YOUR API KEY HERE"
7+
config :sparkpost, http_timeout: 5000
78

89
# This configuration is loaded before any dependency and is restricted
910
# to this project. If another project depends on this project, this

lib/endpoint.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ defmodule SparkPost.Endpoint do
4141
]
4242
end
4343

44+
reqopts = [timeout: Application.get_env(:sparkpost, :http_timeout, 5000)] ++ reqopts
45+
4446
%{status_code: status_code, body: json} = HTTPotion.request(method, url, reqopts)
4547

4648
body = decode_response_body(json)

mix.lock

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
%{"bunt": {:hex, :bunt, "0.1.4"},
2-
"certifi": {:hex, :certifi, "0.3.0"},
3-
"credo": {:hex, :credo, "0.3.0-dev"},
4-
"earmark": {:hex, :earmark, "0.2.1"},
5-
"ex_doc": {:hex, :ex_doc, "0.11.3"},
6-
"excoveralls": {:hex, :excoveralls, "0.4.5"},
7-
"exjsx": {:hex, :exjsx, "3.2.0"},
8-
"hackney": {:hex, :hackney, "1.4.8"},
9-
"httpotion": {:hex, :httpotion, "2.1.0"},
1+
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
2+
"certifi": {:hex, :certifi, "0.3.0", "389d4b126a47895fe96d65fcf8681f4d09eca1153dc2243ed6babad0aac1e763", [:rebar3], []},
3+
"credo": {:hex, :credo, "0.4.3", "29fe87aa2ef3c19bf8dd909594b9b79d9e2ed2857a153c00eb3f697f41cb6782", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
4+
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
5+
"ex_doc": {:hex, :ex_doc, "0.11.3", "bb16cb3f4135d880ce25279dc19a9d70802bc4f4942f0c3de9e4862517ae3ace", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
6+
"excoveralls": {:hex, :excoveralls, "0.4.5", "1508e1c7f373f82805975c633e2468a83898b2b902acf79e7359486d71186ea3", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}, {:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}]},
7+
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
8+
"hackney": {:hex, :hackney, "1.4.8", "c8c6977ed55cc5095e3929f6d94a6f732dd2e31ae42a7b9236d5574ec3f5be13", [:rebar3], [{:ssl_verify_hostname, "1.0.5", [hex: :ssl_verify_hostname, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:idna, "1.0.3", [hex: :idna, optional: false]}, {:certifi, "0.3.0", [hex: :certifi, optional: false]}]},
9+
"httpotion": {:hex, :httpotion, "2.1.0", "3fe84fbd13d4560c2514da656d022b1191a079178ee4992d245fc3c33c01ee18", [:mix], []},
1010
"ibrowse": {:git, "https://github.com/cmullaparthi/ibrowse.git", "ea3305d21f37eced4fac290f64b068e56df7de80", [tag: "v4.1.2"]},
11-
"idna": {:hex, :idna, "1.0.3"},
12-
"jsx": {:hex, :jsx, "2.6.2"},
13-
"meck": {:hex, :meck, "0.8.4"},
14-
"mimerl": {:hex, :mimerl, "1.0.2"},
15-
"mock": {:hex, :mock, "0.1.1"},
16-
"poison": {:hex, :poison, "1.5.2"},
17-
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"}}
11+
"idna": {:hex, :idna, "1.0.3", "d456a8761cad91c97e9788c27002eb3b773adaf5c893275fc35ba4e3434bbd9b", [:rebar3], []},
12+
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
13+
"meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [:rebar, :make], []},
14+
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
15+
"mock": {:hex, :mock, "0.1.1", "e21469ca27ba32aa7b18b61699db26f7a778171b21c0e5deb6f1218a53278574", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, optional: false]}]},
16+
"poison": {:hex, :poison, "1.5.2", "560bdfb7449e3ddd23a096929fb9fc2122f709bcc758b2d5d5a5c7d0ea848910", [:mix], []},
17+
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []}}

test/endpoint_test.exs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ defmodule SparkPost.EndpointTest do
8686
respfn.(method, url, opts)
8787
end
8888
] do
89-
Enum.each([:get, :post, :put, :delete], fn method ->
89+
Enum.each([:get, :post, :put, :delete], fn method ->
9090
Endpoint.request(method, "transmissions", []) end)
9191
end
9292
end
@@ -102,4 +102,17 @@ defmodule SparkPost.EndpointTest do
102102
Endpoint.request(:put, "transmissions", [body: %{}])
103103
end
104104
end
105+
106+
test "Endpoint.request includes request timeout" do
107+
respfn = MockServer.mk_resp
108+
with_mock HTTPotion, [request: fn (method, url, opts) ->
109+
assert Keyword.has_key?(opts, :timeout)
110+
respfn.(method, url, opts)
111+
end
112+
] do
113+
Endpoint.request(:post, "transmissions", [])
114+
Endpoint.request(:put, "transmissions", [])
115+
Endpoint.request(:get, "transmissions", [])
116+
end
117+
end
105118
end

0 commit comments

Comments
 (0)