Send bookmarks to Raindrop
This commit is contained in:
@@ -5,7 +5,8 @@ module Adamantium
|
||||
module Posts
|
||||
class CreateBookmark < Command
|
||||
include Deps["repos.post_repo",
|
||||
syndicate: "commands.posts.syndicate"
|
||||
syndicate: "commands.posts.syndicate",
|
||||
raindrop: "syndication.raindrop"
|
||||
]
|
||||
|
||||
include Dry::Monads[:result]
|
||||
@@ -14,6 +15,7 @@ module Adamantium
|
||||
created_bookmark = post_repo.create(bookmark)
|
||||
|
||||
syndicate.call(created_bookmark.id, bookmark)
|
||||
raindrop.call(post: created_bookmark)
|
||||
|
||||
Success(created_bookmark)
|
||||
end
|
||||
|
@@ -3,14 +3,15 @@ div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
|
||||
|
||||
h2 class="text-xl" Explore posts
|
||||
|
||||
div class="grid grid-cols-4 grid-flow-col gap-2 mb-6"
|
||||
div class="grid grid-cols-2 gap-2 mb-6"
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/tags" 🔖 By tag
|
||||
/ a class="block p-1 border border-blue-200 bg-blue-300 text-blue-900 hover:bg-blue-200 text-center rounded-lg" href="/years" 🗓️ By year
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/posts" 🪧 All posts
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/tagged/weekly" 🔄 Week posts
|
||||
|
||||
h2 class="text-xl" Explore everything else
|
||||
|
||||
div class="grid grid-cols-4 grid-flow-col gap-2 mb-6"
|
||||
div class="grid grid-cols-2 gap-2 mb-6"
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/colophon" 🧱 Colophon
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/hikes" 🥾 Hikes
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/movies" 🍿 Movies
|
||||
|
@@ -1,7 +1,7 @@
|
||||
Hanami.app.register_provider :syndication, namespace: true do
|
||||
start do
|
||||
register "mastodon", Adamantium::Syndication::Mastodon.new
|
||||
register "raindrop", Adamantium::Syndication::Raindrop.new(api_key: target["settings"].raindrop_api_key)
|
||||
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,
|
||||
password: target["settings"].smtp_password,
|
||||
|
@@ -11,12 +11,27 @@ module Adamantium
|
||||
end
|
||||
|
||||
def call(post:)
|
||||
if response.code == 200
|
||||
result = JSON.parse(response, symbolize_name: true)
|
||||
result[:item]
|
||||
Success(href)
|
||||
uri = URI('https://api.raindrop.io/rest/v1/raindrop')
|
||||
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||
dict = {
|
||||
"title" => post[:name],
|
||||
"link" => post[:url]
|
||||
}
|
||||
body = JSON.dump(dict)
|
||||
req = Net::HTTP::Post.new(uri)
|
||||
req.add_field "Authorization", api_key
|
||||
req.add_field "Content-Type", "application/json; charset=utf-8"
|
||||
req.body = body
|
||||
|
||||
response = http.request(req)
|
||||
|
||||
if response.code.to_s == "200"
|
||||
Success()
|
||||
else
|
||||
Failure(:failed_to_post_to_pinboard)
|
||||
Failure(:failed_to_post_to_raindrop)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user