rename to PlugIndie

This commit is contained in:
Inhji 2024-11-29 10:42:27 +01:00
parent c257845f06
commit 257bed5180
13 changed files with 27 additions and 27 deletions

View file

@ -1,4 +1,4 @@
# PlugMicropub
# PlugIndie
A small library for helping build a Plug-based Micropub server.
@ -15,20 +15,20 @@ plug Plug.Parsers,
pass: ["*/*"],
json_decoder: Poison
plug PlugMicropub,
plug PlugIndie,
handler: MyApp.MicropubHandler,
json_encoder: Poison
```
### 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
```elixir
forward "/micropub",
to: PlugMicropub,
to: PlugIndie,
init_opts: [
handler: MyApp.MicropubHandler,
json_encoder: Poison
@ -39,7 +39,7 @@ forward "/micropub",
```elixir
forward "/micropub",
PlugMicropub,
PlugIndie,
handler: MyApp.MicropubHandler,
json_encoder: Poison
```

View file

@ -1,6 +1,6 @@
defmodule PlugMicropub.Handler do
defmodule PlugIndie.Handler do
import Plug.Conn
alias PlugMicropub.{Response, Parser, Properties}
alias PlugIndie.{Response, Parser, Properties}
def handle_action(:create, access_token, conn) do
content_type = conn |> get_req_header("content-type") |> List.first()

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub.Parser do
defmodule PlugIndie.Parser do
import Plug.Conn
def get_action(conn) do

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub do
defmodule PlugIndie do
@moduledoc """
A Plug for building a Micropub server.
@ -7,7 +7,7 @@ defmodule PlugMicropub do
"""
require Logger
use Plug.Router
alias PlugMicropub.{Parser, Handler, Response}
alias PlugIndie.{Parser, Handler, Response}
plug :match
plug :dispatch
@ -44,7 +44,7 @@ defmodule PlugMicropub do
Keyword.get(opts, :scopes) || @default_scopes
token_handler =
Keyword.get(opts, :token_handler) || PlugMicropub.Token
Keyword.get(opts, :token_handler) || PlugIndie.Token
[
hostname: hostname,

View file

@ -1,6 +1,6 @@
defmodule PlugMicropub.HandlerBehaviour do
defmodule PlugIndie.HandlerBehaviour do
@moduledoc """
Behaviour defining the interface for a PlugMicropub Handler
Behaviour defining the interface for a PlugIndie Handler
"""
@type access_token :: String.t()

View file

@ -1,3 +1,3 @@
defmodule PlugMicropub.Post do
defmodule PlugIndie.Post do
defstruct [:type, :title, :content]
end

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub.Properties do
defmodule PlugIndie.Properties do
def parse(properties) do
{:ok, type} = get_post_type(properties)
content = get_content(properties)
@ -7,7 +7,7 @@ defmodule PlugMicropub.Properties do
case type do
:note ->
{:ok,
%PlugMicropub.Post{
%PlugIndie.Post{
type: type,
title: title,
content: content

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub.Response do
defmodule PlugIndie.Response do
import Plug.Conn
def send_content(conn, content) do

View file

@ -1,8 +1,8 @@
defmodule TestHandler do
@behaviour PlugMicropub.HandlerBehaviour
@behaviour PlugIndie.HandlerBehaviour
@impl true
def handle_create(_type, properties, _access_token) do
def handle_create(_type, %PlugIndie.Post{} = properties, _access_token) do
case properties.type do
:note ->
{:ok, :created, "/notes/4711"}

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub.Token do
defmodule PlugIndie.Token do
require Logger
def verify(

View file

@ -1,4 +1,4 @@
defmodule PlugMicropub.MixProject do
defmodule PlugIndie.MixProject do
use Mix.Project
def project do

View file

@ -1,7 +1,7 @@
defmodule ParserTest do
use ExUnit.Case
doctest PlugMicropub.Parser
import PlugMicropub.Parser, only: [parse_create_body: 2]
doctest PlugIndie.Parser
import PlugIndie.Parser, only: [parse_create_body: 2]
test "parse_create_body with content-type json" do
params = %{

View file

@ -1,10 +1,10 @@
defmodule PlugMicropubTest do
defmodule PlugIndieTest do
use ExUnit.Case, async: true
use Plug.Test
doctest PlugMicropub
doctest PlugIndie
@opts PlugMicropub.init(
@opts PlugIndie.init(
hostname: "example.com",
handler: TestHandler,
token_endpoint: "http://example.com/token",
@ -21,7 +21,7 @@ defmodule PlugMicropubTest do
})
# Invoke the plug
conn = PlugMicropub.call(conn, @opts)
conn = PlugIndie.call(conn, @opts)
# Assert the response and status
assert conn.state == :sent