From 1defc794964bbfca87076c2646c548f928bc71a7 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Wed, 1 Feb 2023 21:13:19 +1100 Subject: [PATCH] Rebuild assets --- Gemfile | 3 ++- Gemfile.lock | 3 +++ app/actions/site/config.rb | 4 ++++ app/commands/posts/syndicate.rb | 24 ++++++++++++++++++++++-- config/providers/syndication.rb | 1 + lib/adamantium/syndication/pinboard.rb | 24 ++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 lib/adamantium/syndication/pinboard.rb diff --git a/Gemfile b/Gemfile index 39672f3..baf28b8 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ gem "httparty" gem "redcarpet" gem "rexml" gem "babosa" +gem "pinboard" group :cli, :development do gem "hanami-reloader" @@ -43,7 +44,7 @@ group :development do gem "capistrano", "~> 3.17", require: false gem "capistrano-bundler" gem "capistrano-rbenv", "~> 2.2" - gem 'capistrano3-puma', github: "seuros/capistrano-puma" + gem "capistrano3-puma", github: "seuros/capistrano-puma" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index d4b3c64..7e2637a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -202,6 +202,8 @@ GEM parser (3.2.0.0) ast (~> 2.4.1) pg (1.4.5) + pinboard (0.0.3) + httparty (~> 0.7) pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) @@ -329,6 +331,7 @@ DEPENDENCIES hanami-view! httparty pg + pinboard puma rack-test rake diff --git a/app/actions/site/config.rb b/app/actions/site/config.rb index ee5f780..9cc82f8 100644 --- a/app/actions/site/config.rb +++ b/app/actions/site/config.rb @@ -24,6 +24,10 @@ module Adamantium { uid: "https://social.dnitza.com", name: "Mastodon" + }, + { + uid: "https://pinboard.in", + name: "Pinboard" } ] }.to_json diff --git a/app/commands/posts/syndicate.rb b/app/commands/posts/syndicate.rb index 5ea5971..93e7a2c 100644 --- a/app/commands/posts/syndicate.rb +++ b/app/commands/posts/syndicate.rb @@ -8,16 +8,36 @@ module Adamantium include Dry::Monads[:result] include Dry::Monads::Do.for(:call) - include Deps["settings", "syndication.mastodon"] + include Deps["settings", + "syndication.mastodon", + "syndication.pinboard" + ] def call(post) - if post[:syndicate_to].any? { |url| settings.mastodon_server.match(/#{url}/) } + syndicate_to = syndication_targets(post[:syndicate_to]) + if syndicate_to.include? :mastodon url = yield mastodon.call(post: post) Success([:mastodon, url]) end + + if syndicate_to.include? :pinboard + url = yield pinboard.call(post: post) + + Success([:pinboard, url]) + end + Failure(:no_syndication_targets) end + + private + + def syndication_targets(syndicate_to) + targets = [] + targets << :mastodon if syndicate_to.any? { |url| settings.mastodon_server.match(/#{url}/) } + targets << :pinboard if syndicate_to.any? { |url| "https://pinboard.in".match(/#{url}/) } + targets + end end end end diff --git a/config/providers/syndication.rb b/config/providers/syndication.rb index f8fc60e..36b18e5 100644 --- a/config/providers/syndication.rb +++ b/config/providers/syndication.rb @@ -1,5 +1,6 @@ Hanami.app.register_provider :syndication, namespace: true do start do register "mastodon", Adamantium::Syndication::Mastodon.new + register "pinboard", Adamantium::Syndication::Pinboard.new(api_key: settings.pinboard_api_key) end end diff --git a/lib/adamantium/syndication/pinboard.rb b/lib/adamantium/syndication/pinboard.rb new file mode 100644 index 0000000..92463fc --- /dev/null +++ b/lib/adamantium/syndication/pinboard.rb @@ -0,0 +1,24 @@ +require "pinboard" +require "dry/monads" + +module Adamantium + module Syndication + class Pinboard + attr_reader :pinboard + include Dry::Monads[:result] + + def initialize(api_key:) + @pinboard = Pinboard::Client.new(token: api_key) + end + + def call(post:) + if pinboard.add(url: post[:url], description: post[:content]) == "done" + href = pinboard.get(url: post[:url]).href + Success(href) + else + Failure(:failed_to_post_to_pinboard) + end + end + end + end +end