Add blue sky as a syndication source
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -37,6 +37,7 @@ gem "reverse_markdown"
|
||||
gem "rexml"
|
||||
gem "babosa"
|
||||
gem "pinboard", git: "https://github.com/dnitza/pinboard", branch: "master"
|
||||
gem "bskyrb"
|
||||
gem "ogpr"
|
||||
gem "ruby-filemagic", git: "https://github.com/dnitza/ruby-filemagic", branch: "master"
|
||||
gem "webmention"
|
||||
|
10
Gemfile.lock
10
Gemfile.lock
@@ -122,6 +122,11 @@ GEM
|
||||
babosa (2.0.0)
|
||||
base64 (0.1.1)
|
||||
bigdecimal (3.1.4)
|
||||
bskyrb (0.5.3)
|
||||
date (>= 3.3.3)
|
||||
httparty (>= 0.21.0)
|
||||
json (>= 2.0)
|
||||
xrpc (>= 0.0.4)
|
||||
builder (3.2.4)
|
||||
capistrano (3.18.0)
|
||||
airbrussh (>= 1.0.0)
|
||||
@@ -497,6 +502,10 @@ GEM
|
||||
nokogiri (>= 1.13)
|
||||
xml-simple (1.1.9)
|
||||
rexml
|
||||
xrpc (0.1.7.2)
|
||||
date
|
||||
httparty
|
||||
json (>= 2.0)
|
||||
zeitwerk (2.6.12)
|
||||
|
||||
PLATFORMS
|
||||
@@ -506,6 +515,7 @@ PLATFORMS
|
||||
|
||||
DEPENDENCIES
|
||||
babosa
|
||||
bskyrb
|
||||
builder
|
||||
capistrano (~> 3.7)
|
||||
capistrano-bundler
|
||||
|
@@ -29,6 +29,10 @@ module Adamantium
|
||||
{
|
||||
uid: "https://pinboard.in",
|
||||
name: "Pinboard"
|
||||
},
|
||||
{
|
||||
uid: "https://bsky.app",
|
||||
name: "Blue Sky"
|
||||
}
|
||||
]
|
||||
}.to_json
|
||||
@@ -44,6 +48,10 @@ module Adamantium
|
||||
{
|
||||
uid: "https://pinboard.in",
|
||||
name: "Pinboard"
|
||||
},
|
||||
{
|
||||
uid: "https://bsky.app",
|
||||
name: "Blue Sky"
|
||||
}
|
||||
]
|
||||
}.to_json
|
||||
|
@@ -10,6 +10,7 @@ module Adamantium
|
||||
|
||||
include Deps["settings",
|
||||
"syndication.mastodon",
|
||||
"syndication.blue_sky",
|
||||
add_post_syndication_source: "commands.posts.add_syndication_source",
|
||||
send_to_dayone: "syndication.dayone",
|
||||
]
|
||||
@@ -23,6 +24,12 @@ module Adamantium
|
||||
add_post_syndication_source.call(post_id, :mastodon, res.value!) if res.success?
|
||||
end
|
||||
|
||||
if syndicate_to.include? :blue_sky
|
||||
res = blue_sky.call(post: post)
|
||||
|
||||
add_post_syndication_source.call(post_id, :blue_sky, res.value!) if res.success?
|
||||
end
|
||||
|
||||
if post[:category].include? "weekly"
|
||||
send_to_dayone.call(name: post[:name], content: post[:content])
|
||||
end
|
||||
@@ -35,6 +42,7 @@ module Adamantium
|
||||
def syndication_targets(syndicate_to)
|
||||
targets = []
|
||||
targets << :mastodon if syndicate_to.any? { |url| settings.mastodon_server.match(/#{url}/) }
|
||||
targets << :blue_sky if syndicate_to.any? { |url| settings.blue_sky_url.match(/#{url}/) }
|
||||
targets
|
||||
end
|
||||
end
|
||||
|
2
app/templates/shared/_blue_sky.html.slim
Normal file
2
app/templates/shared/_blue_sky.html.slim
Normal file
@@ -0,0 +1,2 @@
|
||||
- w_class = defined?(width) ? width : "w-6"
|
||||
<svg class="fill-blue-100 hover:fill-blue-400 #{w_class}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M433 179.11c0-97.2-63.71-125.7-63.71-125.7-62.52-28.7-228.56-28.4-290.48 0 0 0-63.72 28.5-63.72 125.7 0 115.7-6.6 259.4 105.63 289.1 40.51 10.7 75.32 13 103.33 11.4 50.81-2.8 79.32-18.1 79.32-18.1l-1.7-36.9s-36.31 11.4-77.12 10.1c-40.41-1.4-83-4.4-89.63-54a102.54 102.54 0 0 1-.9-13.9c85.63 20.9 158.65 9.1 178.75 6.7 56.12-6.7 105-41.3 111.23-72.9 9.8-49.8 9-121.5 9-121.5zm-75.12 125.2h-46.63v-114.2c0-49.7-64-51.6-64 6.9v62.5h-46.33V197c0-58.5-64-56.6-64-6.9v114.2H90.19c0-122.1-5.2-147.9 18.41-175 25.9-28.9 79.82-30.8 103.83 6.1l11.6 19.5 11.6-19.5c24.11-37.1 78.12-34.8 103.83-6.1 23.71 27.3 18.4 53 18.4 175z"/></svg>
|
@@ -1,6 +1,7 @@
|
||||
Hanami.app.register_provider :clients, namespace: true do
|
||||
start do
|
||||
register "mastodon", Adamantium::Client::Mastodon.new
|
||||
register "blue_sky", Adamantium::Client::BlueSky.new
|
||||
register "omdb", Adamantium::Client::Omdb.new(api_key: target["settings"].omdb_api_key)
|
||||
end
|
||||
end
|
||||
|
@@ -1,6 +1,7 @@
|
||||
Hanami.app.register_provider :syndication, namespace: true do
|
||||
start do
|
||||
register "mastodon", Adamantium::Syndication::Mastodon.new
|
||||
register "blue_sky", Adamantium::Syndication::BlueSky.new
|
||||
register "raindrop", Adamantium::Syndication::Raindrop.new(api_key: "Bearer #{target["settings"].raindrop_api_key}")
|
||||
register "dayone", Adamantium::Syndication::Dayone.new(
|
||||
username: target["settings"].smtp_username,
|
||||
|
@@ -22,6 +22,10 @@ module Adamantium
|
||||
setting :mastodon_url, default: nil
|
||||
setting :fed_bridge_url, default: nil
|
||||
|
||||
setting :blue_sky_url, default: nil
|
||||
setting :blue_sky_username, default: nil
|
||||
setting :blue_sky_password, default: nil
|
||||
|
||||
setting :webmention_url, default: nil
|
||||
setting :pingback_url, default: nil
|
||||
setting :webmention_token, default: nil
|
||||
|
52
lib/adamantium/client/blue_sky.rb
Normal file
52
lib/adamantium/client/blue_sky.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
require "bskyrb"
|
||||
require "digest"
|
||||
require "tempfile"
|
||||
require "open-uri"
|
||||
require "dry/monads"
|
||||
require "sanitize"
|
||||
|
||||
module Adamantium
|
||||
module Client
|
||||
class BlueSky
|
||||
include Dry::Monads[:result]
|
||||
include Deps["settings"]
|
||||
|
||||
def create_post(post:)
|
||||
unless settings.mastodon_token && settings.mastodon_server
|
||||
return Failure(:no_mastodon_credentials)
|
||||
end
|
||||
|
||||
content = if post[:name]
|
||||
"#{post[:name]} — #{settings.micropub_site_url}/post/#{post[:slug]}"
|
||||
else
|
||||
"#{sanitze_post(post[:content])} \r\n\r\n 🔗 #{settings.micropub_site_url}/post/#{post[:slug]}"
|
||||
end
|
||||
|
||||
credentials = Bskyrb::Credentials.new(settings.blue_sky_username, settings.blue_sky_password)
|
||||
session = Bskyrb::Session.new(credentials, settings.blue_sky_url)
|
||||
client = Bskyrb::RecordManager.new(session)
|
||||
|
||||
response = client.create_post content
|
||||
|
||||
if response["uri"] && response["uri"] != ""
|
||||
Success(response["uri"])
|
||||
else
|
||||
Failure(response.message)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitze_post(content)
|
||||
replace_links = lambda { |env|
|
||||
return unless env[:node_name] == "a"
|
||||
node = env[:node]
|
||||
url = node[:href]
|
||||
env[:node].replace(url)
|
||||
}
|
||||
|
||||
Sanitize.fragment(content, transformers: [replace_links]).strip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
lib/adamantium/syndication/blue_sky.rb
Normal file
20
lib/adamantium/syndication/blue_sky.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require "dry/monads"
|
||||
|
||||
module Adamantium
|
||||
module Syndication
|
||||
class BlueSky
|
||||
include Dry::Monads[:result]
|
||||
include Deps[blue_sky_client: "clients.blue_sky"]
|
||||
|
||||
def call(post:)
|
||||
response = blue_sky.create_post(post: post)
|
||||
|
||||
if response.success?
|
||||
Success(response.value!)
|
||||
else
|
||||
Failure(:failed_to_syndicate)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -4,7 +4,7 @@ require "dry/monads"
|
||||
RSpec.describe Adamantium::Commands::Posts::Syndicate do
|
||||
include Dry::Monads[:result]
|
||||
|
||||
let(:settings) { double("settings", mastodon_server: "https://mastodon.example/@tester") }
|
||||
let(:settings) { double("settings", mastodon_server: "https://mastodon.example/@tester", blue_sky_url: "https://bluesky.app") }
|
||||
let(:mastodon_client) { double("Adamantium::Client::Mastodon") }
|
||||
let(:mastodon_syndicator) { Adamantium::Syndication::Mastodon.new(mastodon_client: mastodon_client) }
|
||||
let(:post) { {url: "example.com", syndicate_to: ["https://mastodon.example", "https://pinboard.in"], category: []} }
|
||||
|
Reference in New Issue
Block a user