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



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

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



62
63
64
# File 'app/models/job/mailchimp_sync_job.rb', line 62

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

#webhook_campaignObject



58
59
60
# File 'app/models/job/mailchimp_sync_job.rb', line 58

def webhook_campaign
  mailchimp_kit.sync_mailchimp_webhook_campaign_sent(list_id, data)
end

#webhook_cleanedObject

Noop. We don’t respond to this yet.



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

def webhook_cleaned
end

#webhook_profileObject



46
47
48
# File 'app/models/job/mailchimp_sync_job.rb', line 46

def webhook_profile
  mailchimp_kit.sync_mailchimp_webhook_update_person(list_id, data)
end

#webhook_subscribeObject



42
43
44
# File 'app/models/job/mailchimp_sync_job.rb', line 42

def webhook_subscribe
  mailchimp_kit.sync_mailchimp_webhook_new_subscriber(list_id, data)
end

#webhook_unsubscribeObject



54
55
56
# File 'app/models/job/mailchimp_sync_job.rb', line 54

def webhook_unsubscribe
  mailchimp_kit.sync_mailchimp_webhook_member_unsubscribe(list_id, data)
end

#webhook_upemailObject



50
51
52
# File 'app/models/job/mailchimp_sync_job.rb', line 50

def webhook_upemail
  mailchimp_kit.sync_mailchimp_webhook_update_person_email(list_id, data)
end