madmimi-james2m 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg
2
+ *.gem
3
+ tags
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Nicholas Young <nicholas@madmimi.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ = madmimi
2
+
3
+ The power of Mad Mimi in your Ruby application. Deliver emails, track statistics, and manage your subscriber base with ease.
4
+
5
+ == Installation
6
+
7
+ gem install madmimi - or if you prefer to live on the edge, just clone this repository and build it from scratch.
8
+
9
+ == Basic Usage
10
+
11
+ Dependencies:
12
+ active_support (I intend to remove this in the not too distant future, and build my own implementation.)
13
+
14
+ mimi = MadMimi.new('emailaddress', 'api_key')
15
+
16
+ mimi.lists -> get all of your Mad Mimi lists returned as a hash
17
+
18
+ mimi.memberships('email') -> returns a hash of the lists that specific email address is subscribed to
19
+
20
+ mimi.new_list('New list name') -> make a new list
21
+
22
+ mimi.delete_list('New list name') -> delete the list I just created
23
+
24
+ mimi.csv_import("name,email\ndave,dave@example.com\n") -> import from a csv string
25
+
26
+ mimi.add_to_list('dave@example.com', 'Test List') -> add this email address to a specific list
27
+
28
+ mimi.remove_from_list('dave@example.com', 'Test List') -> remove this email address from a specific list
29
+
30
+ mimi.suppressed_since('unix timestamp') -> get a TXT of all addresses that were suppressed since this timestamp
31
+
32
+ mimi.promotions -> returns a hash of your promotions
33
+
34
+ mimi.mailing_stats('promotion_id', 'mailing_id') -> get stats on a specific mailing
35
+
36
+ == Sending E-Mail (using the Mailer API)
37
+
38
+ === Replacing keys in your email body text:
39
+
40
+ options = { 'promotion_name' => 'Test Promotion', 'recipients' => 'Nicholas Young <nicholas@madmimi.com>', 'from' => 'MadMimi Ruby <rubygem@madmimi.com>', 'subject' => 'Test Subject' }
41
+
42
+ yaml_body = { 'greeting' => 'Hello', 'name' => 'Nicholas' }
43
+
44
+ mimi.send_mail(options, yaml_body)
45
+
46
+ === Sending Raw HTML (presumably generated by your app)
47
+
48
+ options = { 'promotion_name' => 'Test Promotion', 'recipients' => 'Nicholas Young <nicholas@madmimi.com>', 'from' => 'MadMimi Ruby <rubygem@madmimi.com>', 'subject' => 'Test Subject' }
49
+
50
+ raw_html = "<html><head><title>My great promotion!</title></head><body>Body stuff[[tracking_beacon]]</body></html>"
51
+
52
+ mimi.send_html(options, raw_html)
53
+
54
+ === Sending Plain Text
55
+
56
+ options = { 'promotion_name' => 'Test Promotion', 'recipients' => 'Nicholas Young <nicholas@madmimi.com>', 'from' => 'MadMimi Ruby <rubygem@madmimi.com>', 'subject' => 'Test Subject' }
57
+
58
+ plain_text = "Plain text email contents [[unsubscribe]]"
59
+
60
+ mimi.send_plaintext(options, plain_text)
61
+
62
+ === Return values
63
+
64
+ In most cases, a return value of a single space indicates success.
65
+
66
+ On success, #send_mail, #send_html, and #send_plaintext return String with a numeric mailing_id. This mailing_id can be used to look up stats with #mailing_stats.
67
+
68
+ Errors or issues preventing operation completing return a human-readable String.
69
+
70
+ Therefore, if the return value is not a space, or is not a numeric String value, then
71
+ there is probably an error or uncompleted operation.
72
+
73
+ === Specific options keys
74
+
75
+ 'raw_html': Must include at least one of the [[tracking_beacon]] or [[peek_image]] tags.
76
+
77
+ 'promotion_name': If a promotion doesn't exist under the given name, it will be created.
78
+ If it exists and you specify raw_html, the promotion body will be replaced.
79
+
80
+ 'list_name': For all of the #send methods, if 'list_name' is provided, the recipients
81
+ will be those for an already-existing "audience."
82
+
83
+ == Note on Patches/Pull Requests
84
+
85
+ * Fork the project.
86
+ * Make your feature addition or bug fix.
87
+ * Add tests for it. This is important so I don't break it in a
88
+ future version unintentionally.
89
+ * Commit, do not mess with rakefile, version, or history.
90
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
91
+ * Send me a pull request. Bonus points for topic branches.
92
+
93
+ == Contributors
94
+ tuker
95
+
96
+ == Copyright
97
+
98
+ Copyright (c) 2010 Nicholas Young. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "madmimi"
8
+ gem.summary = %Q{Mad Mimi API wrapper for Ruby}
9
+ gem.description = %Q{Send emails, track statistics, and manage your subscriber base with ease.}
10
+ gem.email = "nicholas@madmimi.com"
11
+ gem.homepage = "http://github.com/madmimi/madmimi-gem"
12
+ gem.authors = ["Nicholas Young", "Marc Heiligers"]
13
+ gem.add_dependency "crack", "0.1.7"
14
+ gem.add_development_dependency "jeweler", "1.4.0"
15
+ gem.add_development_dependency "fakeweb", "1.2.8"
16
+ gem.add_development_dependency "shoulda", "2.10.3"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "madmimi #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.13
@@ -0,0 +1,224 @@
1
+ # Mad Mimi for Ruby
2
+
3
+ # License
4
+
5
+ # Copyright (c) 2010 Mad Mimi (nicholas@madmimi.com)
6
+
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+
17
+ # Except as contained in this notice, the name(s) of the above copyright holder(s)
18
+ # shall not be used in advertising or otherwise to promote the sale, use or other
19
+ # dealings in this Software without prior written authorization.
20
+
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ # THE SOFTWARE.
28
+
29
+ require 'uri'
30
+ require 'net/http'
31
+ require 'net/https'
32
+ require 'crack'
33
+ require 'csv'
34
+
35
+ class MadMimi
36
+
37
+ class MadMimiError < StandardError; end
38
+
39
+ BASE_URL = 'api.madmimi.com'
40
+ NEW_LISTS_PATH = '/audience_lists'
41
+ AUDIENCE_MEMBERS_PATH = '/audience_members'
42
+ AUDIENCE_LISTS_PATH = '/audience_lists/lists.xml'
43
+ MEMBERSHIPS_PATH = '/audience_members/%email%/lists.xml'
44
+ SUPPRESSED_SINCE_PATH = '/audience_members/suppressed_since/%timestamp%.txt'
45
+ SUPPRESS_USER_PATH = ' /audience_members/%email%/suppress_email'
46
+ PROMOTIONS_PATH = '/promotions.xml'
47
+ MAILING_STATS_PATH = '/promotions/%promotion_id%/mailings/%mailing_id%.xml'
48
+ SEARCH_PATH = '/audience_members/search.xml'
49
+ MAILER_PATH = '/mailer'
50
+ MAILER_TO_LIST_PATH = '/mailer/to_list'
51
+
52
+ attr_reader :response
53
+
54
+ def initialize(username, api_key, options = {})
55
+ @api_settings = options.merge({ :username => username, :api_key => api_key })
56
+ end
57
+
58
+ def raise_exceptions
59
+ @api_settings[:raise_exceptions]
60
+ end
61
+
62
+ def username
63
+ @api_settings[:username]
64
+ end
65
+
66
+ def api_key
67
+ @api_settings[:api_key]
68
+ end
69
+
70
+ def default_opt
71
+ { :username => username, :api_key => api_key }
72
+ end
73
+
74
+ def lists
75
+ request = do_request(AUDIENCE_LISTS_PATH, :get)
76
+ Crack::XML.parse(request)
77
+ end
78
+
79
+ def memberships(email)
80
+ request = do_request(MEMBERSHIPS_PATH.gsub('%email%', email), :get)
81
+ Crack::XML.parse(request)
82
+ end
83
+
84
+ def new_list(list_name)
85
+ do_request(NEW_LISTS_PATH, :post, :name => list_name)
86
+ end
87
+
88
+ def delete_list(list_name)
89
+ do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}", :post, :'_method' => 'delete')
90
+ end
91
+
92
+ def csv_import(csv_string)
93
+ do_request(AUDIENCE_MEMBERS_PATH, :post, :csv_file => csv_string)
94
+ end
95
+
96
+ def add_user(options)
97
+ csv_data = build_csv(options)
98
+ do_request(AUDIENCE_MEMBERS_PATH, :post, :csv_file => csv_data)
99
+ end
100
+
101
+ def add_to_list(email, list_name)
102
+ do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}/add", :post, :email => email)
103
+ end
104
+
105
+ def remove_from_list(email, list_name)
106
+ do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}/remove", :post, :email => email)
107
+ end
108
+
109
+ def suppressed_since(timestamp)
110
+ do_request(SUPPRESSED_SINCE_PATH.gsub('%timestamp%', timestamp), :get)
111
+ end
112
+
113
+ def suppress_email(email)
114
+ do_request(SUPPRESS_USER_PATH.gsub('%email%', email), :post)
115
+ end
116
+
117
+ def promotions
118
+ request = do_request(PROMOTIONS_PATH, :get)
119
+ Crack::XML.parse(request)
120
+ end
121
+
122
+ def mailing_stats(promotion_id, mailing_id)
123
+ path = MAILING_STATS_PATH.gsub('%promotion_id%', promotion_id).gsub('%mailing_id%', mailing_id)
124
+ request = do_request(path, :get)
125
+ Crack::XML.parse(request)
126
+ end
127
+
128
+ def audience_search(query_string, raw = false)
129
+ request = do_request(SEARCH_PATH, :get, :raw => raw, :query => query_string)
130
+ Crack::XML.parse(request)
131
+ end
132
+
133
+ def send_mail(opt, yaml_body)
134
+ options = opt.dup
135
+ options[:body] = yaml_body.to_yaml
136
+ if !options[:list_name].nil?
137
+ do_request(MAILER_TO_LIST_PATH, :post, options, true)
138
+ else
139
+ do_request(MAILER_PATH, :post, options, true)
140
+ end
141
+ end
142
+
143
+ # Not the most elegant, but it works for now. :)
144
+ def add_users_to_list(list_name, arr)
145
+ arr.each do |a|
146
+ a[:add_list] = list_name
147
+ add_user(a)
148
+ end
149
+ end
150
+
151
+ def send_html(opt, html)
152
+ options = opt.dup
153
+ if html.include?('[[tracking_beacon]]') || html.include?('[[peek_image]]')
154
+ options[:raw_html] = html
155
+ if !options[:list_name].nil?
156
+ unless html.include?('[[unsubscribe]]') || html.include?('[[opt_out]]')
157
+ raise MadMimiError, "When specifying list_name, include the [[unsubscribe]] or [[opt_out]] macro in your HTML before sending."
158
+ end
159
+ do_request(MAILER_TO_LIST_PATH, :post, options, true)
160
+ else
161
+ do_request(MAILER_PATH, :post, options, true)
162
+ end
163
+ else
164
+ raise MadMimiError, "You'll need to include either the [[tracking_beacon]] or [[peek_image]] macro in your HTML before sending."
165
+ end
166
+ end
167
+
168
+ def send_plaintext(opt, plaintext)
169
+ options = opt.dup
170
+ options[:raw_plain_text] = plaintext
171
+ if !options[:list_name].nil?
172
+ if plaintext.include?('[[unsubscribe]]') || plaintext.include?('[[opt_out]]')
173
+ do_request(MAILER_TO_LIST_PATH, :post, options, true)
174
+ else
175
+ raise MadMimiError, "You'll need to include either the [[unsubscribe]] or [[opt_out]] macro in your text before sending."
176
+ end
177
+ else
178
+ do_request(MAILER_PATH, :post, options, true)
179
+ end
180
+ end
181
+
182
+ private
183
+
184
+ # Refactor this method asap
185
+ def do_request(path, req_type = :get, options = {}, transactional = false)
186
+ options = options.merge(default_opt)
187
+ form_data = options.inject({}) { |m, (k, v)| m[k.to_s] = v; m }
188
+
189
+ if transactional == true
190
+ http = Net::HTTP.new(BASE_URL, 443)
191
+ http.use_ssl = true
192
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
193
+ else
194
+ http = Net::HTTP.new(BASE_URL, 80)
195
+ end
196
+
197
+ @response = http.start do |http|
198
+ # Either Net::HTTP::Get or Net::HTTP::Post
199
+ http_class = Net::HTTP.const_get(req_type.to_s.camelcase)
200
+ req = http_class.new(path)
201
+ req.set_form_data(form_data)
202
+ http.request(req)
203
+ end
204
+
205
+ @response.value if raise_exceptions
206
+
207
+ @response.body.strip
208
+
209
+ end
210
+
211
+ def build_csv(hash)
212
+ if CSV.respond_to?(:generate_row) # before Ruby 1.9
213
+ buffer = ''
214
+ CSV.generate_row(hash.keys, hash.keys.size, buffer)
215
+ CSV.generate_row(hash.values, hash.values.size, buffer)
216
+ buffer
217
+ else # Ruby 1.9 and after
218
+ CSV.generate do |csv|
219
+ csv << hash.keys
220
+ csv << hash.values
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{madmimi-james2m}
8
+ s.version = "1.0.13"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nicholas Young", "Marc Heiligers", 'James McCarthy']
12
+ s.date = %q{2010-07-21}
13
+ s.description = %q{Send emails, track statistics, and manage your subscriber base with ease.}
14
+ s.email = %q{nicholas@madmimi.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/madmimi.rb",
26
+ "madmimi.gemspec",
27
+ "test/fixtures/lists.xml",
28
+ "test/fixtures/promotions.xml",
29
+ "test/fixtures/search.xml",
30
+ "test/helper.rb",
31
+ "test/test_madmimi.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/madmimi/madmimi-gem}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Mad Mimi API wrapper for Ruby}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/test_madmimi.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<crack>, ["= 0.1.7"])
49
+ s.add_development_dependency(%q<jeweler>, ["= 1.4.0"])
50
+ s.add_development_dependency(%q<fakeweb>, ["= 1.2.8"])
51
+ s.add_development_dependency(%q<shoulda>, ["= 2.10.3"])
52
+ else
53
+ s.add_dependency(%q<crack>, ["= 0.1.7"])
54
+ s.add_dependency(%q<jeweler>, ["= 1.4.0"])
55
+ s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
56
+ s.add_dependency(%q<shoulda>, ["= 2.10.3"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<crack>, ["= 0.1.7"])
60
+ s.add_dependency(%q<jeweler>, ["= 1.4.0"])
61
+ s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
62
+ s.add_dependency(%q<shoulda>, ["= 2.10.3"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,7 @@
1
+ <lists>
2
+ <list subscriber_count="0" name="Funky List" id="90920"/>
3
+ <list subscriber_count="0" name="New Test" id="90913"/>
4
+ <list subscriber_count="0" name="New Test List" id="93852"/>
5
+ <list subscriber_count="0" name="Other test" id="89621"/>
6
+ <list subscriber_count="0" name="Test List" id="88803"/>
7
+ </lists>
@@ -0,0 +1,10 @@
1
+ <promotions>
2
+ <promotion updated_at="Mon May 24 19:58:02 -0400 2010" mimio="1bee3" name="HTML Test" id="257713">
3
+ </promotion>
4
+ <promotion updated_at="Mon May 24 13:20:14 -0400 2010" mimio="69ce3" name="Untitled Promotion" id="257174">
5
+ <mailing id="1274713">
6
+ <started_send>Mon May 24 13:20:03 -0400 2010</started_send>
7
+ <finished_send>Mon May 24 13:20:06 -0400 2010</finished_send>
8
+ </mailing>
9
+ </promotion>
10
+ </promotions>
@@ -0,0 +1,38 @@
1
+ <audience>
2
+ <member suppressed="false">
3
+ <first_name></first_name>
4
+ <last_name></last_name>
5
+ <email>nicholas@madmimi.com</email>
6
+ <created_at>Mon May 24 13:19:59 -0400 2010</created_at>
7
+ <city></city>
8
+ <phone></phone>
9
+ <company></company>
10
+ <title></title>
11
+ <address></address>
12
+ <state></state>
13
+ <zip></zip>
14
+ <country></country>
15
+ <confirmed></confirmed>
16
+ <music></music>
17
+ <lists>
18
+ </lists>
19
+ </member>
20
+ <member suppressed="false">
21
+ <first_name></first_name>
22
+ <last_name></last_name>
23
+ <email>nicholas@nicholaswyoung.com</email>
24
+ <created_at>Mon May 24 20:17:30 -0400 2010</created_at>
25
+ <city></city>
26
+ <phone></phone>
27
+ <company></company>
28
+ <title></title>
29
+ <address></address>
30
+ <state></state>
31
+ <zip></zip>
32
+ <country></country>
33
+ <confirmed></confirmed>
34
+ <music></music>
35
+ <lists>
36
+ </lists>
37
+ </member>
38
+ </audience>
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'madmimi'
9
+
10
+ class Test::Unit::TestCase
11
+ end
12
+
13
+ def fixture_file(filename)
14
+ return '' if filename == ''
15
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
16
+ File.read(file_path)
17
+ end
18
+
19
+ def madmimi_url(url, https = false)
20
+ if https = false
21
+ url =~ /^http/ ? url : "http://api.madmimi.com#{url}"
22
+ else
23
+ url =~ /^https/ ? url : "https://api.madmimi.com#{url}"
24
+ end
25
+ end
26
+
27
+ def stub_get(url, filename, status = nil)
28
+ options = { :body => fixture_file(filename) }
29
+ options.merge!({ :status => status }) unless status.nil?
30
+ FakeWeb.register_uri(:get, madmimi_url(url), options)
31
+ end
32
+
33
+ # In the process of tweaking this. - Nicholas
34
+ def stub_post(url, filename = nil, status = nil)
35
+ options = { :body => "" }
36
+ options.merge!({ :status => status }) unless status.nil?
37
+ FakeWeb.register_url(:get, madmimi_url(url), options)
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ class TestMadmimi < Test::Unit::TestCase
4
+ context "A API call" do
5
+ setup do
6
+ @mimi = MadMimi.new('email@example.com', 'testapikey')
7
+ end
8
+
9
+ should "retrieve a hash of promotions" do
10
+ stub_get('/promotions.xml', 'promotions.xml')
11
+ response = @mimi.promotions
12
+ flunk "I couldn't find any promotions." unless response.kind_of?(Hash) || !response.empty?
13
+ end
14
+
15
+ should "retrieve a hash of lists" do
16
+ stub_get('/audience_lists/lists.xml', 'lists.xml')
17
+ response = @mimi.lists
18
+ flunk "Doesn't return any lists." unless response.kind_of?(Hash) || !response.empty?
19
+ end
20
+
21
+ should "retrieve a hash of users found with the search term nicholas" do
22
+ stub_get('/audience_members/search.xml?query=nicholas', 'search.xml')
23
+ response = @mimi.audience_search('nicholas')
24
+ flunk "No users found." unless response.kind_of?(Hash) || !response.empty?
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: madmimi-james2m
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 13
9
+ version: 1.0.13
10
+ platform: ruby
11
+ authors:
12
+ - Nicholas Young
13
+ - Marc Heiligers
14
+ - James McCarthy
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-07-21 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: crack
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ - 1
32
+ - 7
33
+ version: 0.1.7
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 4
46
+ - 0
47
+ version: 1.4.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: fakeweb
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 2
60
+ - 8
61
+ version: 1.2.8
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: shoulda
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 2
73
+ - 10
74
+ - 3
75
+ version: 2.10.3
76
+ type: :development
77
+ version_requirements: *id004
78
+ description: Send emails, track statistics, and manage your subscriber base with ease.
79
+ email: nicholas@madmimi.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files:
85
+ - LICENSE
86
+ - README.rdoc
87
+ files:
88
+ - .gitignore
89
+ - LICENSE
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/madmimi.rb
94
+ - madmimi.gemspec
95
+ - test/fixtures/lists.xml
96
+ - test/fixtures/promotions.xml
97
+ - test/fixtures/search.xml
98
+ - test/helper.rb
99
+ - test/test_madmimi.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/madmimi/madmimi-gem
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options:
106
+ - --charset=UTF-8
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.6
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Mad Mimi API wrapper for Ruby
130
+ test_files:
131
+ - test/helper.rb
132
+ - test/test_madmimi.rb