mailchimp_subscriber 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mailchimp_subscriber.rb +53 -0
- data/mailchimp_subscriber.gemspec +21 -0
- metadata +98 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module MailchimpSubscriber
|
2
|
+
require 'hominid'
|
3
|
+
attr_accessor :api_key, :email, :fields, :content_type, :double_optin, :update_existing, :replace_interests, :send_welcome, :delete_member, :send_goodbye, :send_notify
|
4
|
+
|
5
|
+
def subscribe_to(list_name,options={})
|
6
|
+
after_create do |record|
|
7
|
+
begin
|
8
|
+
subscribe(record,list_name,options)
|
9
|
+
rescue RuntimeError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after_destroy do |record|
|
14
|
+
begin
|
15
|
+
unsubscribe(record,list_name,options)
|
16
|
+
rescue RuntimeError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.connect(mailchimp_api_key)
|
22
|
+
Hominid::API.new(mailchimp_api_key)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_options(record,options)
|
26
|
+
@api_key = options[:using][:api_key]
|
27
|
+
@email = record.send(options[:using][:email])
|
28
|
+
@fields = options[:using][:fields] ? options[:using][:fields].inject({}) { |h, (k, v)| h[k] = record.send(v); h } : {}
|
29
|
+
@content_type = options[:using][:content_type] || 'html'
|
30
|
+
@double_optin = options[:using][:double_optin] || false
|
31
|
+
@update_existing = options[:using][:update_existing] || true
|
32
|
+
@replace_interests = options[:using][:replace_interests] || false
|
33
|
+
@send_welcome = options[:using][:send_welcome] || false
|
34
|
+
@delete_member = options[:using][:delete_member] || true
|
35
|
+
@send_goodbye = options[:using][:send_goodbye] || false
|
36
|
+
@send_notify = options[:using][:send_notify] || false
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.subscribe(record,list_name,options)
|
40
|
+
parse_options(record, options)
|
41
|
+
client = connect(@api_key)
|
42
|
+
list_id = client.find_list_by_name(list_name)['id']
|
43
|
+
client.list_subscribe(list_id, @email, @fields, @content_type, @double_optin, @update_existing, @replace_interests, @send_welcome)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.unsubscribe(record,list_name,options)
|
47
|
+
parse_options(record, options)
|
48
|
+
client = connect(@api_key)
|
49
|
+
list_id = client.find_list_by_name(list_name)["id"]
|
50
|
+
client.list_unsubscribe(list_id, @email, @delete_member, @send_goodbye, @send_notify)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "mailchimp_subscriber"
|
5
|
+
s.version = '0.1.0'
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Brandon Harris"]
|
8
|
+
s.email = ["brandon@brandon-harris.com"]
|
9
|
+
s.homepage = "https://github.com/bbwharris/mailchimp_subscriber"
|
10
|
+
s.summary = %q{Sync user emails with MailChimp mailing lists}
|
11
|
+
s.description = %q{Sync user emails with MailChimp mailing lists}
|
12
|
+
|
13
|
+
s.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_development_dependency 'rails', '>= 3.0.0'
|
18
|
+
s.add_development_dependency 'hominid', '>= 3.2.0'
|
19
|
+
|
20
|
+
ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailchimp_subscriber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brandon Harris
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hominid
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 15
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
version: 3.2.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Sync user emails with MailChimp mailing lists
|
53
|
+
email:
|
54
|
+
- brandon@brandon-harris.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- lib/mailchimp_subscriber.rb
|
63
|
+
- mailchimp_subscriber.gemspec
|
64
|
+
homepage: https://github.com/bbwharris/mailchimp_subscriber
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Sync user emails with MailChimp mailing lists
|
97
|
+
test_files: []
|
98
|
+
|