diff --git a/Gemfile b/Gemfile index 51d93b0..7859321 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ gem "webmention" gem "sanitize" gem "time_math2", require: "time_math" gem "lastfm", "~> 1.27" +gem "mail" group :cli, :development do gem "hanami-reloader" diff --git a/Gemfile.lock b/Gemfile.lock index d692cdc..8a4ced5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,7 @@ GEM database_cleaner-sequel (2.0.2) database_cleaner-core (~> 2.0.0) sequel + date (3.3.3) diff-lcs (1.5.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) @@ -225,6 +226,11 @@ GEM ffi-compiler (~> 1.0) rake (~> 13.0) lumberjack (1.2.8) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) @@ -237,8 +243,17 @@ GEM hansi (~> 0.2.0) mustermann (= 3.0.0) nenv (0.3.0) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) + net-smtp (0.3.3) + net-protocol net-ssh (7.0.1) netrc (0.11.0) nio4r (2.5.8) @@ -365,6 +380,7 @@ GEM tilt (2.0.11) time_math2 (0.1.1) timecop (0.9.6) + timeout (0.3.2) transproc (1.1.1) unf (0.1.4) unf_ext @@ -404,6 +420,7 @@ DEPENDENCIES hanami-view! httparty lastfm (~> 1.27) + mail ogpr pg pinboard! diff --git a/app/commands/posts/create_entry.rb b/app/commands/posts/create_entry.rb index 45daeb8..3e66077 100644 --- a/app/commands/posts/create_entry.rb +++ b/app/commands/posts/create_entry.rb @@ -8,6 +8,7 @@ module Adamantium "post_utilities.slugify", renderer: "renderers.markdown", syndicate: "commands.posts.syndicate", + send_to_dayone: "syndication.dayone", add_post_syndication_source: "commands.posts.add_syndication_source", send_webmentions: "commands.posts.send_webmentions", ] @@ -18,6 +19,8 @@ module Adamantium post_params = prepare_params(params: post) created_post = post_repo.create(post_params) + send_to_dayone.call(name: post.name, content: post.content) if post[:category].include? "weekly" + syndicate.call(post).bind do |results| results.each do |result| source, url = result diff --git a/config/providers/syndication.rb b/config/providers/syndication.rb index 40eae75..8ae1758 100644 --- a/config/providers/syndication.rb +++ b/config/providers/syndication.rb @@ -2,5 +2,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: target["settings"].pinboard_api_key) + register "dayone", Adamantium::Syndication::Dayone.new end end diff --git a/config/settings.rb b/config/settings.rb index 037b6d9..61587f5 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -28,6 +28,9 @@ module Adamantium setting :lastfm_api_key, default: nil setting :lastfm_secret, default: nil + setting :from_email, default: nil + setting :dayone_email, default: nil + # Micropub endpoints setting :micropub_media_endpoint, default: "", constructor: Types::Params::String diff --git a/lib/adamantium/syndication/dayone.rb b/lib/adamantium/syndication/dayone.rb new file mode 100644 index 0000000..bf4dd2a --- /dev/null +++ b/lib/adamantium/syndication/dayone.rb @@ -0,0 +1,18 @@ +require "mail" + +module Adamantium + module Syndication + class Dayone + include Deps["settings"] + + def call(name:, content:) + Mail.deliver do + to settings.dayone_email + from settings.from_email + subject name + body content + end + end + end + end +end