- CLASS IntegrationProvider::Mailchimp::MailchimpConnectionTimeoutError
- CLASS IntegrationProvider::Mailchimp::MailchimpError
- CLASS IntegrationProvider::Mailchimp::SyncListDirector
- A
- C
- E
- G
- L
- M
- N
- R
- S
- U
- V
Attributes
| [R] | errors | |
| [R] | integration | |
| [R] | lists |
Class Public methods
member_list_sync(member) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 127 def self.member_list_sync(member) integration = member.site.integrations.mailchimp.first return false if new(integration).api_key_inactive? if member.status != "awaiting_approval" director = SyncListDirector.new(member: member, integration: integration) director.add_lists.each do |list_id| MailchimpJob.perform_later( method: "subscribe", integration: integration, member: member, list_id: list_id ) end director.remove_lists.each do |list_id| MailchimpJob.perform_later( method: "unsubscribe", integration: integration, member: member, email: member.email, list_id: list_id ) end end end
new(integration) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 5 def initialize(integration) @integration = integration @errors = nil end
remove_from_all_lists(email, site_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 156 def self.remove_from_all_lists(email, site_id) integration = DB::Integration.mailchimp.find_by(site_id: site_id) return false if new(integration).api_key_inactive? lists = [] config = integration.configuration lists << config["default_list_id"] if config["default_list_id"].present? if config["plan_to_list"].present? config["plan_to_list"].each do |p2l| lists << p2l["list_id"] end end lists.each do |list_id| MailchimpJob.perform_later( method: "unsubscribe", integration: integration, email: email, list_id: list_id ) end end
Instance Public methods
api_key_inactive?() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 115 def api_key_inactive? if integration.blank? @errors = "Your Mailchimp API key is not configured" true elsif integration.authentication_inactive? @errors = "Your Mailchimp API key has been marked as inactive or disabled" true else false end end
connected?() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 10 def connected? api_key.size > 5 end
email_on_list?(email, list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 39 def email_on_list?(email, list_id) return false if api_key_inactive? response = connect { connection.get("/3.0/lists/#{list_id}/members/#{Digest::MD5.hexdigest(email)}") } response.status == 200 end
get_lists() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 23 def get_lists return false if api_key_inactive? @lists = get_lists_data true rescue Faraday::ConnectionFailed => e @errors = "Failed to connect to Mailchimp: #{e}. Please try again later." false end
list_details(list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 32 def list_details(list_id) return false if api_key_inactive? response = connect { connection.get("/3.0/lists/#{list_id}") } manage_response(response) end
list_members(list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 79 def list_members(list_id) return false if api_key_inactive? response = connection.get("/3.0/lists/#{list_id}?fields=member.email_address") data = JSON.parse response.body data["members"] end
subscribe(user, list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 48 def subscribe(user, list_id) return false if api_key_inactive? params = {"email_address" => user.email, "status" => "subscribed", "merge_fields" => {"FNAME" => user.first_name, "LNAME" => user.last_name}} response = connect { connection.post("/3.0/lists/#{list_id}/members") do |req| req.body = JSON.generate(params) end } manage_response(response) end
unsubscribe(user, list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 63 def unsubscribe(user, list_id) return false if api_key_inactive? unsubscribe_by_email(user.email, list_id) end
unsubscribe_by_email(email, list_id) Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 69 def unsubscribe_by_email(email, list_id) return false if api_key_inactive? subscriber_hash = Digest::MD5.hexdigest(email) response = connect { connection.delete("/3.0/lists/#{list_id}/members/#{subscriber_hash}") } if response.status >= 500 raise MailchimpError, "Unable to unsubscribe #{email} from mailchimp list #{list_id}" end end
valid?() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 14 def valid? if integration.configuration["plan_to_list"] alter_plan_to_list has_api_key? && plan_to_list_valid? else has_api_key? end end
view_all_plans() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 93 def view_all_plans @view_all_plans ||= [ ["No plan selected...", nil] ] + integration.site.plans.map { |p| [p.name, p.id] } end
view_lists() Link
Source: show
# File app/lib/integration_provider/mailchimp.rb, line 99 def view_lists if has_api_key? unless @errors @view_lists ||= [ ["No list selected...", nil] ] + @lists.map { |list| [list["name"], list["id"]] } end else [] end end