Skip to content

Commit 971cd76

Browse files
committed
wires up geolix call
1 parent cd07bfb commit 971cd76

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/geolix_plug.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ defmodule Geolix.Plug do
33
Geolix Plug
44
"""
55

6+
import Plug.Conn
7+
68
@behaviour Plug
79

810
def init(opts), do: opts
911

10-
def call(conn, _opts), do: conn
12+
def call(conn, opts) do
13+
lookup = Geolix.lookup(conn.remote_ip, opts)
14+
15+
put_private(conn, :geolix, lookup)
16+
end
1117
end

test/geolix_plug_test.exs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Geolix.PlugTest do
55
defmodule Router do
66
use Plug.Router
77

8-
plug Geolix.Plug
8+
plug Geolix.Plug, where: :city
99

1010
plug :match
1111
plug :dispatch
@@ -16,6 +16,9 @@ defmodule Geolix.PlugTest do
1616
@opts Router.init([])
1717

1818
test "returns 200" do
19-
assert 200 == conn(:get, "/") |> Router.call(@opts) |> Map.fetch!(:status)
19+
conn = conn(:get, "/") |> Router.call(@opts)
20+
21+
assert 200 == conn.status
22+
refute conn.private[:geolix]
2023
end
2124
end

0 commit comments

Comments
 (0)