Allow parsing of webmention.io mentions
This commit is contained in:
@@ -5,18 +5,20 @@ module Adamantium
|
|||||||
include Dry::Monads[:result]
|
include Dry::Monads[:result]
|
||||||
|
|
||||||
def call(params:)
|
def call(params:)
|
||||||
case params[:"wm-property"]
|
wm_params = params.fetch(:post, params)
|
||||||
|
|
||||||
|
case wm_params[:"wm-property"]
|
||||||
when "in-reply-to"
|
when "in-reply-to"
|
||||||
Success[:reply, {
|
Success[:reply, {
|
||||||
type: "reply",
|
type: "reply",
|
||||||
author_name: params[:author][:name],
|
author_name: wm_params[:author][:name],
|
||||||
author_photo: params[:author][:photo],
|
author_photo: wm_params[:author][:photo],
|
||||||
author_url: params[:author][:url],
|
author_url: wm_params[:author][:url],
|
||||||
published_at: params[:published],
|
published_at: wm_params[:published],
|
||||||
content_html: params[:content][:html],
|
content_html: wm_params[:content][:html],
|
||||||
content_text: params[:content][:text],
|
content_text: wm_params[:content][:text],
|
||||||
source_url: params[:url],
|
source_url: wm_params[:url],
|
||||||
target_url: params[:"in-reply-to"]
|
target_url: wm_params[:"in-reply-to"]
|
||||||
}]
|
}]
|
||||||
when "like-of"
|
when "like-of"
|
||||||
Failure(:not_implemented)
|
Failure(:not_implemented)
|
||||||
|
@@ -29,9 +29,38 @@ RSpec.describe Adamantium::WebmentionRequestParser do
|
|||||||
}'
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let(:webmention_io_json) {
|
||||||
|
'{
|
||||||
|
"post": {
|
||||||
|
"type":"entry",
|
||||||
|
"author": {
|
||||||
|
"type":"card",
|
||||||
|
"name":"nitza",
|
||||||
|
"photo":"https://webmention.io/avatar/micro.blog/2aa75068b73fe7777faf37c7933486a6acd5d158fcdf769064c0472ecd55f120.jpg",
|
||||||
|
"url":"https://micro.blog/nitza"
|
||||||
|
},
|
||||||
|
"url":"https://micro.blog/nitza/28127218",
|
||||||
|
"published":"2023-12-20T22:28:40+00:00",
|
||||||
|
"wm-received":"2023-12-20T22:28:42Z",
|
||||||
|
"wm-id":1756646,
|
||||||
|
"wm-source":"https://micro.blog/nitza/28127218",
|
||||||
|
"wm-target":"https://dnitza.com/post/b9d5bfca-4f51-463c-a63c-7b2e1b8a5ad9",
|
||||||
|
"wm-protocol":"webmention",
|
||||||
|
"content":{
|
||||||
|
"html": "<p><a href=\"https://micro.blog/example\">@example</a> hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅</p>",
|
||||||
|
"text": "@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅"
|
||||||
|
},
|
||||||
|
"in-reply-to":"https://dnitza.com/post/b9d5bfca-4f51-463c-a63c-7b2e1b8a5ad9",
|
||||||
|
"wm-property":"in-reply-to",
|
||||||
|
"wm-private":false
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
context "reply" do
|
context "reply" do
|
||||||
it "parses a reply" do
|
it "parses a reply" do
|
||||||
expect(subject.call(params: JSON.parse(reply_json, symbolize_names: true))).to be_success
|
expect(subject.call(params: JSON.parse(reply_json, symbolize_names: true))).to be_success
|
||||||
|
expect(subject.call(params: JSON.parse(webmention_io_json, symbolize_names: true))).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails to parses a reply" do
|
it "fails to parses a reply" do
|
||||||
|
Reference in New Issue
Block a user