Class: MailService::Member
- Inherits:
-
Object
- Object
- MailService::Member
- Includes:
- ActiveModel::Model
- Defined in:
- app/services/mail_service/member.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#double_optin ⇒ Object
readonly
Returns the value of attribute double_optin.
-
#email ⇒ Object
(also: #name)
Attribute Settings —————————————————————————————.
-
#list_id ⇒ Object
Attribute Settings —————————————————————————————.
-
#locale ⇒ Object
Attribute Settings —————————————————————————————.
-
#subscriber_id ⇒ Object
readonly
Returns the value of attribute subscriber_id.
Class Method Summary collapse
-
.create(attributes = {}) ⇒ Object
Class Methods —————————————————————————————.
- .exists?(options = {}) ⇒ Boolean
- .find_by_email(email) ⇒ Object
Instance Method Summary collapse
- #confirmed? ⇒ Boolean
- #destroy ⇒ Object
- #info ⇒ Object
-
#initialize(attributes = {}) {|_self| ... } ⇒ Member
constructor
Constructor —————————————————————————————.
-
#list ⇒ Object
Instance Methods —————————————————————————————.
- #method_missing(method_name, *args, &block) ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ Member
Constructor
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/services/mail_service/member.rb', line 74 def initialize(attributes = {}) defaults = { locale: I18n.locale, double_optin: true } attributes = defaults.merge(attributes).symbolize_keys @email = attributes[:email] @locale = attributes[:locale] @connection = self.class.parent.connection @double_optin = attributes[:double_optin] @list_id = attributes[:list_id] yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
156 157 158 159 160 161 162 |
# File 'app/services/mail_service/member.rb', line 156 def method_missing(method_name, *args, &block) if info.keys.include?(method_name.to_s) info[method_name] else super end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
40 41 42 |
# File 'app/services/mail_service/member.rb', line 40 def connection @connection end |
#double_optin ⇒ Object (readonly)
Returns the value of attribute double_optin.
40 41 42 |
# File 'app/services/mail_service/member.rb', line 40 def double_optin @double_optin end |
#email ⇒ Object Also known as: name
Attribute Settings
38 39 40 |
# File 'app/services/mail_service/member.rb', line 38 def email @email end |
#list_id ⇒ Object
Attribute Settings
38 39 40 |
# File 'app/services/mail_service/member.rb', line 38 def list_id @list_id end |
#locale ⇒ Object
Attribute Settings
38 39 40 |
# File 'app/services/mail_service/member.rb', line 38 def locale @locale end |
#subscriber_id ⇒ Object (readonly)
Returns the value of attribute subscriber_id.
40 41 42 |
# File 'app/services/mail_service/member.rb', line 40 def subscriber_id @subscriber_id end |
Class Method Details
.create(attributes = {}) ⇒ Object
Class Methods
172 173 174 175 176 |
# File 'app/services/mail_service/member.rb', line 172 def self.create(attributes = {}) mailservice = new(attributes) mailservice.save mailservice end |
.exists?(options = {}) ⇒ Boolean
182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/services/mail_service/member.rb', line 182 def self.exists?( = {}) return false if .blank? begin new(.slice(:email, :list_id)).info.present? rescue => e Rails.logger.info "**[MailService Error][Exists] #{e.}" Rails.logger.warn "**[MailService Error][Exists] #{e.backtrace.join("\n")}" if Rails.env.development? e. end end |
.find_by_email(email) ⇒ Object
178 179 180 |
# File 'app/services/mail_service/member.rb', line 178 def self.find_by_email(email) new(new(email: email).info.symbolize_keys) end |
Instance Method Details
#confirmed? ⇒ Boolean
152 153 154 |
# File 'app/services/mail_service/member.rb', line 152 def confirmed? info[:timestamp_opt].present? end |
#destroy ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/services/mail_service/member.rb', line 140 def destroy begin connection.lists.unsubscribe( id: list_id, email: { email: email } ) rescue => e Rails.logger.info "**[MailService Error][Destroy] #{e.}" Rails.logger.warn "**[MailService Error][Destroy] #{e.backtrace.join("\n")}" if Rails.env.development? end end |
#info ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/services/mail_service/member.rb', line 103 def info begin unless @info response = connection.lists.member_info(id: list_id, emails: [{ email: email}]).with_indifferent_access @info = response[:data].first if response[:success_count] && response[:success_count] >= 1 end rescue => e Rails.logger.info "**[MailService Error][Info] #{e.}" Rails.logger.warn "**[MailService Error][Info] #{e.backtrace.join("\n")}" if Rails.env.development? end @info || {} end |
#list ⇒ Object
Instance Methods
99 100 101 |
# File 'app/services/mail_service/member.rb', line 99 def list List.find_by_list_id(list_id) if list_id end |
#persisted? ⇒ Boolean
117 118 119 |
# File 'app/services/mail_service/member.rb', line 117 def persisted? false end |
#save ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/services/mail_service/member.rb', line 121 def save return false unless valid? return true if Rails.env.test? begin connection.lists.subscribe( id: list_id, email: { email: email }, double_optin: double_optin, merge_vars: { mc_language: locale } ) rescue => e Rails.logger.info "**[MailService Error][Save] #{e.}" Rails.logger.warn "**[MailService Error][Save] #{e.backtrace.join("\n")}" if Rails.env.development? false end end |