mcmailer 0.0.1
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/.autotest +25 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +57 -0
- data/Rakefile +17 -0
- data/lib/mcmailer.rb +6 -0
- data/test/test_mcmailer.rb +112 -0
- metadata +127 -0
data/.autotest
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "autotest/restart"
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.testlib = "minitest/unit"
|
7
|
+
#
|
8
|
+
# at.extra_files << "../some/external/dependency.rb"
|
9
|
+
#
|
10
|
+
# at.libs << ":../some/external"
|
11
|
+
#
|
12
|
+
# at.add_exception "vendor"
|
13
|
+
#
|
14
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
15
|
+
# at.files_matching(/test_.*rb$/)
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# %w(TestA TestB).each do |klass|
|
19
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
# Autotest.add_hook :run_command do |at|
|
24
|
+
# system "rake build"
|
25
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= mcmailer
|
2
|
+
|
3
|
+
* https://github.com/jmitchell/mcmailer
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Wrapper around Gibbon gem for Mailchimp
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== DEVELOPERS:
|
26
|
+
|
27
|
+
After checking out the source, run:
|
28
|
+
|
29
|
+
$ rake newb
|
30
|
+
|
31
|
+
This task will install any missing dependencies, run the tests/specs,
|
32
|
+
and generate the RDoc.
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Copyright (c) 2013 Jacob Mitchell
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
+
a copy of this software and associated documentation files (the
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
46
|
+
the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be
|
49
|
+
included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "hoe"
|
5
|
+
|
6
|
+
Hoe.plugin :bundler
|
7
|
+
|
8
|
+
Hoe.spec "mcmailer" do
|
9
|
+
developer("Jacob Mitchell", "jacob.d.mitchell@gmail.com")
|
10
|
+
|
11
|
+
dependency 'uuid', '2.3.5'
|
12
|
+
dependency 'gibbon', '0.3.5'
|
13
|
+
|
14
|
+
license "MIT"
|
15
|
+
end
|
16
|
+
|
17
|
+
# vim: syntax=ruby
|
data/lib/mcmailer.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "mcmailer"
|
3
|
+
require "uuid"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
describe MailchimpClient do
|
7
|
+
MAILCHIMP = YAML.load_file('config/mcmailer.yml')["test"]
|
8
|
+
|
9
|
+
def client
|
10
|
+
@client ||= MailchimpClient.new(MAILCHIMP['api_key'], MAILCHIMP['timeout'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def uuid
|
14
|
+
@uuid ||= UUID.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def random
|
18
|
+
@random ||= Random.new
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
client.use_list(MAILCHIMP['list_name'])
|
23
|
+
client.destroy_all_subscribers!
|
24
|
+
|
25
|
+
client.subscribers.count.must_equal 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can subscribe people to to the mailing list individually" do
|
29
|
+
subscriber_email = 'mailchimp_client_test@unit.test'
|
30
|
+
client.subscribe(subscriber_email, random_field_data)
|
31
|
+
|
32
|
+
client.subscribers.count.must_equal 1
|
33
|
+
client.subscribers.first['email'].must_equal subscriber_email
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can destroy an individual subscription from the mailing list" do
|
37
|
+
subscriber_email = 'mailchimp_client_test@unit.test'
|
38
|
+
client.subscribe(subscriber_email, random_field_data)
|
39
|
+
|
40
|
+
client.subscribers.count.must_equal 1
|
41
|
+
client.subscribers.first['email'].must_equal subscriber_email
|
42
|
+
|
43
|
+
client.destroy!(subscriber_email)
|
44
|
+
|
45
|
+
client.subscribers.count.must_equal 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can subscribe a batch of users" do
|
49
|
+
batch_size = 15
|
50
|
+
subscribers = random_batch(batch_size)
|
51
|
+
client.batch_subscribe(subscribers)
|
52
|
+
|
53
|
+
client.subscribers.count.must_equal batch_size
|
54
|
+
end
|
55
|
+
|
56
|
+
it "has a batch subscription operation that's idempotent" do
|
57
|
+
batch_size = 15
|
58
|
+
subscribers = random_batch(batch_size)
|
59
|
+
5.times do
|
60
|
+
client.batch_subscribe(subscribers)
|
61
|
+
end
|
62
|
+
|
63
|
+
client.subscribers.count.must_equal batch_size
|
64
|
+
end
|
65
|
+
|
66
|
+
it "can destroy a batch of subscriptions" do
|
67
|
+
batch_size = 15
|
68
|
+
subscribers = random_batch(batch_size)
|
69
|
+
client.batch_subscribe(subscribers)
|
70
|
+
|
71
|
+
client.subscribers.count.must_equal batch_size
|
72
|
+
|
73
|
+
unsubscription_batch_size = 13
|
74
|
+
emails = emails_from_batch(subscribers)
|
75
|
+
client.batch_destroy!(emails[0...unsubscription_batch_size])
|
76
|
+
|
77
|
+
client.subscribers.count.must_equal (batch_size - unsubscription_batch_size)
|
78
|
+
end
|
79
|
+
|
80
|
+
def random_batch(count)
|
81
|
+
(1..count).collect do |n|
|
82
|
+
result = random_field_data
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def emails_from_batch(batch)
|
87
|
+
batch.collect {|s| s[:EMAIL]}
|
88
|
+
end
|
89
|
+
|
90
|
+
def random_field_data()
|
91
|
+
data = { :EMAIL => "#{uuid.generate}@unit.test" }
|
92
|
+
fields = MAILCHIMP['required_fields']
|
93
|
+
fields = fields.merge(MAILCHIMP['optional_fields']) if random.rand >= 0.5
|
94
|
+
fields.each_pair do |name,type|
|
95
|
+
data[name.upcase.to_sym] = random_value(type)
|
96
|
+
end
|
97
|
+
data
|
98
|
+
end
|
99
|
+
|
100
|
+
def random_value(type)
|
101
|
+
case type
|
102
|
+
when 'text'
|
103
|
+
'Lorem ipsum'
|
104
|
+
when 'number'
|
105
|
+
random.rand(10)
|
106
|
+
when 'bool'
|
107
|
+
(random.rand >= 0.5) ? 1 : 0
|
108
|
+
else
|
109
|
+
''
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mcmailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacob Mitchell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: uuid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: gibbon
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.3.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hoe
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.6'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.6'
|
78
|
+
description: Wrapper around Gibbon gem for Mailchimp
|
79
|
+
email:
|
80
|
+
- jacob.d.mitchell@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- History.txt
|
85
|
+
- Manifest.txt
|
86
|
+
- README.txt
|
87
|
+
files:
|
88
|
+
- .autotest
|
89
|
+
- History.txt
|
90
|
+
- Manifest.txt
|
91
|
+
- README.txt
|
92
|
+
- Rakefile
|
93
|
+
- lib/mcmailer.rb
|
94
|
+
- test/test_mcmailer.rb
|
95
|
+
- .gemtest
|
96
|
+
homepage: https://github.com/jmitchell/mcmailer
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --main
|
102
|
+
- README.txt
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: -99083887662033116
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project: mcmailer
|
122
|
+
rubygems_version: 1.8.24
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Wrapper around Gibbon gem for Mailchimp
|
126
|
+
test_files:
|
127
|
+
- test/test_mcmailer.rb
|