Class: Crm::MailingRecipient

Inherits:
Core::BasicResource show all
Includes:
Core::Mixins::Inspectable
Defined in:
lib/crm/mailing_recipient.rb

Overview

MailingRecipient represents a mailing recipient email address.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Mixins::Inspectable

#inspect

Methods inherited from Core::BasicResource

base_type, #eql?, #id, path, #path, #reload, resource_name, #type

Methods included from Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Class Method Details

.find(email) ⇒ MailingRecipient

Returns the requested mailing recipient.

Examples:

r = Crm::MailingRecipient.find("[email protected]")
r.active
# => true
r.consent
# => "unknown"
r.consent_given_at
# => nil
r.consent_revoked_at
# => nil
r.complained_at
# => nil
r.permanent_bounced_at
# => nil
r.topic_names
# => ["foo"]
r.topic_names_unsubscribed
# => ["bar", "baz"]
r.consent_logs
# => [
  {
    "at"=>"2018-06-20T13:13:32Z",
    "description"=>"edited by API2 user root: this is the reason",
    "changes"=>{"active"=>["false", "true"]
  }
]

Parameters:

  • email (String)

    the email address

Returns:



38
39
40
41
42
43
# File 'lib/crm/mailing_recipient.rb', line 38

def self.find(email)
  if email.blank?
    raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [email])
  end
  new({'id' => email}).reload
end

Instance Method Details

#update(attributes = {}) ⇒ self

Updates the attributes of this mailing recipient.

Examples:

mailing_recipient.update({
  consent: "given",
  topic_names: ["foo", "bar"],
  edit_reason: "user registered on www.example.com and confirmed the double opt-in email link",
})
mailing_recipient.update({
  consent: "revoked",
  edit_reason: "user unsubscribed using our newsletter form on www.example.com",
})

Parameters:

  • attributes (Hash{String, Symbol => String}) (defaults to: {})

    the new attributes.

Returns:

  • (self)

    the updated mailing recipient.



59
60
61
# File 'lib/crm/mailing_recipient.rb', line 59

def update(attributes = {})
  load_attributes(Core::RestApi.instance.put(path, attributes, if_match_header))
end