diff --git a/acts_as_chimp.tmproj b/acts_as_chimp.tmproj new file mode 100644 index 0000000..b911b00 --- /dev/null +++ b/acts_as_chimp.tmproj @@ -0,0 +1,184 @@ + + + + + currentDocument + lib/chimp_helper.rb + documents + + + expanded + + name + acts_as_chimp + regexFolderFilter + !.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$ + sourceDirectory + + + + fileHierarchyDrawerWidth + 324 + metaData + + README + + caret + + column + 253 + line + 7 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + Rakefile + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + init.rb + + caret + + column + 36 + line + 2 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + install.rb + + caret + + column + 73 + line + 3 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + lib/chimp_helper.rb + + caret + + column + 75 + line + 7 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + lib/mandarin_soda/chimp.rb + + caret + + column + 14 + line + 52 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + mail_chimp.yml.tpl + + caret + + column + 12 + line + 10 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 0 + line + 0 + + selectTo + + column + 0 + line + 11 + + + tasks/acts_as_chimp_tasks.rake + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + test/acts_as_chimp_test.rb + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + + openDocuments + + init.rb + lib/mandarin_soda/chimp.rb + lib/chimp_helper.rb + install.rb + Rakefile + tasks/acts_as_chimp_tasks.rake + test/acts_as_chimp_test.rb + README + mail_chimp.yml.tpl + + showFileHierarchyDrawer + + windowFrame + {{31, 49}, {1064, 785}} + + diff --git a/generators/.DS_Store b/generators/.DS_Store new file mode 100644 index 0000000..73a9048 Binary files /dev/null and b/generators/.DS_Store differ diff --git a/lib/mandarin_soda/chimp_campaign.rb b/lib/mandarin_soda/chimp_campaign.rb new file mode 100644 index 0000000..f2eddaa --- /dev/null +++ b/lib/mandarin_soda/chimp_campaign.rb @@ -0,0 +1,77 @@ +require 'xmlrpc/client' +module MandarinSoda + module ChimpCampaign + class ChimpConfigError < StandardError; end + class ChimpConnectError < StandardError; end + + def self.included(base) + base.extend ActMethods + mattr_reader :chimp_config + begin + @@chimp_config_path = (RAILS_ROOT + '/config/mail_chimp.yml') + @@chimp_config = YAML.load_file(@@chimp_config_path)[RAILS_ENV].symbolize_keys + end + end + + module ActMethods + def acts_as_chimp_campaign(options = {}) + unless included_modules.include? InstanceMethods + class_inheritable_accessor :options + extend ClassMethods + include InstanceMethods + end + self.options = options + end + + end + + module ClassMethods + end + + module InstanceMethods + def create_campaign + auth ||= chimp_login(chimp_config[:username], chimp_config[:password]) + end + + def update_campaign + auth ||= chimp_login(chimp_config[:username], chimp_config[:password]) + end + + def resume_campaign + auth ||= chimp_login(chimp_config[:username], chimp_config[:password]) + end + + def search_campaigns + auth ||= chimp_login(chimp_config[:username], chimp_config[:password]) + end + + private + CHIMP_URL = "http://api.mailchimp.com/1.1/" + def chimp_login(user, password) + chimp_api ||= XMLRPC::Client.new2(CHIMP_URL) + chimp_api.call("login", user, password) + end + + def chimp_subscribe(auth, mailing_list_id, email, merge_vars, email_content_type="html", double_optin=true) + begin + chimp_api ||= XMLRPC::Client.new2(CHIMP_URL) + chimp_api.call("listSubscribe", auth, mailing_list_id, email, merge_vars, email_content_type, double_optin) + rescue XMLRPC::FaultException => e + puts e.faultCode + puts e.faultString + end + end + + def chimp_remove(auth, mailing_list_id, email, delete_user=false, send_goodbye=true, send_notify=true) + chimp_api ||= XMLRPC::Client.new2(CHIMP_URL) + chimp_api.call("listUnsubscribe", auth, mailing_list_id, email, delete_user, send_goodbye, send_notify) + end + + def chimp_info(auth, mailing_list_id, email) + chimp_api ||= XMLRPC::Client.new2(CHIMP_URL) + chimp_api.call("listMemberInfo", auth, mailing_list_id, email) + end + + end + end +end