Class: MailchimpSyncJob

Inherits:
Struct
  • Object
show all
Defined in:
app/models/job/mailchimp_sync_job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mailchimp_kitObject

Returns the value of attribute mailchimp_kit

Returns:

  • (Object)

    the current value of mailchimp_kit



1
2
3
# File 'app/models/job/mailchimp_sync_job.rb', line 1

def mailchimp_kit
  @mailchimp_kit
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



1
2
3
# File 'app/models/job/mailchimp_sync_job.rb', line 1

def options
  @options
end

Class Method Details

.merged_person(kit, loser_email, winner_id, new_lists) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'app/models/job/mailchimp_sync_job.rb', line 2

def self.merged_person(kit, loser_email, winner_id, new_lists)
  return if kit.cancelled?
  job = new(kit, {
    :type => "merged_person",
    :loser_email => loser_email,
    :winner_id => winner_id,
    :new_lists => new_lists
  })
  Delayed::Job.enqueue(job, :queue => "mailchimp")
end

Instance Method Details

#initial_syncObject



17
18
19
20
21
22
23
24
# File 'app/models/job/mailchimp_sync_job.rb', line 17

def initial_sync
  list_ids.each do |list_id|
    mailchimp_kit.create_webhooks(list_id)
    mailchimp_kit.sync_mailchimp_to_artfully_update_members(list_id)
    mailchimp_kit.sync_mailchimp_to_artfully_new_members(list_id)
  end
  ProducerMailer.mailchimp_kit_initial_sync_notification(mailchimp_kit, mailchimp_kit.organization.owner, added_list_names, removed_list_names).deliver
end

#kit_cancelledObject



64
65
66
67
68
69
70
71
72
73
# File 'app/models/job/mailchimp_sync_job.rb', line 64

def kit_cancelled
  mailchimp_kit.attached_lists.each do |list|
    mailchimp_kit.destroy_webhooks(list[:list_id])
  end

  mailchimp_kit.organization.people.each do |person|
    person.subscribed_lists = []
    person.save!
  end
end

#list_removalObject



26
27
28
29
# File 'app/models/job/mailchimp_sync_job.rb', line 26

def list_removal
  mailchimp_kit.destroy_webhooks(list_id)
  mailchimp_kit.unsubscribe_old_members(list_id)
end

#merged_personObject



31
32
33
34
# File 'app/models/job/mailchimp_sync_job.rb', line 31

def merged_person
  mailchimp_kit.sync_merged_loser_to_mailchimp(options[:loser_email])
  mailchimp_kit.sync_merged_winner_to_mailchimp(options[:winner_id], options[:new_lists])
end

#performObject



13
14
15
# File 'app/models/job/mailchimp_sync_job.rb', line 13

def perform
  send(options[:type])
end

#person_update_to_mailchimpObject



60
61
62
# File 'app/models/job/mailchimp_sync_job.rb', line 60

def person_update_to_mailchimp
  mailchimp_kit.sync_artfully_person_update(options[:person_id], options[:person_changes])
end

#webhook_campaignObject



56
57
58
# File 'app/models/job/mailchimp_sync_job.rb', line 56

def webhook_campaign
  mailchimp_kit.sync_mailchimp_webhook_campaign_sent(list_id, data)
end

#webhook_cleanedObject



36
37
38
# File 'app/models/job/mailchimp_sync_job.rb', line 36

def webhook_cleaned
  mailchimp_kit.sync_mailchimp_webhook_cleaned(list_id, data)
end

#webhook_profileObject



44
45
46
# File 'app/models/job/mailchimp_sync_job.rb', line 44

def webhook_profile
  mailchimp_kit.sync_mailchimp_webhook_update_person(list_id, data)
end

#webhook_subscribeObject



40
41
42
# File 'app/models/job/mailchimp_sync_job.rb', line 40

def webhook_subscribe
  mailchimp_kit.sync_mailchimp_webhook_new_subscriber(list_id, data)
end

#webhook_unsubscribeObject



52
53
54
# File 'app/models/job/mailchimp_sync_job.rb', line 52

def webhook_unsubscribe
  mailchimp_kit.sync_mailchimp_webhook_member_unsubscribe(list_id, data)
end

#webhook_upemailObject



48
49
50
# File 'app/models/job/mailchimp_sync_job.rb', line 48

def webhook_upemail
  mailchimp_kit.sync_mailchimp_webhook_update_person_email(list_id, data)
end