Class: CommunicationRecipient
Overview
== Schema Information
Table name: communication_recipients
Database name: primary
id :integer not null, primary key
category :string(255)
detail :string(255)
email_method :string(3)
ip_address :string(255)
name :string(255)
state :string(25)
state_response :text
state_updated_at :datetime
user_agent :text
created_at :datetime not null
updated_at :datetime not null
communication_id :integer
contact_point_id :integer
Indexes
idx_comm_rp_contact_point_id (contact_point_id)
idx_communication_id_contact_point_id (communication_id,contact_point_id)
idx_communication_id_email_method (communication_id,email_method)
idx_communication_recipients_unique (communication_id,category,detail) UNIQUE
index_communication_recipients_on_state (state)
index_communication_recipients_on_state_updated_at (state_updated_at) USING brin
Foreign Keys
communication_recipients_communication_id_fk (communication_id => communications.id) ON DELETE => cascade
Constant Summary
collapse
- UNDELIVERED =
%w[dropped deferred bounced].freeze
- DELIVERED =
%w[processed delivered opened clicked spammed unsubscribed].freeze
- UNWANTED =
%w[spammed unsubscribed].freeze
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#combo_category ⇒ Object
Returns the value of attribute combo_category.
50
51
52
|
# File 'app/models/communication_recipient.rb', line 50
def combo_category
@combo_category
end
|
#detail ⇒ Object
121
|
# File 'app/models/communication_recipient.rb', line 121
validates :detail, presence: true
|
#ignore_global_unsubscribe ⇒ Object
Returns the value of attribute ignore_global_unsubscribe.
51
52
53
|
# File 'app/models/communication_recipient.rb', line 51
def ignore_global_unsubscribe
@ignore_global_unsubscribe
end
|
Class Method Details
A relation of CommunicationRecipients that are emails. Active Record Scope
112
|
# File 'app/models/communication_recipient.rb', line 112
scope :emails, -> { where(category: ContactPoint::EMAIL) }
|
A relation of CommunicationRecipients that are faxes. Active Record Scope
113
|
# File 'app/models/communication_recipient.rb', line 113
scope :faxes, -> { where(category: ContactPoint::FAX) }
|
.states_for_select ⇒ Object
131
132
133
|
# File 'app/models/communication_recipient.rb', line 131
def self.states_for_select
state_machines[:state].states.map(&:name)
end
|
A relation of CommunicationRecipients that are undelivered. Active Record Scope
114
|
# File 'app/models/communication_recipient.rb', line 114
scope :undelivered, -> { where(state: UNDELIVERED) }
|
A relation of CommunicationRecipients that are unwanted. Active Record Scope
115
|
# File 'app/models/communication_recipient.rb', line 115
scope :unwanted, -> { where(state: UNWANTED) }
|
A relation of CommunicationRecipients that are with party. Active Record Scope
111
|
# File 'app/models/communication_recipient.rb', line 111
scope :with_party, -> { joins(contact_point: :party) }
|
Instance Method Details
45
|
# File 'app/models/communication_recipient.rb', line 45
has_one :campaign_delivery
|
43
|
# File 'app/models/communication_recipient.rb', line 43
belongs_to :communication, inverse_of: :communication_recipients, optional: true
|
#communication_recipient_email_links ⇒ ActiveRecord::Relation<CommunicationRecipientEmailLink>
47
|
# File 'app/models/communication_recipient.rb', line 47
has_many :communication_recipient_email_links
|
44
|
# File 'app/models/communication_recipient.rb', line 44
belongs_to :contact_point, inverse_of: :communication_recipients, optional: true
|
#customer ⇒ Object
189
190
191
|
# File 'app/models/communication_recipient.rb', line 189
def customer
party.try(:customer)
end
|
#deep_dup ⇒ Object
125
126
127
128
129
|
# File 'app/models/communication_recipient.rb', line 125
def deep_dup
deep_clone(except: %i[state_updated_at user_agent ip_address state_response]) do |_original, copy|
copy.state = 'ok' if copy.is_a?(CommunicationRecipient)
end
end
|
#display_name ⇒ Object
193
194
195
|
# File 'app/models/communication_recipient.rb', line 193
def display_name
name || contact_point.try(:party).try(:full_name)
end
|
#email_links ⇒ ActiveRecord::Relation<EmailLink>
48
|
# File 'app/models/communication_recipient.rb', line 48
has_many :email_links, -> { distinct }, through: :communication_recipient_email_links
|
#is_email? ⇒ Boolean
167
168
169
|
# File 'app/models/communication_recipient.rb', line 167
def is_email?
category == ContactPoint::EMAIL
end
|
#is_fax? ⇒ Boolean
171
172
173
|
# File 'app/models/communication_recipient.rb', line 171
def is_fax?
category == ContactPoint::FAX
end
|
#is_undelivered? ⇒ Boolean
159
160
161
|
# File 'app/models/communication_recipient.rb', line 159
def is_undelivered?
UNDELIVERED.include? state
end
|
#is_unwanted? ⇒ Boolean
163
164
165
|
# File 'app/models/communication_recipient.rb', line 163
def is_unwanted?
UNWANTED.include? state
end
|
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'app/models/communication_recipient.rb', line 208
def normalize_format
return if detail.blank?
self.detail = detail.gsub(/\P{ASCII}/u, '').strip.downcase
if RFC822::EMAIL.match?(detail)
self.category = ContactPoint::EMAIL
elsif p = PhoneNumber.parse(detail)
self.category = ContactPoint::FAX
self.detail = p.to_s
end
true
end
|
#notify_rep_email_bounced ⇒ Object
#party ⇒ Object
185
186
187
|
# File 'app/models/communication_recipient.rb', line 185
def party
contact_point.try(:party)
end
|
#webhook_events ⇒ ActiveRecord::Relation<WebhookEvent>
46
|
# File 'app/models/communication_recipient.rb', line 46
has_many :webhook_events
|