Skip to content

Commit

Permalink
fold spec
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Feb 5, 2024
1 parent 5c7f4e6 commit c6d07a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# copy id key from from result of account.sh

export id=01707154556408094497
export key=01707154556408001098
export id=01707161812754226949
export key=01707161812754213150

curl -H "Auth: $key" -X PUT "http://localhost:5010/subscription/$id" -d @priv/subscription.json
curl -H "Auth: $key" -X GET "http://localhost:5010/subscription"
Expand Down
53 changes: 25 additions & 28 deletions lib/up_rest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,13 @@ defmodule UP.HTTP do
plug :match
plug :dispatch
plug Plug.Parsers, parsers: [:json], json_decoder: Jason
get "/" do meta(conn) end
get "/account" do get3(conn,auth(conn),"account",[],"lst") end
get "/account/:id" do get3(conn,auth(conn),"account",id,"get") end
put "/account/" do put3(conn,auth(conn),"account",[],"put") end
get "/site" do get3(conn,auth(conn),"site",[],"lst") end
get "/site/:id" do get3(conn,auth(conn),"site",id,"get") end
put "/site/:id" do put3(conn,auth(conn),"site",id,"put") end
get "/incident" do get3(conn,auth(conn),"incident",[],"lst") end
get "/incident/:id" do get3(conn,auth(conn),"incident",id,"get") end
put "/incident/:id" do put3(conn,auth(conn),"incident",id,"put") end
get "/metric" do get3(conn,auth(conn),"metric",[],"lst") end
get "/metric/:id" do get3(conn,auth(conn),"metric",id,"get") end
put "/metric/:id" do put3(conn,auth(conn),"metric",id,"put") end
get "/subscription" do get3(conn,auth(conn),"subscription",[],"lst") end
get "/subscription/:id" do get3(conn,auth(conn),"subscription",id,"get") end
put "/subscription/:id" do put3(conn,auth(conn),"subscription",id,"put") end
get "/maintenance" do get3(conn,auth(conn),"maintenance",[],"lst") end
put "/maintenance/:id" do put3(conn,auth(conn),"maintenance",id,"put") end
get "/maintenance/:id" do get3(conn,auth(conn),"maintenance",id,"get") end
get "/component" do get3(conn,auth(conn),"component",[],"lst") end
get "/component/:id" do get3(conn,auth(conn),"component",id,"get") end
put "/component/:id" do put3(conn,auth(conn),"component",id,"put") end
get "/" do meta(conn) end
get "/account" do get3(conn,auth(conn),"account",[],"lst") end
get "/account/:id" do get3(conn,auth(conn),"account",id,"get") end
put "/account/" do put3(conn,auth(conn),"account",[],"put") end
get "/:type" do get3(conn,auth(conn),type,[],"lst") end
get "/:type/:id" do get3(conn,auth(conn),type,id,"get") end
put "/:type/:id" do put3(conn,auth(conn),type,id,"put") end
match _ do send_resp(conn, 404, "Please refer to https://up.erp.uno manual " <>
"for information about endpoints addresses.") end

Expand All @@ -46,11 +31,11 @@ defmodule UP.HTTP do
conn |> Plug.Conn.put_resp_content_type("application/json") |>
send_resp(200, encode([%{ "resourceType" => "UP", "methods" => [
"GET /account", "GET /accounts/:id", "PUT /account",
"GET /subscription", "GET /subscription/:id", "PUT /subscription",
"GET /incident", "GET /incidents/:id", "PUT /incidents",
"GET /maintenance", "GET /maintenance/:id", "PUT /maintenance",
"GET /metric", "GET /metric/:id", "PUT /metric",
"GET /component", "GET /component//:id", "PUT /component"
"GET /subscription", "GET /subscription/:id", "PUT /subscription/:id",
"GET /incident", "GET /incidents/:id", "PUT /incidents/:id",
"GET /maintenance", "GET /maintenance/:id", "PUT /maintenance/:id",
"GET /metric", "GET /metric/:id", "PUT /metric/:id",
"GET /component", "GET /component/:id", "PUT /component/:id"
], "version" => "1.0", "uri" => "https://up.erp.uno" }])) end

# PUT PATHWAY
Expand Down Expand Up @@ -114,7 +99,13 @@ defmodule UP.HTTP do
encode([%{ "error" => "Authorization",
"text" => "Security admin key doesn't match." }])) end end

# GET LIST PATHWAY
def put3(conn, _, type, _, _) do
send_resp(conn, 400,
encode([%{ "error" => "Method",
"text" => "Resource :#{type} not found." }]))
end

# GET PATHWAY

def get3(conn, auth, type, _, spec) when type == "account" do
secAdmin = :application.get_env :up, :security_admin, "1707126861546831000"
Expand Down Expand Up @@ -147,6 +138,12 @@ defmodule UP.HTTP do
encode([%{ "error" => "Authorization",
"text" => "Account key doesn't match." }])) end end

def get3(conn, _, type, _, _) do
send_resp(conn, 400,
encode([%{ "error" => "Method",
"text" => "Resource #{type} not found." }]))
end

# DELETE PATH WAY

def delete3(conn,_,type,id,spec) do
Expand Down

0 comments on commit c6d07a7

Please sign in to comment.