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 @@