mirror of
https://github.com/mitchell/shortnr.git
synced 2025-12-19 14:07:22 +00:00
Impl. config based dep. injection for ets;
- Check for extant url ids - Various minor refactors
This commit is contained in:
parent
fe413d2a5e
commit
50de5607d6
12 changed files with 90 additions and 58 deletions
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Shortnr.Transport.Http do
|
||||
defmodule Shortnr.Transport.HTTP do
|
||||
import Plug.Conn
|
||||
|
||||
@type ok_error :: {:ok, term(), Plug.Conn.t()} | error()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Shortnr.Transport.Json do
|
||||
import Plug.Conn
|
||||
alias Shortnr.Transport.Http
|
||||
alias Shortnr.Transport.HTTP
|
||||
|
||||
@spec decode_request(Plug.Conn.t(), module()) :: Http.ok_error()
|
||||
@spec decode_request(Plug.Conn.t(), module()) :: HTTP.ok_error()
|
||||
def decode_request(conn, struct_module) do
|
||||
{:ok, body, conn} = read_body(conn)
|
||||
{:ok, params} = Jason.decode(body)
|
||||
|
|
@ -15,7 +15,7 @@ defmodule Shortnr.Transport.Json do
|
|||
{:ok, struct(struct_module, params_list), conn}
|
||||
end
|
||||
|
||||
@spec encode_response(Http.ok_error()) :: Http.ok_error()
|
||||
@spec encode_response(HTTP.ok_error()) :: HTTP.ok_error()
|
||||
def encode_response({:error, {status, response}, conn}) do
|
||||
{:ok, json_body} = Jason.encode(%{data: response})
|
||||
{:error, {status, json_body}, conn}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
defmodule Shortnr.Transport.Text do
|
||||
import Plug.Conn
|
||||
alias Shortnr.Transport.Http
|
||||
alias Shortnr.Transport.HTTP
|
||||
alias Shortnr.URL
|
||||
|
||||
@spec decode_request(Plug.Conn.t()) :: Http.ok_error()
|
||||
@spec decode_request(Plug.Conn.t()) :: HTTP.ok_error()
|
||||
def decode_request(conn) do
|
||||
{:ok, body, conn} = read_body(conn)
|
||||
{:ok, body, conn}
|
||||
end
|
||||
|
||||
@spec encode_response(Http.ok_error()) :: Http.ok_error()
|
||||
@spec encode_response(HTTP.ok_error()) :: HTTP.ok_error()
|
||||
def encode_response(ok_error = {:error, _, _}), do: ok_error
|
||||
|
||||
def encode_response({:ok, [], conn}) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue