Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjcarlson committed Oct 29, 2008
1 parent 4be71f0 commit 16487fd
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 0 deletions.
184 changes: 184 additions & 0 deletions acts_as_chimp.tmproj
@@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>currentDocument</key>
<string>lib/chimp_helper.rb</string>
<key>documents</key>
<array>
<dict>
<key>expanded</key>
<true/>
<key>name</key>
<string>acts_as_chimp</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string></string>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
<integer>324</integer>
<key>metaData</key>
<dict>
<key>README</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>253</integer>
<key>line</key>
<integer>7</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>Rakefile</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>0</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>init.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>36</integer>
<key>line</key>
<integer>2</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>install.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>73</integer>
<key>line</key>
<integer>3</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>lib/chimp_helper.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>75</integer>
<key>line</key>
<integer>7</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>lib/mandarin_soda/chimp.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>14</integer>
<key>line</key>
<integer>52</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>mail_chimp.yml.tpl</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>12</integer>
<key>line</key>
<integer>10</integer>
</dict>
<key>columnSelection</key>
<false/>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
<key>selectFrom</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>0</integer>
</dict>
<key>selectTo</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>11</integer>
</dict>
</dict>
<key>tasks/acts_as_chimp_tasks.rake</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>0</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>test/acts_as_chimp_test.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>0</integer>
<key>line</key>
<integer>0</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
</dict>
<key>openDocuments</key>
<array>
<string>init.rb</string>
<string>lib/mandarin_soda/chimp.rb</string>
<string>lib/chimp_helper.rb</string>
<string>install.rb</string>
<string>Rakefile</string>
<string>tasks/acts_as_chimp_tasks.rake</string>
<string>test/acts_as_chimp_test.rb</string>
<string>README</string>
<string>mail_chimp.yml.tpl</string>
</array>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{31, 49}, {1064, 785}}</string>
</dict>
</plist>
Binary file added generators/.DS_Store
Binary file not shown.
77 changes: 77 additions & 0 deletions 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

0 comments on commit 16487fd

Please sign in to comment.