madmimi 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nicholas Young
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.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
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
+ == A brief tutorial
6
+
7
+ Dependencies:
8
+ active_support (I intend to remove this in the not too distant future, and build my own implementation.)
9
+
10
+ mimi = MadMimi.new('emailaddress', 'api_key')
11
+
12
+ mimi.lists -> get all of your Mad Mimi lists returned as a hash
13
+
14
+ mimi.memberships('email') -> returns a hash of the lists that specific email address is subscribed to
15
+
16
+ mimi.new_list('New list name') -> make a new list
17
+
18
+ mimi.delete_list('New list name') -> delete the list I just created
19
+
20
+ mimi.csv_import("name,email\ndave,dave@example.com\n") -> import from a csv string
21
+
22
+ mimi.add_to_list('dave@example.com', 'Test List') -> add this email address to a specific list
23
+
24
+ mimi.remove_from_list('dave@example.com', 'Test List') -> remove this email address from a specific list
25
+
26
+ mimi.suppressed_since('unix timestamp') -> get a TXT of all addresses that were suppressed since this timestamp
27
+
28
+ mimi.promotions -> returns a hash of your promotions
29
+
30
+ mimi.mailing_stats('promotion_id', 'mailing_id') -> get stats on a specific mailing
31
+
32
+ == Note on Patches/Pull Requests
33
+
34
+ * Fork the project.
35
+ * Make your feature addition or bug fix.
36
+ * Add tests for it. This is important so I don't break it in a
37
+ future version unintentionally.
38
+ * Commit, do not mess with rakefile, version, or history.
39
+ (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)
40
+ * Send me a pull request. Bonus points for topic branches.
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2010 Nicholas Young. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
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/nicholaswyoung/mad_mimi_ruby"
12
+ gem.authors = ["Nicholas Young"]
13
+ gem.add_development_dependency "activesupport", ">= 2.3.5"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "madmimi #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
data/lib/madmimi.rb ADDED
@@ -0,0 +1,184 @@
1
+ # Mad Mimi - v.0.0.1 the incredibly basic, and barely usable version, in my opinion. (too many stinkin' dependencies!)
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 'rubygems' # So I can actually have other gems... All I need to do is ditch activesupport, and I'm good to ditch this one
30
+ require 'uri'
31
+ require 'net/http'
32
+ require 'net/https'
33
+ require 'active_support' # I want to find a way to get away from this, yet I love the Hash.from_xml method!
34
+
35
+ class MadMimi
36
+
37
+ BASE_URL = "madmimi.com"
38
+ NEW_LISTS_PATH = "/audience_lists"
39
+ AUDIENCE_MEMBERS_PATH = "/audience_members"
40
+ AUDIENCE_LISTS_PATH = "/audience_lists/lists.xml"
41
+ MEMBERSHIPS_PATH = "/audience_members/%email%/lists.xml"
42
+ SUPPRESSED_SINCE_PATH = "/audience_members/suppressed_since/%timestamp%.txt"
43
+ PROMOTIONS_PATH = "/promotions.xml"
44
+ MAILING_STATS_PATH = "/promotions/%promotion_id%/mailings/%mailing_id%.xml"
45
+ SEARCH_PATH = "/audience_members/search.xml"
46
+
47
+ @@api_settings = {}
48
+
49
+ def initialize(username, api_key)
50
+ @@api_settings[:username] = username
51
+ @@api_settings[:api_key] = api_key
52
+ end
53
+
54
+ def username
55
+ @@api_settings[:username]
56
+ end
57
+
58
+ def api_key
59
+ @@api_settings[:api_key]
60
+ end
61
+
62
+ def default_opt
63
+ { 'username' => username, 'api_key' => api_key }
64
+ end
65
+
66
+ # Refactor this method asap
67
+ def do_request(path, req_type = :get, options = {}, transactional = false)
68
+ resp = href = "";
69
+ case req_type
70
+ when :get then
71
+ begin
72
+ http = Net::HTTP.new(BASE_URL, 80)
73
+ http.start do |http|
74
+ req = Net::HTTP::Get.new(path)
75
+ req.set_form_data(options)
76
+ response = http.request(req)
77
+ resp = response.body
78
+ end
79
+ resp
80
+ rescue SocketError
81
+ raise "Host unreachable."
82
+ end
83
+ when :post then
84
+ begin
85
+ if transactional == true
86
+ http = Net::HTTP.new(BASE_URL, 443)
87
+ http.use_ssl = true
88
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
89
+ else
90
+ http = Net::HTTP.new(BASE_URL, 80)
91
+ end
92
+ http.start do |http|
93
+ req = Net::HTTP::Post.new(path)
94
+ req.set_form_data(options)
95
+ response = http.request(req)
96
+ resp = response.body
97
+ end
98
+ rescue SocketError
99
+ raise "Host unreachable."
100
+ end
101
+ end
102
+ end
103
+
104
+ def lists
105
+ request = do_request(AUDIENCE_LISTS_PATH, :get, default_opt)
106
+ Hash.from_xml(request)
107
+ end
108
+
109
+ def memberships(email)
110
+ request = do_request((MEMBERSHIPS_PATH.gsub('%email%', email)), :get, default_opt)
111
+ Hash.from_xml(request)
112
+ end
113
+
114
+ def new_list(list_name)
115
+ options = { 'name' => list_name }
116
+ do_request(NEW_LISTS_PATH, :post, options.merge(default_opt))
117
+ end
118
+
119
+ def delete_list(list_name)
120
+ options = { '_method' => 'delete' }
121
+ do_request(NEW_LISTS_PATH + "/" + URI.escape(list_name), :post, options.merge(default_opt))
122
+ end
123
+
124
+ def csv_import(csv_string)
125
+ options = { 'csv_file' => csv_string }
126
+ do_request(AUDIENCE_MEMBERS_PATH, :post, options.merge(default_opt))
127
+ end
128
+
129
+ def build_csv(hash)
130
+ csv = ""
131
+ hash.keys.each do |key|
132
+ csv << "#{key},"
133
+ end
134
+ # strip out one char at the end
135
+ csv << "\n"
136
+ csv = csv[0..-1]
137
+ hash.values.each do |value|
138
+ csv << "#{value},"
139
+ end
140
+ csv = csv[0..-1]
141
+ csv << "\n"
142
+ end
143
+
144
+ def add_user(options)
145
+ csv_data = build_csv(options)
146
+ opt = { 'csv_file' => csv_data }
147
+ do_request(AUDIENCE_MEMBERS_PATH, :post, opt.merge(default_opt))
148
+ end
149
+
150
+ def add_to_list(email, list_name)
151
+ options = { 'email' => email }
152
+ do_request(NEW_LISTS_PATH + "/" + URI.escape(list_name) + "/add", :post, options.merge(default_opt))
153
+ end
154
+
155
+ def remove_from_list(email, list_name)
156
+ options = { 'email' => email }
157
+ do_request(NEW_LISTS_PATH + "/" + URI.escape(list_name) + "/remove", :post, options.merge(default_opt))
158
+ end
159
+
160
+ def suppressed_since(timestamp)
161
+ do_request((SUPPRESSED_SINCE_PATH.gsub('%timestamp%', timestamp)), :get, default_opt)
162
+ end
163
+
164
+ def promotions
165
+ request = do_request(PROMOTIONS_PATH, :get, default_opt)
166
+ Hash.from_xml(request)
167
+ end
168
+
169
+ def mailing_stats(promotion_id, mailing_id)
170
+ path = (MAILING_STATS_PATH.gsub('%promotion_id%', promotion_id).gsub('%mailing_id%', mailing_id))
171
+ request = do_request(path, :get, default_opt)
172
+ Hash.from_xml(request)
173
+ end
174
+
175
+ def audience_search(query_string, raw = false)
176
+ options = { 'raw' => raw, 'query' => query_string }
177
+ request = do_request(SEARCH_PATH, :get, options.merge(default_opt))
178
+ Hash.from_xml(request)
179
+ end
180
+
181
+ def send_mail(opt)
182
+ do_request('/mailer', :post, opt.merge(default_opt), true)
183
+ end
184
+ end
data/madmimi.gemspec ADDED
@@ -0,0 +1,53 @@
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}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nicholas Young"]
12
+ s.date = %q{2010-04-30}
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
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/madmimi.rb",
25
+ "madmimi.gemspec",
26
+ "pkg/madmimi-1.0.0.gem",
27
+ "test/helper.rb",
28
+ "test/test_madmimi.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/nicholaswyoung/mad_mimi_ruby}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.6}
34
+ s.summary = %q{Mad Mimi API wrapper for Ruby}
35
+ s.test_files = [
36
+ "test/helper.rb",
37
+ "test/test_madmimi.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<activesupport>, [">= 2.3.5"])
46
+ else
47
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
51
+ end
52
+ end
53
+
Binary file
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'madmimi'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMadmimi < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "Coming soon!"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: madmimi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Nicholas Young
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-30 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Send emails, track statistics, and manage your subscriber base with ease.
35
+ email: nicholas@madmimi.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - lib/madmimi.rb
49
+ - madmimi.gemspec
50
+ - pkg/madmimi-1.0.0.gem
51
+ - test/helper.rb
52
+ - test/test_madmimi.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/nicholaswyoung/mad_mimi_ruby
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Mad Mimi API wrapper for Ruby
83
+ test_files:
84
+ - test/helper.rb
85
+ - test/test_madmimi.rb