Skip to content

Instantly share code, notes, and snippets.

@ciscodesign
Created August 3, 2012 14:55
Show Gist options
  • Save ciscodesign/3248383 to your computer and use it in GitHub Desktop.
Save ciscodesign/3248383 to your computer and use it in GitHub Desktop.
a class for connecting to mailchimp, with gibbon gem
# encoding: UTF-8
# this is a class for connecting to mailchimp, with gibbon gem
class NewsletterService
def connect
@u = Gibbon.new(MC_API_KEY)
@u.throws_exceptions = true
@u
end
def subscribe_user(user)
#return true if subscription goes ok, false if not
@new_user.connect
@result = @new_user.list_subscribe(
:id => mailchimp_user_id_list,
:email_address => user.email,
:merge_vars => {
'FNAME' => user.name,
'LNAME' => user.surname
},
:email_type => "html",
:double_optin => false,
:send_welcome => false)
@result ? true : false
end
def unsubscribe_user(user)
#return true if unsubscription goes ok, false if not
@old_user.connect
@result = @old_user.list_unsubscribe(:id => mailchimp_user_id_list, :email_address => user.email, :delete_member => true, :send_goodbye => false, :send_notify => false)
@result ? true : false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment