Compare commits

...

5 Commits

Author SHA1 Message Date
Ryan Johnson c6976ac951
Merge pull request #2 from inhji/handle_syndicate_to_query
add handle_syndicate_to_query, fix handle_undelete signature
2019-04-19 08:09:48 -07:00
Inhji 7d93f0b277 add handle_syndicate_to_query, fix handle_undelete signature 2019-04-17 20:36:43 +02:00
Ryan Johnson 0c38da7de7 Stop filtering out mp-* props 2018-06-27 17:20:33 -07:00
Ryan Johnson 85c46f927f Small fixes
- Use plug formatter
- Add fallback match
- Remove tabs!
2018-04-11 22:50:37 -07:00
Ryan Johnson 293b660ee9
json_decoder -> json_encoder 2018-04-11 22:08:37 -07:00
4 changed files with 18 additions and 14 deletions

View File

@ -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]
]

View File

@ -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/

View File

@ -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()

View File

@ -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()],