From 0083443168a5a88149b1e6380d3fae28f0dd7113 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Thu, 6 Jul 2023 21:14:23 +1000 Subject: [PATCH] Add stubs for remaining webmention types --- app/actions/webmentions/create.rb | 2 ++ lib/adamantium/webmention_request_parser.rb | 14 +++++++++-- .../webmention_request_parser_spec.rb | 3 +-- spec/requests/create_webmention_spec.rb | 24 +++++++++---------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/actions/webmentions/create.rb b/app/actions/webmentions/create.rb index 4a68b2d..71c5dd5 100644 --- a/app/actions/webmentions/create.rb +++ b/app/actions/webmentions/create.rb @@ -22,6 +22,8 @@ module Adamantium res.status = 201 in Failure(:invalid_request) res.status = 429 + in Failure(:not_implemented) + res.status = 429 end end end diff --git a/lib/adamantium/webmention_request_parser.rb b/lib/adamantium/webmention_request_parser.rb index 9f93dfe..3b7bf68 100644 --- a/lib/adamantium/webmention_request_parser.rb +++ b/lib/adamantium/webmention_request_parser.rb @@ -2,11 +2,11 @@ require "dry/monads" module Adamantium class WebmentionRequestParser - include Dry::Monads[:result] def call(params:) - if params[:"wm-property"] == "in-reply-to" + case params[:"wm-property"] + when "in-reply-to" Success[:reply, { type: "reply", author_name: params[:author][:name], @@ -18,6 +18,16 @@ module Adamantium source_url: params[:url], target_url: params[:"in-reply-to"] }] + when "like-of" + Failure(:not_implemented) + when "repost-of" + Failure(:not_implemented) + when "bookmark-of" + Failure(:not_implemented) + when "mention-of" + Failure(:not_implemented) + when "rsvp" + Failure(:not_implemented) else Failure(:invalid_request) end diff --git a/spec/adamantium/webmention_request_parser_spec.rb b/spec/adamantium/webmention_request_parser_spec.rb index 93f1b0e..703f8f4 100644 --- a/spec/adamantium/webmention_request_parser_spec.rb +++ b/spec/adamantium/webmention_request_parser_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# + RSpec.describe Adamantium::WebmentionRequestParser do include Dry::Monads[:result] subject { described_class.new } @@ -39,4 +39,3 @@ RSpec.describe Adamantium::WebmentionRequestParser do end end end - diff --git a/spec/requests/create_webmention_spec.rb b/spec/requests/create_webmention_spec.rb index e730d8f..af5d6c9 100644 --- a/spec/requests/create_webmention_spec.rb +++ b/spec/requests/create_webmention_spec.rb @@ -7,22 +7,22 @@ RSpec.describe "Webmention creation", :db, :requests do context "reply" do let(:reply_json) { { - "type": "entry", - "author": { - "type": "card", - "name": "nitza", - "photo": "", - "url": "https://micro.blog/nitza" + type: "entry", + author: { + type: "card", + name: "nitza", + photo: "", + url: "https://micro.blog/nitza" }, - "url": "https://micro.blog/nitza/20554783", - "published": "2023-07-05T09:44:41+00:00", + url: "https://micro.blog/nitza/20554783", + published: "2023-07-05T09:44:41+00:00", "wm-received": "2023-07-05T09:44:48Z", "wm-id": 1692950, "wm-source": "https://micro.blog/nitza/20554783", "wm-target": "https://dnitza.com/post/#{post_record.slug}", - "content": { - "html": "

@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅

", - "text": "@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅" + content: { + html: "

@example hah! I thought the same thing — but this is the most affordable thing that Teenage Engineering makes 😅

", + 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/#{post_record.slug}", "wm-property": "in-reply-to", @@ -38,4 +38,4 @@ RSpec.describe "Webmention creation", :db, :requests do expect(last_response).to be_successful end end -end \ No newline at end of file +end