rename to PlugIndie
This commit is contained in:
parent
c257845f06
commit
257bed5180
13 changed files with 27 additions and 27 deletions
10
README.md
10
README.md
|
@ -1,4 +1,4 @@
|
||||||
# PlugMicropub
|
# PlugIndie
|
||||||
|
|
||||||
A small library for helping build a Plug-based Micropub server.
|
A small library for helping build a Plug-based Micropub server.
|
||||||
|
|
||||||
|
@ -15,20 +15,20 @@ plug Plug.Parsers,
|
||||||
pass: ["*/*"],
|
pass: ["*/*"],
|
||||||
json_decoder: Poison
|
json_decoder: Poison
|
||||||
|
|
||||||
plug PlugMicropub,
|
plug PlugIndie,
|
||||||
handler: MyApp.MicropubHandler,
|
handler: MyApp.MicropubHandler,
|
||||||
json_encoder: Poison
|
json_encoder: Poison
|
||||||
```
|
```
|
||||||
|
|
||||||
### Forwarding
|
### Forwarding
|
||||||
|
|
||||||
If you want `PlugMicropub` to serve only a particular route, configure your router like:
|
If you want `PlugIndie` to serve only a particular route, configure your router like:
|
||||||
|
|
||||||
#### Plug.Router
|
#### Plug.Router
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
forward "/micropub",
|
forward "/micropub",
|
||||||
to: PlugMicropub,
|
to: PlugIndie,
|
||||||
init_opts: [
|
init_opts: [
|
||||||
handler: MyApp.MicropubHandler,
|
handler: MyApp.MicropubHandler,
|
||||||
json_encoder: Poison
|
json_encoder: Poison
|
||||||
|
@ -39,7 +39,7 @@ forward "/micropub",
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
forward "/micropub",
|
forward "/micropub",
|
||||||
PlugMicropub,
|
PlugIndie,
|
||||||
handler: MyApp.MicropubHandler,
|
handler: MyApp.MicropubHandler,
|
||||||
json_encoder: Poison
|
json_encoder: Poison
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule PlugMicropub.Handler do
|
defmodule PlugIndie.Handler do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
alias PlugMicropub.{Response, Parser, Properties}
|
alias PlugIndie.{Response, Parser, Properties}
|
||||||
|
|
||||||
def handle_action(:create, access_token, conn) do
|
def handle_action(:create, access_token, conn) do
|
||||||
content_type = conn |> get_req_header("content-type") |> List.first()
|
content_type = conn |> get_req_header("content-type") |> List.first()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub.Parser do
|
defmodule PlugIndie.Parser do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|
||||||
def get_action(conn) do
|
def get_action(conn) do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub do
|
defmodule PlugIndie do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
A Plug for building a Micropub server.
|
A Plug for building a Micropub server.
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ defmodule PlugMicropub do
|
||||||
"""
|
"""
|
||||||
require Logger
|
require Logger
|
||||||
use Plug.Router
|
use Plug.Router
|
||||||
alias PlugMicropub.{Parser, Handler, Response}
|
alias PlugIndie.{Parser, Handler, Response}
|
||||||
|
|
||||||
plug :match
|
plug :match
|
||||||
plug :dispatch
|
plug :dispatch
|
||||||
|
@ -44,7 +44,7 @@ defmodule PlugMicropub do
|
||||||
Keyword.get(opts, :scopes) || @default_scopes
|
Keyword.get(opts, :scopes) || @default_scopes
|
||||||
|
|
||||||
token_handler =
|
token_handler =
|
||||||
Keyword.get(opts, :token_handler) || PlugMicropub.Token
|
Keyword.get(opts, :token_handler) || PlugIndie.Token
|
||||||
|
|
||||||
[
|
[
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule PlugMicropub.HandlerBehaviour do
|
defmodule PlugIndie.HandlerBehaviour do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Behaviour defining the interface for a PlugMicropub Handler
|
Behaviour defining the interface for a PlugIndie Handler
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@type access_token :: String.t()
|
@type access_token :: String.t()
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
defmodule PlugMicropub.Post do
|
defmodule PlugIndie.Post do
|
||||||
defstruct [:type, :title, :content]
|
defstruct [:type, :title, :content]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub.Properties do
|
defmodule PlugIndie.Properties do
|
||||||
def parse(properties) do
|
def parse(properties) do
|
||||||
{:ok, type} = get_post_type(properties)
|
{:ok, type} = get_post_type(properties)
|
||||||
content = get_content(properties)
|
content = get_content(properties)
|
||||||
|
@ -7,7 +7,7 @@ defmodule PlugMicropub.Properties do
|
||||||
case type do
|
case type do
|
||||||
:note ->
|
:note ->
|
||||||
{:ok,
|
{:ok,
|
||||||
%PlugMicropub.Post{
|
%PlugIndie.Post{
|
||||||
type: type,
|
type: type,
|
||||||
title: title,
|
title: title,
|
||||||
content: content
|
content: content
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub.Response do
|
defmodule PlugIndie.Response do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|
||||||
def send_content(conn, content) do
|
def send_content(conn, content) do
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
defmodule TestHandler do
|
defmodule TestHandler do
|
||||||
@behaviour PlugMicropub.HandlerBehaviour
|
@behaviour PlugIndie.HandlerBehaviour
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_create(_type, properties, _access_token) do
|
def handle_create(_type, %PlugIndie.Post{} = properties, _access_token) do
|
||||||
case properties.type do
|
case properties.type do
|
||||||
:note ->
|
:note ->
|
||||||
{:ok, :created, "/notes/4711"}
|
{:ok, :created, "/notes/4711"}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub.Token do
|
defmodule PlugIndie.Token do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def verify(
|
def verify(
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,4 +1,4 @@
|
||||||
defmodule PlugMicropub.MixProject do
|
defmodule PlugIndie.MixProject do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule ParserTest do
|
defmodule ParserTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest PlugMicropub.Parser
|
doctest PlugIndie.Parser
|
||||||
import PlugMicropub.Parser, only: [parse_create_body: 2]
|
import PlugIndie.Parser, only: [parse_create_body: 2]
|
||||||
|
|
||||||
test "parse_create_body with content-type json" do
|
test "parse_create_body with content-type json" do
|
||||||
params = %{
|
params = %{
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule PlugMicropubTest do
|
defmodule PlugIndieTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
use Plug.Test
|
use Plug.Test
|
||||||
|
|
||||||
doctest PlugMicropub
|
doctest PlugIndie
|
||||||
|
|
||||||
@opts PlugMicropub.init(
|
@opts PlugIndie.init(
|
||||||
hostname: "example.com",
|
hostname: "example.com",
|
||||||
handler: TestHandler,
|
handler: TestHandler,
|
||||||
token_endpoint: "http://example.com/token",
|
token_endpoint: "http://example.com/token",
|
||||||
|
@ -21,7 +21,7 @@ defmodule PlugMicropubTest do
|
||||||
})
|
})
|
||||||
|
|
||||||
# Invoke the plug
|
# Invoke the plug
|
||||||
conn = PlugMicropub.call(conn, @opts)
|
conn = PlugIndie.call(conn, @opts)
|
||||||
|
|
||||||
# Assert the response and status
|
# Assert the response and status
|
||||||
assert conn.state == :sent
|
assert conn.state == :sent
|
||||||
|
|
Loading…
Reference in a new issue