Simple Mail Opt In/Out Service, its based on JSONAPI Format.
Subscribe a user to a list of diffusion
curl -X POST \
http(s)://<domain>/users/:user_id/subscriptions/subscribe \
-H 'Accept: application/vnd.api+json' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"data": {
"attributes": {
"list": "Newsletters"
}
}
}'Unubscribe a given user to a list of diffusion
curl -X POST \
http(s)://<domain>/users/:user_id/subscriptions/subscribe \
-H 'Accept: application/vnd.api+json' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"data": {
"attributes": {
"list": "Whatever List"
}
}
}'Get the subscriptions of a given user
curl -X GET \
http(s)://<domain>/users/:user_id/subscriptions \
-H 'Accept: application/vnd.api+json' \
-H 'Content-Type: application/vnd.api+json' \
-H 'cache-control: no-cache'{
"data": [
{
"id": "1bbd2fc2-9deb-4c07-ab10-13ebea5f7ab5",
"type": "subscription",
"attributes": {
"list": "Joel Test List"
}
}
]
}See API Doc here https://documenter.getpostman.com/view/2646236/S11NMH9y
gem 'mail_opt_out'And then execute:
$ bundleOr install it yourself as:
$ gem install mail_opt_outmount MailOptOut::Engine => '/'bundle exec rails generate migration CreateMailOptOutLists
class CreateMailOptOutLists < ActiveRecord::Migration[5.2]
def change
create_table :mail_opt_out_lists do |t|
t.string :number
t.string :name
t.text :description
t.boolean :published, default: false
t.timestamps
end
end
endbundle exec rails generate migration CreateMailOptOutSubscriptionsclass CreateMailOptOutSubscriptions < ActiveRecord::Migration[5.2]
def change
create_table :mail_opt_out_subscriptions do |t|
t.references :list
t.references :user, polymorphic: true, index: true
t.timestamps
end
end
endThis Engine is designed to support serveral services, for now it come with Mailchimp
This gem come with a integration to Mailchimp, however is totally optional.
If you want to activate it
gem 'gibbon'Set ENV['MAILCHIMP_API_KEY']
To synchronize your Mailchimp list add Rake Task to periodically launch MailOptOut.sync
If you have a different User model you define it.
If you to set thrid service as backgound just tick async = true
You can add config/initialize/mail_opt_out.rb
require 'mail_opt_out'
MailOptOut.user_class = 'User'
MailOptOut.async = true
make sure all tests still passed, and every contribution is covered by test.
rake
By Priority 1 low, 5 high
Engine
- 1 Add Generators
- 1 Rake Task to sync existing data with services
- 1 Rake Task to setup, start and cleanup dummy app
- 1 Extract Engine, Gem and Services
- mail-opt-out-engine
- mail-opt-out-core
- mail-opt-out-mailchimp
Core
- 1 Rename List#number => List#code
- 5 Make List Name Unique on Number Scope
- 3 Make configurable email method on User#email
- 3 Make configurable User#name, first_name, last_name
- 1 Add Code Doc
Services (Mailchimp)
- 2 Set FirstName LastName if it possible
The gem is available as open source under the terms of the MIT License.