Skip to content

Commit

Permalink
V2 endpoints (#278)
Browse files Browse the repository at this point in the history
* Check in, routes do not comply with http [skip ci]

* Update routes to GET `@` endpoints

* Bump to version 0.4.0
  • Loading branch information
Jesus Bracho authored Mar 28, 2018
1 parent ca77897 commit fbfc4b1
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plenario_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule PlenarioWeb do

def api_controller do
quote do
use Phoenix.Controller, namespece: PlenarioWeb.Api
use Phoenix.Controller, namespace: PlenarioWeb.Api
import Plug.Conn
import Canary.Plugs
end
Expand Down Expand Up @@ -110,6 +110,7 @@ defmodule PlenarioWeb do
def api_view do
quote do
use Phoenix.View,
root: "lib/plenario_web/templates/api",
namespace: PlenarioWeb.Api
import Phoenix.Controller, only: [view_module: 1]
import PlenarioWeb.Router.Helpers
Expand Down
15 changes: 15 additions & 0 deletions lib/plenario_web/controllers/api/aot_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.AotController do
use PlenarioWeb, :api_controller

def get(conn, _params) do
render(conn, "get.json", %{})
end

def head(conn, _params) do
render(conn, "head.json", %{})
end

def describe(conn, _params) do
render(conn, "describe.json", %{})
end
end
15 changes: 15 additions & 0 deletions lib/plenario_web/controllers/api/detail_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.DetailController do
use PlenarioWeb, :api_controller

def get(conn, _params) do
render(conn, "get.json", %{})
end

def head(conn, _params) do
render(conn, "head.json", %{})
end

def describe(conn, _params) do
render(conn, "describe.json", %{})
end
end
15 changes: 15 additions & 0 deletions lib/plenario_web/controllers/api/list_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.ListController do
use PlenarioWeb, :api_controller

def get(conn, _params) do
render(conn, "get.json", %{})
end

def head(conn, _params) do
render(conn, "head.json", %{})
end

def describe(conn, _params) do
render(conn, "describe.json", %{})
end
end
14 changes: 13 additions & 1 deletion lib/plenario_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,20 @@ defmodule PlenarioWeb.Router do

##
# api paths
scope "/api", PlenarioWeb.Api do
scope "/api/v2", PlenarioWeb.Api do
pipe_through [:api]

get "/data-sets", ListController, :get
get "/data-sets/@head", ListController, :head
get "/data-sets/@describe", ListController, :describe

get "/detail", DetailController, :get
get "/detail/@head", DetailController, :head
get "/detail/@describe", DetailController, :describe

get "/aot", AotController, :get
get "/aot/@head", AotController, :head
get "/aot/@describe", AotController, :describe
end
end

Expand Down
15 changes: 15 additions & 0 deletions lib/plenario_web/views/api/aot_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.AotView do
use PlenarioWeb, :api_view

def render("get.json", _params) do
%{}
end

def render("head.json", _params) do
%{}
end

def render("describe.json", _params) do
%{}
end
end
15 changes: 15 additions & 0 deletions lib/plenario_web/views/api/detail_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.DetailView do
use PlenarioWeb, :api_view

def render("get.json", _params) do
%{}
end

def render("head.json", _params) do
%{}
end

def render("describe.json", _params) do
%{}
end
end
15 changes: 15 additions & 0 deletions lib/plenario_web/views/api/list_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule PlenarioWeb.Api.ListView do
use PlenarioWeb, :api_view

def render("get.json", _params) do
%{}
end

def render("head.json", _params) do
%{}
end

def render("describe.json", _params) do
%{}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Plenario.Mixfile do
def project do
[
app: :plenario,
version: "0.3.0",
version: "0.4.0",
elixir: "~> 1.6",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
Expand Down
18 changes: 18 additions & 0 deletions test/plenario_web/controllers/api/aot_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule PlenarioWeb.Api.AotControllerTest do
use PlenarioWeb.Testing.ConnCase

test "GET /api/v2/aot", %{conn: conn} do
conn = get(conn, "/api/v2/aot")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/aot/@head", %{conn: conn} do
conn = get(conn, "/api/v2/aot/@head")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/aot/@describe", %{conn: conn} do
conn = get(conn, "/api/v2/aot/@describe")
assert json_response(conn, 200) == %{}
end
end
18 changes: 18 additions & 0 deletions test/plenario_web/controllers/api/detail_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule PlenarioWeb.Api.DetailControllerTest do
use PlenarioWeb.Testing.ConnCase

test "GET /api/v2/detail", %{conn: conn} do
conn = get(conn, "/api/v2/detail")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/detail/@head", %{conn: conn} do
conn = get(conn, "/api/v2/detail/@head")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/detail/@describe", %{conn: conn} do
conn = get(conn, "/api/v2/detail/@describe")
assert json_response(conn, 200) == %{}
end
end
18 changes: 18 additions & 0 deletions test/plenario_web/controllers/api/list_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule PlenarioWeb.Api.ListControllerTest do
use PlenarioWeb.Testing.ConnCase

test "GET /api/v2/data-sets", %{conn: conn} do
conn = get(conn, "/api/v2/data-sets")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/data-sets/@head", %{conn: conn} do
conn = get(conn, "/api/v2/data-sets")
assert json_response(conn, 200) == %{}
end

test "GET /api/v2/data-sets/@describe", %{conn: conn} do
conn = get(conn, "/api/v2/data-sets")
assert json_response(conn, 200) == %{}
end
end

0 comments on commit fbfc4b1

Please sign in to comment.