mad_mimi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
File without changes
data/Gemfile CHANGED
File without changes
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mad_mimi (0.0.1)
5
- faraday (= 0.5.4)
6
- faraday_middleware (= 0.3.1)
7
- multi_xml (= 0.2.0)
4
+ mad_mimi (0.0.2)
5
+ faraday (= 0.5.5)
6
+ faraday_middleware (= 0.3.2)
7
+ multi_xml (= 0.2.1)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- addressable (2.2.3)
12
+ addressable (2.2.4)
13
13
  crack (0.1.8)
14
14
  diff-lcs (1.1.2)
15
- faraday (0.5.4)
16
- addressable (~> 2.2.2)
15
+ faraday (0.5.5)
16
+ addressable (~> 2.2.4)
17
17
  multipart-post (~> 1.1.0)
18
18
  rack (>= 1.1.0, < 2)
19
- faraday_middleware (0.3.1)
20
- faraday (~> 0.5.3)
21
- multi_xml (0.2.0)
19
+ faraday_middleware (0.3.2)
20
+ faraday (~> 0.5.4)
21
+ multi_xml (0.2.1)
22
22
  multipart-post (1.1.0)
23
23
  rack (1.2.1)
24
24
  rspec (2.4.0)
File without changes
data/Manifest CHANGED
File without changes
@@ -1,6 +1,71 @@
1
- = MadMimi
1
+ = The MadMimi Ruby Gem
2
2
 
3
- Manage your MadMimi audience
3
+ A Ruby wrapper for the MadMimi API. Deliver emails and manage your MadMimi audience.
4
+
5
+ == Installation
6
+
7
+ gem install mad_mimi
8
+
9
+ == Documentation
10
+
11
+ http://rdoc.info/gems/mad_mimi
12
+
13
+ == Usage Examples
14
+
15
+ require "rubygems"
16
+ require "mad_mimi"
17
+
18
+ # Sets the MadMimi configuration options. Best used by passing a block.
19
+ MadMimi.configure do |config|
20
+ config.username = "YourMadMimiEmailAddress"
21
+ config.api_key = "YourMadMimiApiKey"
22
+ end
23
+
24
+ # Sending transactional email
25
+ MadMimi.mailer.mail({ :promotion_name => "Welcome", :recipients => "Ozéias Sant'Ana <oz.santana@gmail.com>" })
26
+
27
+ # Performs an audience search and returns the up to the first 100 results.
28
+ MadMimi.audience.search
29
+
30
+ # Get Audience Members
31
+ MadMimi.audience.members
32
+
33
+ # Get all Audience Lists
34
+ MadMimi.audience.lists
35
+
36
+ # Add Audience List Membership
37
+ MadMimi.audience.add_to_list('Clients', {:first_name => 'Ozéias', :last_name => 'Santana', :email => 'oz.santana@gmail.com'})
38
+
39
+ # Remove Audience List Membership
40
+ MadMimi.audience.remove_from_list('Clients', 'oz.santana@gmail.com')
41
+
42
+ # Suppress an Audience Member
43
+ MadMimi.audience.suppress('oz.santana@gmail.com')
44
+
45
+ == Contributing
46
+
47
+ In the spirit of {free software}[http://www.fsf.org/licensing/essays/free-sw.html], *everyone* is encouraged to help improve this project.
48
+
49
+ Here are some ways you can contribute:
50
+
51
+ * by using alpha, beta, and prerelease versions
52
+ * by reporting bugs
53
+ * by suggesting new features
54
+ * by writing or editing documentation
55
+ * by writing specifications
56
+ * by writing code (no patch is too small: fix typos, add comments, clean up inconsistent whitespace)
57
+ * by refactoring code
58
+ * by closing {issues}[https://github.com/ozeias/mad_mimi/issues]
59
+ * by reviewing patches
60
+
61
+ == Submitting an Issue
62
+
63
+ We use the {GitHub issue tracker}[https://github.com/ozeias/mad_mimi/issues] to track bugs and
64
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
65
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
66
+ bug report, please include a {Gist}[http://gist.github.com/] that includes a stack trace and any
67
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
68
+ operating system. Ideally, a bug report should include a pull request with failing specs.
4
69
 
5
70
  == Copyright
6
71
 
data/Rakefile CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  require "singleton"
2
2
 
3
3
  require "mad_mimi/audience"
4
+ require "mad_mimi/mailer"
4
5
  require "mad_mimi/config"
5
6
 
6
7
  module MadMimi #:nodoc
@@ -10,8 +11,8 @@ module MadMimi #:nodoc
10
11
  # Example:
11
12
  #
12
13
  # MadMimi.configure do |config|
13
- # config.username = "emailaddress"
14
- # config.api_key = "api_key"
14
+ # config.username = "YourMadMimiEmailAddress"
15
+ # config.api_key = "YourMadMimiApiKey"
15
16
  # end
16
17
  #
17
18
  # Returns:
@@ -33,12 +34,16 @@ module MadMimi #:nodoc
33
34
  }
34
35
  end
35
36
 
36
- def api_url
37
- 'http://api.madmimi.com'
37
+ def api_url(ssl = false)
38
+ "#{ssl ? 'https' : 'http'}://api.madmimi.com"
38
39
  end
39
40
 
40
41
  def audience
41
42
  MadMimi::Audience.new
42
43
  end
44
+
45
+ def mailer
46
+ MadMimi::Mailer.new
47
+ end
43
48
  end
44
49
  end
@@ -1,7 +1,22 @@
1
1
  require File.expand_path('../request', __FILE__)
2
+
2
3
  module MadMimi #:nodoc
3
4
  class Audience #:nodoc
4
5
  include Request
6
+ # Search
7
+ #
8
+ # Performs an audience search and returns the up to the first 100 results.
9
+ #
10
+ # == Optional parameters are:
11
+ # * <tt>:query</tt> -- The query parameter can be any search criteria you can use in the interface. A common use would be to use this function to get all of a member’s details by sending the email address as the query.
12
+ # * <tt>:raw</tt> -- if you want to return all users, regardless of suppression status, add the raw=true parameter on the end of your query.
13
+ # * <tt>:add_list</tt> -- You can add the results of the search to a new or existing list by passing an additional add_list parameter with the name of the list.
14
+ #
15
+ # See {Search}[http://madmimi.com/developer/lists/search]
16
+ def search(options = {})
17
+ response = get('/audience_members/search.xml', options)
18
+ response ? response["audience"]["member"] : response
19
+ end
5
20
 
6
21
  # Get Audience Members
7
22
  #
@@ -14,8 +29,8 @@ module MadMimi #:nodoc
14
29
  #
15
30
  # See {Get Audience Members}[http://madmimi.com/developer/lists]
16
31
  def members(options = {})
17
- members = get('/audience_members')
18
- members ? members["audience"]["member"] : members
32
+ response = get('/audience_members')
33
+ response ? response["audience"]["member"] : response
19
34
  end
20
35
 
21
36
  # Get all Audience Lists
@@ -24,8 +39,8 @@ module MadMimi #:nodoc
24
39
  #
25
40
  # See {Get all Audience Lists}[http://madmimi.com/developer/lists/get-all-audience-lists]
26
41
  def lists
27
- lists = get('/audience_lists/lists.xml')
28
- lists ? lists["lists"]["list"] : lists
42
+ response = get('/audience_lists/lists.xml')
43
+ response ? response["lists"]["list"] : response
29
44
  end
30
45
 
31
46
  # Add Audience List Membership
File without changes
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../request', __FILE__)
2
+
3
+ module MadMimi #:nodoc
4
+ # The Mailer API that lets you use Mad Mimi to send your transactional emails like welcome letters,
5
+ # password resets, and account activations. You can also use it to programmatically send promotional
6
+ # emails to an audience list.
7
+
8
+ class Mailer
9
+ include Request
10
+
11
+ # Sending transactional email
12
+ #
13
+ # Sends a single transactional email to the recipient. Returns a unique transaction id if successful.
14
+ #
15
+ # == Required parameters are:
16
+ # * <tt>:promotion_name</tt> -- The name of the promotion Mimi will send. For +raw_html+ or +raw_plain_text+ promotions, MadMimi will automatically create or update the promotion in your account.
17
+ # * <tt>:recipients</tt> -- The recipient (singular although the parameter name is plural) again just the email or in +Display Name <email@domain.com>+ format.
18
+ # * <tt>:body</tt> -- Required if you have placeholders. YAML encoded replacements for any {placeholders} in your promotion.
19
+ #
20
+ # == Optional parameters are:
21
+ # * <tt>:subject</tt> -- The subject of the email. Will default to the +promotion_name+ if not supplied.
22
+ # * <tt>:from</tt> -- The from address. Just the email address or in +Display Name <email@domain.com>+ format.
23
+ # * <tt>:bcc</tt> -- An email address to BCC. Just the email address.
24
+ # * <tt>:raw_html</tt> -- The custom HTML to send. Can be used on its own or in conjunction with +raw_plain_text+.
25
+ # * <tt>:raw_plain_text</tt> -- The custom plain text to send. Can be used on its own or in conjunction with +raw_html+.
26
+ # * <tt>:check_suppressed</tt> -- Checks if the recipient is suppressed and does not send if so (default: on).
27
+ # * <tt>:track_links</tt> -- Enable or disable link tracking in HTML promotions (default: on).
28
+ # * <tt>:hidden</tt> -- Creates the promotion as a hidden promotion so as not to clutter up your web interface (default: off).
29
+ #
30
+ # See {Sending transactional email with the Mailer API}[http://madmimi.com/developer/mailer/transactional]
31
+ def mail(options = {})
32
+ options[:check_suppressed] ||= true
33
+ post("/mailer", options, true, true)
34
+ end
35
+ end
36
+ end
@@ -8,13 +8,13 @@ module MadMimi
8
8
  request(:get, path, options, raw)
9
9
  end
10
10
 
11
- def post(path, options={}, raw = false)
12
- request(:post, path, options, raw)
11
+ def post(path, options={}, raw = false, ssl = false)
12
+ request(:post, path, options, raw, ssl)
13
13
  end
14
14
 
15
15
  private
16
- def request(method, path, options, raw = false)
17
- response = connection(raw).send(method) do |request|
16
+ def request(method, path, options, raw = false, ssl = false)
17
+ response = connection(raw, ssl).send(method) do |request|
18
18
  options = options.merge(MadMimi.authentication)
19
19
  case method
20
20
  when :get
@@ -27,11 +27,11 @@ module MadMimi
27
27
  raw ? response : response.body
28
28
  end
29
29
 
30
- def connection(raw = false)
30
+ def connection(raw = false, ssl = false)
31
31
  options = {
32
32
  :headers => {'Accept' => "application/xml", 'User-Agent' => 'MadMimi Gem'},
33
33
  :ssl => { :verify => false },
34
- :url => MadMimi.api_url
34
+ :url => MadMimi.api_url(ssl)
35
35
  }
36
36
 
37
37
  Faraday::Connection.new(options) do |builder|
@@ -1,3 +1,3 @@
1
1
  module MadMimi
2
- VERSION = "0.0.1" unless defined?(::MadMimi::VERSION)
2
+ VERSION = "0.0.2" unless defined?(::MadMimi::VERSION)
3
3
  end
@@ -13,12 +13,12 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.summary = %q{Manage your MadMimi audience}
15
15
 
16
- s.required_rubygems_version = Gem::Requirement.new('>= 1.3.7') if s.respond_to? :required_rubygems_version=
16
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
17
17
 
18
- s.add_runtime_dependency 'faraday', '0.5.4'
18
+ s.add_runtime_dependency 'faraday', '0.5.5'
19
19
 
20
- s.add_dependency 'faraday_middleware', '0.3.1'
21
- s.add_dependency 'multi_xml', '0.2.0'
20
+ s.add_dependency 'faraday_middleware', '0.3.2'
21
+ s.add_dependency 'multi_xml', '0.2.1'
22
22
 
23
23
  s.add_development_dependency 'rspec', '~> 2.4.0'
24
24
  s.add_development_dependency 'webmock', '~> 1.6.2'
File without changes
File without changes
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <audience>
3
+ <member suppressed="false">
4
+ <first_name>Ozéias</first_name>
5
+ <last_name>Sant'ana</last_name>
6
+ <email>oz.santana@gmail.com</email>
7
+ <created_at>Tue Jan 24 11:05:25 -0400 2011</created_at>
8
+ <title>Mrs</title>
9
+ <country>BR</country>
10
+ <confirmed/>
11
+ <twitter>@ozeias</twitter>
12
+ <friend_name>Oz</friend_name>
13
+ <lists>
14
+ <list>dev</list>
15
+ </lists>
16
+ </member>
17
+ <member suppressed="false">
18
+ <first_name>Mad</first_name>
19
+ <last_name>Mimi</last_name>
20
+ <email>support@madmimi.com</email>
21
+ <created_at>Tue Apr 20 14:30:25 -0400 2010</created_at>
22
+ <city/>
23
+ <phone/>
24
+ <company>Mad Mimi</company>
25
+ <title>Mrs</title>
26
+ <address/>
27
+ <state/>
28
+ <zip/>
29
+ <country>US</country>
30
+ <confirmed/>
31
+ <birthday/>
32
+ <categories/>
33
+ <friend_name>Marc</friend_name>
34
+ <lists>
35
+ <list>test</list>
36
+ </lists>
37
+ </member>
38
+ </audience>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <audience>
3
+ <member suppressed="false">
4
+ <first_name>Ozéias</first_name>
5
+ <last_name>Sant'ana</last_name>
6
+ <email>oz.santana@gmail.com</email>
7
+ <created_at>Tue Jan 24 11:05:25 -0400 2011</created_at>
8
+ <title>Mrs</title>
9
+ <country>BR</country>
10
+ <confirmed/>
11
+ <twitter>@ozeias</twitter>
12
+ <friend_name>Oz</friend_name>
13
+ <lists>
14
+ <list>dev</list>
15
+ </lists>
16
+ </member>
17
+ </audience>
@@ -14,6 +14,29 @@ describe MadMimi::Audience do
14
14
  connection.should == "http://api.madmimi.com/"
15
15
  end
16
16
 
17
+ describe ".search" do
18
+ before do
19
+ stub_get('/audience_members/search.xml').
20
+ with(:headers => {'Accept'=>'application/xml', 'User-Agent'=>'MadMimi Gem'}).
21
+ to_return(:status => 200, :body => fixture("audience_search.xml"), :headers => {:content_type => "application/xml; charset=utf-8"})
22
+
23
+ stub_get('/audience_members/search.xml', { :query => 'oz.santana@gmail.com'}).
24
+ with(:headers => {'Accept'=>'application/xml', 'User-Agent'=>'MadMimi Gem'}).
25
+ to_return(:status => 200, :body => fixture("audience_search_query.xml"), :headers => {:content_type => "application/xml; charset=utf-8"})
26
+ end
27
+
28
+ it "should get all audience members" do
29
+ MadMimi.audience.search.should == [
30
+ { "created_at"=>"Tue Jan 24 11:05:25 -0400 2011", "confirmed"=>nil, "country"=>"BR", "title"=>"Mrs", "suppressed"=>"false", "lists"=>{"list"=>"dev"}, "friend_name"=>"Oz", "last_name"=>"Sant'ana", "twitter"=>"@ozeias", "email"=>"oz.santana@gmail.com", "first_name"=>"Ozéias" },
31
+ { "address"=>nil, "company"=>"Mad Mimi", "city"=>nil, "zip"=>nil, "created_at"=>"Tue Apr 20 14:30:25 -0400 2010", "confirmed"=>nil, "country"=>"US", "title"=>"Mrs", "suppressed"=>"false", "lists"=>{"list"=>"test"}, "friend_name"=>"Marc", "birthday"=>nil, "phone"=>nil, "last_name"=>"Mimi", "categories"=>nil, "state"=>nil, "email"=>"support@madmimi.com", "first_name"=>"Mad" }
32
+ ]
33
+ end
34
+
35
+ it "should set the query" do
36
+ MadMimi.audience.search({:query => 'oz.santana@gmail.com'}).should == { "created_at"=>"Tue Jan 24 11:05:25 -0400 2011", "confirmed"=>nil, "country"=>"BR", "title"=>"Mrs", "suppressed"=>"false", "lists"=>{"list"=>"dev"}, "friend_name"=>"Oz", "last_name"=>"Sant'ana", "twitter"=>"@ozeias", "email"=>"oz.santana@gmail.com", "first_name"=>"Ozéias" }
37
+ end
38
+ end
39
+
17
40
  describe ".members" do
18
41
  before do
19
42
  stub_get('/audience_members').
@@ -0,0 +1,27 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe MadMimi::Mailer do
4
+ before (:all) do
5
+ MadMimi.configure do |config|
6
+ config.username = "email@example.com"
7
+ config.api_key = "api_key"
8
+ end
9
+ end
10
+
11
+ describe ".mail" do
12
+ before do
13
+ stub_post('/mailer', true).
14
+ with(:headers => {'Accept'=>'application/xml', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'MadMimi Gem'}).
15
+ to_return(:status => 200, :body => "2875078090", :headers => {:content_type => "text/html; charset=utf-8"})
16
+ end
17
+
18
+ it "should remove audience list membership" do
19
+ MadMimi.mailer.mail({ :promotion_name => "Welcome to Acme Widgets", :recipients => "Ozéias Sant'Ana <oz.santana@gmail.com>" })
20
+
21
+ a_post('/mailer', true).
22
+ with(:body => 'username=email%40example.com&promotion_name=Welcome+to+Acme+Widgets&recipients=Oz%C3%A9ias+Sant%27Ana+%3Coz.santana%40gmail.com%3E&api_key=api_key&check_suppressed=true').
23
+ with(:headers => {'Accept'=>'application/xml', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'MadMimi Gem'}).
24
+ should have_been_made
25
+ end
26
+ end
27
+ end
File without changes
@@ -4,17 +4,17 @@ require 'rspec'
4
4
  require 'webmock/rspec'
5
5
  include WebMock::API
6
6
 
7
- def a_post(path)
8
- a_request(:post, MadMimi.api_url + path)
7
+ def a_post(path, ssl = false)
8
+ a_request(:post, MadMimi.api_url(ssl) + path)
9
9
  end
10
10
 
11
- def stub_get(path)
12
- path = path + '?' + parameterize(MadMimi.authentication)
11
+ def stub_get(path, options = {})
12
+ path = path + '?' + parameterize(options.merge(MadMimi.authentication))
13
13
  stub_request(:get, MadMimi.api_url + path)
14
14
  end
15
15
 
16
- def stub_post(path)
17
- stub_request(:post, MadMimi.api_url + path)
16
+ def stub_post(path, ssl = false)
17
+ stub_request(:post, MadMimi.api_url(ssl) + path)
18
18
  end
19
19
 
20
20
  def fixture_path
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mad_mimi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Oz\xC3\xA9ias Sant'ana"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-23 00:00:00 -02:00
18
+ date: 2011-02-11 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - "="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 1
30
30
  segments:
31
31
  - 0
32
32
  - 5
33
- - 4
34
- version: 0.5.4
33
+ - 5
34
+ version: 0.5.5
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - "="
44
44
  - !ruby/object:Gem::Version
45
- hash: 17
45
+ hash: 23
46
46
  segments:
47
47
  - 0
48
48
  - 3
49
- - 1
50
- version: 0.3.1
49
+ - 2
50
+ version: 0.3.2
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -58,12 +58,12 @@ dependencies:
58
58
  requirements:
59
59
  - - "="
60
60
  - !ruby/object:Gem::Version
61
- hash: 23
61
+ hash: 21
62
62
  segments:
63
63
  - 0
64
64
  - 2
65
- - 0
66
- version: 0.2.0
65
+ - 1
66
+ version: 0.2.1
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
@@ -117,12 +117,16 @@ files:
117
117
  - lib/mad_mimi.rb
118
118
  - lib/mad_mimi/audience.rb
119
119
  - lib/mad_mimi/config.rb
120
+ - lib/mad_mimi/mailer.rb
120
121
  - lib/mad_mimi/request.rb
121
122
  - lib/mad_mimi/version.rb
122
123
  - mad_mimi.gemspec
123
124
  - spec/fixtures/audience_lists.xml
124
125
  - spec/fixtures/audience_members.xml
126
+ - spec/fixtures/audience_search.xml
127
+ - spec/fixtures/audience_search_query.xml
125
128
  - spec/mad_mimi/audience_spec.rb
129
+ - spec/mad_mimi/mailer_spec.rb
126
130
  - spec/mad_mimi_spec.rb
127
131
  - spec/spec_helper.rb
128
132
  has_rdoc: true
@@ -148,22 +152,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  requirements:
149
153
  - - ">="
150
154
  - !ruby/object:Gem::Version
151
- hash: 21
155
+ hash: 23
152
156
  segments:
153
157
  - 1
154
158
  - 3
155
- - 7
156
- version: 1.3.7
159
+ - 6
160
+ version: 1.3.6
157
161
  requirements: []
158
162
 
159
163
  rubyforge_project:
160
- rubygems_version: 1.3.7
164
+ rubygems_version: 1.4.2
161
165
  signing_key:
162
166
  specification_version: 3
163
167
  summary: Manage your MadMimi audience
164
168
  test_files:
165
169
  - spec/fixtures/audience_lists.xml
166
170
  - spec/fixtures/audience_members.xml
171
+ - spec/fixtures/audience_search.xml
172
+ - spec/fixtures/audience_search_query.xml
167
173
  - spec/mad_mimi/audience_spec.rb
174
+ - spec/mad_mimi/mailer_spec.rb
168
175
  - spec/mad_mimi_spec.rb
169
176
  - spec/spec_helper.rb