From 9cb9125e3e6a79bc68c3551e33bcb6a91390e498 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Mon, 29 Apr 2024 12:00:54 -0500 Subject: [PATCH] ConvertKit email submission --- .env.example | 4 ++++ Gemfile | 1 + Gemfile.lock | 8 ++++++++ app/controllers/signups_controller.rb | 9 +++++++++ app/views/pages/index.html.erb | 4 ++-- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index e69de29b..1fe492c4 100644 --- a/.env.example +++ b/.env.example @@ -0,0 +1,4 @@ +CONVERTKIT_API_KEY= +CONVERTKIT_API_SECRET= +CONVERTKIT_FORM_ID= +CONVERTKIT_TAG_ID= \ No newline at end of file diff --git a/Gemfile b/Gemfile index a8a1f92e..ff8b8f2e 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem "stimulus-rails" gem "turbo-rails" # Other +gem "faraday" gem "jbuilder" gem "tzinfo-data", platforms: %i[ windows jruby ] diff --git a/Gemfile.lock b/Gemfile.lock index 7233fe32..3f51fe02 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,6 +144,10 @@ GEM rubocop smart_properties erubi (1.12.0) + faraday (2.9.0) + faraday-net_http (>= 2.0, < 3.2) + faraday-net_http (3.1.0) + net-http ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) @@ -182,6 +186,8 @@ GEM mini_mime (1.1.5) minitest (5.21.2) msgpack (1.7.2) + net-http (0.4.1) + uri net-imap (0.4.10) date net-protocol @@ -320,6 +326,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) + uri (0.13.0) useragent (0.16.10) web-console (4.2.1) actionview (>= 6.0.0) @@ -350,6 +357,7 @@ DEPENDENCIES debug dotenv-rails erb_lint + faraday hotwire-livereload importmap-rails jbuilder diff --git a/app/controllers/signups_controller.rb b/app/controllers/signups_controller.rb index 3b401eb1..801886ae 100644 --- a/app/controllers/signups_controller.rb +++ b/app/controllers/signups_controller.rb @@ -3,5 +3,14 @@ def new end def create + form_id = ENV["CONVERTKIT_FORM_ID"] + tag_id = ENV["CONVERTKIT_TAG_ID"] + api_key = ENV["CONVERTKIT_API_KEY"] + email = params[:email] + + Faraday.post("https://api.convertkit.com/v3/forms/#{form_id}/subscribe") do |req| + req.headers["Content-Type"] = "application/json; charset=utf-8" + req.body = { api_key: api_key, email: email, tags: [ tag_id ] }.to_json + end end end diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 40d25677..e7c25149 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -1,5 +1,5 @@
-
+
Maybe <%= image_tag("icon-maybe-color.svg", alt: "Maybe Logo", class: "inline") %> is a fully* *your finances are secure open-source
<%= link_to "https://github.com/maybe-finance/maybe", class: "px-2 py-1.5 border-r shadow-[inset_0_-2px_5px_0_rgba(0,0,0,0.07)] bg-neutral-100 rounded-l-md border-neutral-200 flex items-center justify-center" do %> @@ -9,7 +9,7 @@
OS for your personal finances <%= image_tag("icon-chart.svg", alt: "Chart", class: "inline") %> built by a small team <%= image_tag("icon-team.png", alt: "Maybe Team", class: "inline h-9") %> alongside an incredible community <%= image_tag("icon-discord.svg", alt: "Discord", class: "inline") %>
-
+
<%= render_signup_form %>