Module: Devise::Models::Mailjet
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_mailjet/model.rb,
lib/devise_mailjet/mailjet_list_api_mapper.rb
Overview
Mailjet is responsible for joining users to mailjet lists when the create accounts with devise When a user is created, and join_mailing_list is set to true, they will automatically be added to one or more mailing lists returned by mailjet_lists_to_join.
Configuration
mailing_list_name: Default mailing list for user to join. This can be an array of strings, or just one string.
By default, this is "Site List". If this will be configurable for each user, override
mailjet_lists_to_join returning the list name or an array of list names for the user to
join.
mailing_list_opt_in_by_default: Determines if the checkbox for the user to opt-in to the mailing list should
be checked by default, or not. Defaults to true.
Examples:
User.find(1).add_to_mailjet_list('Site Administrators List')
User.find(1).remove_from_mailjet_list('Site Administrators List')
u = User.new
u.join_mailing_list = true
u.save
Defined Under Namespace
Modules: ClassMethods Classes: MailjetListApiMapper
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_mailjet_list(list_name) ⇒ Object
Add the user to the mailjet list with the specified name.
-
#commit_mailing_list_join ⇒ Object
Commit the user to the mailing list if they have selected to join.
- #join_mailing_list ⇒ Object
-
#join_mailing_list=(join) ⇒ Object
Set this to true to have the user automatically join the mailjet_lists_to_join.
-
#mailjet_list_mapper ⇒ Object
mapper that helps convert list names to mailjet ids.
-
#mailjet_lists_to_join ⇒ Object
The mailing list or lists the user will join Should return either a single string or an array of strings.
-
#remove_from_mailjet_list(list_name) ⇒ Object
remove the user from the mailjet list with the specified name.
Class Method Details
.required_fields(klass) ⇒ Object
33 34 35 |
# File 'lib/devise_mailjet/model.rb', line 33 def self.required_fields(klass) [ :join_mailing_list ] end |
Instance Method Details
#add_to_mailjet_list(list_name) ⇒ Object
Add the user to the mailjet list with the specified name
56 57 58 59 60 |
# File 'lib/devise_mailjet/model.rb', line 56 def add_to_mailjet_list(list_name) mapper = mailjet_list_mapper.respond_to?(:delay) ? mailjet_list_mapper.delay : mailjet_list_mapper # options = self.respond_to?(:mailjet_list_subscribe_options) ? mailjet_list_subscribe_options : {} mapper.subscribe_to_lists(list_name, self.email) end |
#commit_mailing_list_join ⇒ Object
Commit the user to the mailing list if they have selected to join
69 70 71 |
# File 'lib/devise_mailjet/model.rb', line 69 def commit_mailing_list_join add_to_mailjet_list(mailjet_lists_to_join) if self.join_mailing_list end |
#join_mailing_list ⇒ Object
43 44 45 |
# File 'lib/devise_mailjet/model.rb', line 43 def join_mailing_list (new_record?) ? self.class.mailing_list_opt_in_by_default : read_attribute(:join_mailing_list) end |
#join_mailing_list=(join) ⇒ Object
Set this to true to have the user automatically join the mailjet_lists_to_join
38 39 40 41 |
# File 'lib/devise_mailjet/model.rb', line 38 def join_mailing_list=(join) join.downcase! if join.is_a?(String) write_attribute(:join_mailing_list, ['yes','true',true,'1',1].include?(join)) end |
#mailjet_list_mapper ⇒ Object
mapper that helps convert list names to mailjet ids
74 75 76 |
# File 'lib/devise_mailjet/model.rb', line 74 def mailjet_list_mapper @@mailjet_list_mapper ||= MailjetListApiMapper.new end |
#mailjet_lists_to_join ⇒ Object
The mailing list or lists the user will join Should return either a single string or an array of strings. By default, returns the mailing_list_name configuration option. If you want to customize the lists based on other information, override this method in your model.
51 52 53 |
# File 'lib/devise_mailjet/model.rb', line 51 def mailjet_lists_to_join self.class.mailing_list_name end |
#remove_from_mailjet_list(list_name) ⇒ Object
remove the user from the mailjet list with the specified name
63 64 65 66 |
# File 'lib/devise_mailjet/model.rb', line 63 def remove_from_mailjet_list(list_name) mapper = mailjet_list_mapper.respond_to?(:delay) ? mailjet_list_mapper.delay : mailjet_list_mapper mapper.unsubscribe_from_lists(list_name, self.email) end |