mirror of
https://github.com/danbee/micropub.git
synced 2025-03-04 08:59:13 +00:00
Add first JSON spec
This commit is contained in:
parent
dca44465e1
commit
084511e8b8
@ -26,7 +26,7 @@ module Micropub
|
|||||||
|
|
||||||
post "/micropub/main" do
|
post "/micropub/main" do
|
||||||
if valid_token?
|
if valid_token?
|
||||||
post = Post.new(params)
|
post = Post.new(post_params)
|
||||||
|
|
||||||
if github.post!(post)
|
if github.post!(post)
|
||||||
headers "Location" => "#{ENV.fetch("SITE_URL")}#{post.path}"
|
headers "Location" => "#{ENV.fetch("SITE_URL")}#{post.path}"
|
||||||
@ -39,6 +39,15 @@ module Micropub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_params
|
||||||
|
if request.env["CONTENT_TYPE"] == "application/json"
|
||||||
|
request.body.rewind
|
||||||
|
JSON.parse(request.body.read)
|
||||||
|
else
|
||||||
|
params
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def valid_token?
|
def valid_token?
|
||||||
token = Indieauth::Token.new(endpoints.token_endpoint)
|
token = Indieauth::Token.new(endpoints.token_endpoint)
|
||||||
|
|
||||||
|
|||||||
@ -61,5 +61,16 @@ describe "create post" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "creates a post with JSON" do
|
it "creates a post with JSON" do
|
||||||
|
post_json = {
|
||||||
|
content: "Hello, World!",
|
||||||
|
category: ["one", "two", "three"],
|
||||||
|
}.to_json
|
||||||
|
|
||||||
|
post "/micropub/main", post_json, { "CONTENT_TYPE" => "application/json" }
|
||||||
|
|
||||||
|
date = Time.now.strftime("%Y/%m/%d")
|
||||||
|
assert last_response.accepted?
|
||||||
|
assert_equal last_response.headers["Location"],
|
||||||
|
"https://test.danbarber.me/blog/#{date}/hello-world"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user