mirror of https://github.com/inhji/plug_micropub
Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Ryan Johnson | c6976ac951 | |
Inhji | 7d93f0b277 | |
Ryan Johnson | 0c38da7de7 | |
Ryan Johnson | 85c46f927f | |
Ryan Johnson | 293b660ee9 |
|
@ -1,4 +1,5 @@
|
|||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
||||
import_deps: [:plug]
|
||||
]
|
||||
|
|
|
@ -17,7 +17,7 @@ plug Plug.Parsers,
|
|||
|
||||
plug PlugMicropub,
|
||||
handler: MyApp.MicropubHandler,
|
||||
json_decoder: Poison
|
||||
json_encoder: Poison
|
||||
```
|
||||
|
||||
### Forwarding
|
||||
|
@ -30,8 +30,8 @@ If you want `PlugMicropub` to serve only a particular route, configure your rout
|
|||
forward "/micropub",
|
||||
to: PlugMicropub,
|
||||
init_opts: [
|
||||
handler: MyApp.MicropubHandler,
|
||||
json_decoder: Poison
|
||||
handler: MyApp.MicropubHandler,
|
||||
json_encoder: Poison
|
||||
]
|
||||
```
|
||||
|
||||
|
@ -41,7 +41,7 @@ forward "/micropub",
|
|||
forward "/micropub",
|
||||
PlugMicropub,
|
||||
handler: MyApp.MicropubHandler,
|
||||
json_decoder: Poison
|
||||
json_encoder: Poison
|
||||
```
|
||||
|
||||
[1]: https://micropub.rocks/
|
||||
|
|
|
@ -7,8 +7,8 @@ defmodule PlugMicropub do
|
|||
"""
|
||||
use Plug.Router
|
||||
|
||||
plug(:match)
|
||||
plug(:dispatch)
|
||||
plug :match
|
||||
plug :dispatch
|
||||
|
||||
# Plug Callbacks
|
||||
|
||||
|
@ -64,6 +64,10 @@ defmodule PlugMicropub do
|
|||
end
|
||||
end
|
||||
|
||||
match _ do
|
||||
send_error(conn, {:error, :invalid_request})
|
||||
end
|
||||
|
||||
# Internal Functions
|
||||
|
||||
defp send_content(conn, content) do
|
||||
|
@ -295,10 +299,7 @@ defmodule PlugMicropub do
|
|||
defp parse_create_body("application/json", params) do
|
||||
with {:ok, ["h-" <> type]} <- Map.fetch(params, "type"),
|
||||
{:ok, properties} when is_map(properties) <- Map.fetch(params, "properties") do
|
||||
properties =
|
||||
properties
|
||||
|> Enum.reject(&match?({"mp-" <> _, _}, &1))
|
||||
|> Map.new()
|
||||
properties = Map.new(properties)
|
||||
|
||||
{:ok, type, properties}
|
||||
else
|
||||
|
@ -310,7 +311,6 @@ defmodule PlugMicropub do
|
|||
with {type, params} when is_binary(type) <- Map.pop(params, "h") do
|
||||
properties =
|
||||
params
|
||||
|> Enum.reject(&match?({"mp-" <> _, _}, &1))
|
||||
|> Enum.map(fn {k, v} -> {k, List.wrap(v)} end)
|
||||
|> Map.new()
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ defmodule PlugMicropub.HandlerBehaviour do
|
|||
@callback handle_undelete(url :: String.t(), access_token) ::
|
||||
:ok
|
||||
| {:ok, url :: String.t()}
|
||||
| {:error, handler_error}
|
||||
| {:error, handler_error, error_description :: String.t()}
|
||||
| handler_error
|
||||
|
||||
@callback handle_config_query(access_token) ::
|
||||
{:ok, map}
|
||||
|
@ -41,6 +40,10 @@ defmodule PlugMicropub.HandlerBehaviour do
|
|||
{:ok, map}
|
||||
| handler_error
|
||||
|
||||
@callback handle_syndicate_to_query(access_token) ::
|
||||
{:ok, map}
|
||||
| handler_error
|
||||
|
||||
@callback handle_source_query(
|
||||
url :: String.t(),
|
||||
properties :: [String.t()],
|
||||
|
|
Loading…
Reference in New Issue