ruby-mailchimp 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mail_chimp.rb +88 -31
- metadata +45 -38
data/lib/mail_chimp.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/imap'
|
3
3
|
require 'rubygems'
|
4
|
+
require 'xmlrpc/client'
|
4
5
|
gem 'actionmailer'
|
5
6
|
require 'action_mailer'
|
6
7
|
|
@@ -10,45 +11,101 @@ require 'action_mailer'
|
|
10
11
|
# ruby-mailchimp is designed to allow you to use Ruby to subscribe or unsubscribe
|
11
12
|
# users to an existing MailChimp (http://www.mailchimp.com) account. You will need the following:
|
12
13
|
# - MailChimp Account: MailChimp is free to sign up for and only charges for sent messages
|
13
|
-
# - MailChimp List ID: You can get this from the id field of MailChimp's signup form code.
|
14
14
|
#
|
15
|
+
# The API is basically a wrapper on MailChimp's XML-RPC API. For more details on what variables
|
16
|
+
# mean, you can reference their API specification at: http://www.mailchimp.com/api/.
|
17
|
+
#
|
18
|
+
# I'm leaving the subscribe/unsubscribe mail processor code in for now, but it is deprecated and
|
19
|
+
# will be removed in a future release. The ability to query MailChimp using their XML-RPC API
|
20
|
+
# has eliminated the need to process mails to keep the lists in sync.
|
21
|
+
#
|
15
22
|
# Author:: C. G. Brown (mailto: cgbrown@projectlocker.com)
|
16
|
-
# Copyright:: Copyright (c) 2007 One Percent Software/ProjectLocker
|
23
|
+
# Copyright:: Copyright (c) 2007-8 One Percent Software/ProjectLocker
|
17
24
|
# License:: Apache Software License
|
18
25
|
#
|
19
26
|
# Example Usage:
|
20
|
-
# -
|
21
|
-
# bonobo = MailChimp.new
|
22
|
-
# bonobo.subscribe_user("MyListID", "testuser@nowhere.com")
|
23
|
-
#
|
24
|
-
# - Subscribing a User with other data: -
|
25
|
-
# bonobo = MailChimp.new
|
26
|
-
# bonobo.subscribe_user("MyListID", "otheruser@nowhere.com", {:FNAME=>'Barnaby', :LNAME=>'Jones'})
|
27
|
-
#
|
28
|
-
# - Unsubscribing a User -
|
27
|
+
# - Logging In (required before all other functions): -
|
29
28
|
# bonobo = MailChimp.new
|
30
|
-
# bonobo.
|
31
|
-
#
|
32
|
-
# -
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# ip = unsubscriber[:ip]
|
45
|
-
# signup_date = unsubscriber[:date]
|
46
|
-
# #Do what you like with the data here
|
47
|
-
# end
|
48
|
-
#
|
29
|
+
# uid = bonobo.login("MailChimpUsername", "MailChimpPassword")
|
30
|
+
#
|
31
|
+
# - Obtaining a List ID -
|
32
|
+
# list_id = bonobo.getListByName(uid, "My List on MailChimp")
|
33
|
+
#
|
34
|
+
# - Subscribing a User: -
|
35
|
+
# bonobo.listSubscribe(uid, list_id, "testuser@nowhere.com", {})
|
36
|
+
#
|
37
|
+
# - Subscribing a User with Merge Data: -
|
38
|
+
# bonobo.listSubscribe(uid, list_id, "testuser@nowhere.com", {"FNAME"=>'Barnaby', "LNAME"=>'Jones'})
|
39
|
+
#
|
40
|
+
# - Unsubscribing a User: -
|
41
|
+
# bonobo.listUnsubscribe(uid, list_id, "testuser@nowhere.com")
|
42
|
+
#
|
49
43
|
class MailChimp
|
50
44
|
|
51
|
-
attr_accessor :email_server, :email_user, :email_password
|
45
|
+
attr_accessor :email_server, :email_user, :email_password, :client
|
46
|
+
|
47
|
+
def login(username, password)
|
48
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
49
|
+
client.call("login", username, password)
|
50
|
+
end
|
51
|
+
|
52
|
+
def lists(uid)
|
53
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
54
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
55
|
+
client.call("lists", uid)
|
56
|
+
end
|
57
|
+
|
58
|
+
def getListByName(uid, listname)
|
59
|
+
listinfo = lists(uid)
|
60
|
+
listhash = {}
|
61
|
+
listinfo.each {|list|
|
62
|
+
listhash_key = list["name"]
|
63
|
+
listhash[listhash_key] = list
|
64
|
+
}
|
65
|
+
return list[listname]
|
66
|
+
end
|
67
|
+
|
68
|
+
def listMergeVars(uid, list_id)
|
69
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
70
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
71
|
+
client.call("listMergeVars", uid, list_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def listInterestGroups(uid, list_id)
|
75
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
76
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
77
|
+
client.call("listInterestGroups", uid, list_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def listSubscribe(uid, list_id, email, merge_vars, email_type="html", double_optin=true)
|
81
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
82
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
83
|
+
client.call("listSubscribe", uid, list_id, email, merge_vars, email_type, double_optin)
|
84
|
+
end
|
85
|
+
|
86
|
+
def listUnsubscribe(uid, list_id, email, delete_member=false, send_goodbye=true, send_notify=true)
|
87
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
88
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
89
|
+
client.call("listUnsubscribe", uid, list_id, email, delete_member, send_goodbye, send_notify)
|
90
|
+
end
|
91
|
+
|
92
|
+
def listUpdateMember(uid, list_id, email, merge_vars, email_type, replace_interests=true)
|
93
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
94
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
95
|
+
client.call("listUpdateMember", uid, list_id, email, merge_vars, email_type, replace_interests)
|
96
|
+
end
|
97
|
+
|
98
|
+
def listMembers(uid, list_id, status)
|
99
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
100
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
101
|
+
client.call("listMembers", uid, list_id, status)
|
102
|
+
end
|
103
|
+
|
104
|
+
def listMemberInfo(uid, list_id, email)
|
105
|
+
raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?)
|
106
|
+
client = XMLRPC::Client.new2("http://www.mailchimp.com/admin/api/1.0/index.phtml") if client.nil?
|
107
|
+
client.call("listMemberInfo", uid, list_id, email)
|
108
|
+
end
|
52
109
|
|
53
110
|
#
|
54
111
|
# Stores the inbox attributes to allow connection by check_inbox
|
metadata
CHANGED
@@ -1,54 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: ruby-mailchimp
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-11-27 00:00:00 -05:00
|
8
|
-
summary: Allows programmatic subscription and unsubscription to MailChimp. Requires MailChimp account.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: cgbrown@projectlocker.com
|
12
|
-
homepage: http://www.projectlocker.com
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: mail_chimp
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.3.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- C. G. Brown
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
rdoc_options: []
|
36
|
-
|
37
|
-
extra_rdoc_files: []
|
38
|
-
|
39
|
-
executables: []
|
40
|
-
|
41
|
-
extensions: []
|
42
|
-
|
43
|
-
requirements: []
|
8
|
+
autorequire: mail_chimp
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
44
11
|
|
12
|
+
date: 2008-02-11 00:00:00 -05:00
|
13
|
+
default_executable:
|
45
14
|
dependencies:
|
46
15
|
- !ruby/object:Gem::Dependency
|
47
16
|
name: actionmailer
|
48
17
|
version_requirement:
|
49
|
-
version_requirements: !ruby/object:Gem::
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
19
|
requirements:
|
51
20
|
- - ">="
|
52
21
|
- !ruby/object:Gem::Version
|
53
22
|
version: 1.3.2
|
54
23
|
version:
|
24
|
+
description:
|
25
|
+
email: cgbrown@projectlocker.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- lib/mail_chimp.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://www.projectlocker.com
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 0.9.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: Allows programmatic subscription and unsubscription to MailChimp. Requires MailChimp account.
|
60
|
+
test_files: []
|
61
|
+
|