Sha256: 7a571c665b8702b63399dab50d0050e49fd32fa8603e36c96289b77016b2e119

Contents?: true

Size: 1.77 KB

Versions: 16

Compression:

Stored size: 1.77 KB

Contents

class MailchimpNewsletterSubscriber < NewsletterSubscriber

  attr_accessor   :member_info_data, :email, :euid, :subscribed, :grouping_id, :groups
  
  # is subscriber interested in the named group?
  #------------------------------------------------------------------------------
  def interest_group?(name)
    group = self.groups.detect {|group| group['name'] == name} if self.groups
    return (group ? group['interested'] : false)
  end

  #------------------------------------------------------------------------------
  def subscribed?
    subscribed
  end
  
  # Instantiate a new subscriber based on data from a Mailchimp query like 
  # member_info.  Does nothing with the database at this time.
  #------------------------------------------------------------------------------
  def self.new_from_mailchimp(attributes = {})
    obj = MailchimpNewsletterSubscriber.new
    obj.member_info_data  = attributes
    obj.subscribed        = attributes['status'] == 'subscribed' ? true : false
    obj.email             = attributes['email']
    obj.euid              = attributes['euid']
    obj.grouping_id       = attributes['merges']['GROUPINGS'] ? attributes['merges']['GROUPINGS'][0]['id'] : nil
    obj.groups            = attributes['merges']['GROUPINGS'] ? attributes['merges']['GROUPINGS'][0]['groups'] : nil
    return obj
  end
  
  # Query for the subscriber info.
  #------------------------------------------------------------------------------
  def self.subscriber_info(newsletter, email)
    api         = MailchimpNewsletter.api
    subscriber  = api.lists.member_info(id: newsletter.mc_id, emails: [email: email])
    if subscriber['success_count'] == 1
      return MailchimpNewsletterSubscriber.new_from_mailchimp(subscriber['data'][0])
    else
      return nil
    end
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dm_newsletter-4.2.3.10 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.9 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.8 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.7 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.6 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.5 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.4 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.3 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.2 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3.1 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.3 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.2.3 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.2.2 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.2.1 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.2 app/models/mailchimp_newsletter_subscriber.rb
dm_newsletter-4.2.1.5 app/models/mailchimp_newsletter_subscriber.rb