postageapp 1.0.19 → 1.0.20
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/.gitignore +7 -0
- data/.travis.yml +6 -5
- data/Gemfile +2 -6
- data/LICENSE +1 -1
- data/README.md +5 -5
- data/Rakefile +2 -28
- data/lib/postageapp/mailer.rb +10 -8
- data/lib/postageapp/mailer/mailer_4.rb +174 -0
- data/lib/postageapp/version.rb +1 -5
- data/postageapp.gemspec +18 -99
- data/test/gemfiles/Gemfile.rails-2.3.x +0 -4
- data/test/gemfiles/Gemfile.rails-3.0.x +0 -4
- data/test/gemfiles/Gemfile.rails-3.1.x +0 -4
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -4
- data/test/gemfiles/Gemfile.rails-4.0.x +1 -5
- data/test/helper.rb +1 -2
- data/test/mailer_3_test.rb +20 -20
- data/test/mailer_4_test.rb +89 -0
- metadata +12 -30
- data/VERSION +0 -1
data/.gitignore
ADDED
data/.travis.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
language: ruby
|
1
2
|
rvm:
|
2
3
|
- 1.8.7
|
3
4
|
- 1.9.2
|
@@ -9,14 +10,14 @@ gemfile:
|
|
9
10
|
- test/gemfiles/Gemfile.rails-3.0.x
|
10
11
|
- test/gemfiles/Gemfile.rails-3.1.x
|
11
12
|
- test/gemfiles/Gemfile.rails-3.2.x
|
12
|
-
- test/gemfiles/Gemfile.rails
|
13
|
+
- test/gemfiles/Gemfile.rails-4.0.x
|
13
14
|
matrix:
|
14
15
|
exclude:
|
15
16
|
- rvm: 2.0.0
|
16
17
|
gemfile: test/gemfiles/Gemfile.rails-2.3.x
|
17
18
|
- rvm: 1.8.7
|
18
|
-
gemfile: test/gemfiles/Gemfile.rails
|
19
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
19
20
|
- rvm: ree
|
20
|
-
gemfile: test/gemfiles/Gemfile.rails
|
21
|
-
|
22
|
-
|
21
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
22
|
+
- rvm: 1.9.2
|
23
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
This is the gem used to integrate Ruby apps with PostageApp service.
|
4
4
|
Personalized, mass email sending can be offloaded to PostageApp via JSON based API.
|
5
5
|
|
6
|
-
### [API Documentation](http://help.postageapp.com/kb/api/api-overview) • [
|
6
|
+
### [API Documentation](http://help.postageapp.com/kb/api/api-overview) • [Knowledge Base](http://help.postageapp.com/kb) • [Help Portal](http://help.postageapp.com)
|
7
7
|
|
8
8
|
Installation
|
9
9
|
------------
|
10
10
|
|
11
|
-
### Rails 3
|
11
|
+
### Rails 3 / 4
|
12
12
|
Add postageapp gem to your Gemfile:
|
13
13
|
|
14
14
|
gem 'postageapp'
|
@@ -18,7 +18,7 @@ Then from the Rails project's root run:
|
|
18
18
|
bundle install
|
19
19
|
script/rails generate postageapp --api-key PROJECT_API_KEY
|
20
20
|
|
21
|
-
### Rails 2
|
21
|
+
### Rails 2
|
22
22
|
In config/environment.rb add the following:
|
23
23
|
|
24
24
|
config.gem 'postageapp'
|
@@ -106,7 +106,7 @@ Please note that `deliver` method will return `PostageApp::Response` object. Thi
|
|
106
106
|
>> response.ok?
|
107
107
|
=> true
|
108
108
|
|
109
|
-
### Rails 3
|
109
|
+
### Rails 3 / 4
|
110
110
|
|
111
111
|
Here's an example of a mailer in Rails 3 environment:
|
112
112
|
|
@@ -158,7 +158,7 @@ class Notifier < PostageApp::Mailer
|
|
158
158
|
end
|
159
159
|
```
|
160
160
|
|
161
|
-
### Rails 2
|
161
|
+
### Rails 2
|
162
162
|
|
163
163
|
Here's an example of a mailer you'd set in in a Rails 2 environment:
|
164
164
|
|
data/Rakefile
CHANGED
@@ -1,34 +1,8 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
1
|
require 'bundler'
|
4
|
-
|
5
|
-
Bundler.setup(:default, :development)
|
6
|
-
rescue Bundler::BundlerError => e
|
7
|
-
$stderr.puts e.message
|
8
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
-
exit e.status_code
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'rake'
|
2
|
+
require 'rake/testtask'
|
13
3
|
|
14
|
-
require
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = 'postageapp'
|
18
|
-
gem.summary = 'Easier way to send email from web apps'
|
19
|
-
gem.description = 'Gem that interfaces with PostageApp.com service to send emails from web apps'
|
20
|
-
gem.email = 'oleg@twg.ca'
|
21
|
-
gem.homepage = 'http://github.com/postageapp/postageapp-ruby'
|
22
|
-
gem.authors = ['Oleg Khabarov, The Working Group Inc']
|
23
|
-
gem.license = 'MIT'
|
24
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
-
end
|
29
|
-
Jeweler::RubygemsDotOrgTasks.new
|
4
|
+
Bundler.require
|
30
5
|
|
31
|
-
require 'rake/testtask'
|
32
6
|
Rake::TestTask.new(:test) do |test|
|
33
7
|
test.libs << 'lib' << 'test'
|
34
8
|
test.pattern = 'test/**/*_test.rb'
|
data/lib/postageapp/mailer.rb
CHANGED
@@ -4,7 +4,9 @@ require 'action_mailer/version'
|
|
4
4
|
# Loading PostageApp::Mailer class depending on what action_mailer is
|
5
5
|
# currently installed on the system. Assuming we're dealing only with
|
6
6
|
# ones that come with Rails 2 and 3
|
7
|
-
if ActionMailer::VERSION::MAJOR
|
7
|
+
if ActionMailer::VERSION::MAJOR == 4
|
8
|
+
require File.expand_path('../mailer/mailer_4', __FILE__)
|
9
|
+
elsif ActionMailer::VERSION::MAJOR == 3
|
8
10
|
require File.expand_path('../mailer/mailer_3', __FILE__)
|
9
11
|
else
|
10
12
|
require File.expand_path('../mailer/mailer_2', __FILE__)
|
@@ -13,7 +15,7 @@ end
|
|
13
15
|
# General helper methods for Request object to act more like TMail::Mail
|
14
16
|
# of Mail for testing
|
15
17
|
class PostageApp::Request
|
16
|
-
|
18
|
+
|
17
19
|
# Getter and setter for headers. You can specify headers in the following
|
18
20
|
# formats:
|
19
21
|
# headers['Custom-Header'] = 'Custom Value'
|
@@ -28,23 +30,23 @@ class PostageApp::Request
|
|
28
30
|
end
|
29
31
|
self.arguments['headers']
|
30
32
|
end
|
31
|
-
|
33
|
+
|
32
34
|
def to
|
33
35
|
out = self.arguments_to_send.dig('arguments', 'recipients')
|
34
36
|
out.is_a?(Hash) ? out : [out].flatten
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
def from
|
38
40
|
[self.arguments_to_send.dig('arguments', 'headers', 'from')].flatten
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
def subject
|
42
44
|
self.arguments_to_send.dig('arguments', 'headers', 'subject')
|
43
45
|
end
|
44
|
-
|
46
|
+
|
45
47
|
def body
|
46
48
|
out = self.arguments_to_send.dig('arguments', 'content')
|
47
49
|
out.is_a?(Hash) ? out.values.join("\n\n") : out.to_s
|
48
50
|
end
|
49
|
-
|
50
|
-
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Postage::Mailer allows you to use/re-use existing mailers set up using
|
2
|
+
# ActionMailer. The only catch is to change inheritance from ActionMailer::Base
|
3
|
+
# to PostageApp::Mailer. Also don't forget to require 'postageapp/mailer'
|
4
|
+
#
|
5
|
+
# Here's an example of a valid PostageApp::Mailer class
|
6
|
+
#
|
7
|
+
# require 'postageapp/mailer'
|
8
|
+
#
|
9
|
+
# class Notifier < PostageApp::Mailer
|
10
|
+
# def signup_notification(recipient)
|
11
|
+
# mail(
|
12
|
+
# :to => recipient.email,
|
13
|
+
# :from => 'sender@test.test',
|
14
|
+
# :subject => 'Test Message'
|
15
|
+
# )
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Postage::Mailer introduces a few mailer methods specific to Postage:
|
20
|
+
#
|
21
|
+
# * postageapp_template - template name that is defined in your PostageApp project
|
22
|
+
# * postageapp_variables - extra variables you want to send along with the message
|
23
|
+
#
|
24
|
+
# Sending email
|
25
|
+
#
|
26
|
+
# request = Notifier.signup_notification(user) # creates PostageApp::Request object
|
27
|
+
# response = request.deliver # attempts to deliver the message and creates a PostageApp::Response
|
28
|
+
#
|
29
|
+
class PostageApp::Mailer < ActionMailer::Base
|
30
|
+
|
31
|
+
# Wrapper for creating attachments
|
32
|
+
# Attachments sent to PostageApp are in the following format:
|
33
|
+
# 'filename.ext' => {
|
34
|
+
# 'content_type' => 'content/type',
|
35
|
+
# 'content' => 'base64_encoded_content'
|
36
|
+
# }
|
37
|
+
class Attachments < Hash
|
38
|
+
|
39
|
+
def initialize(message)
|
40
|
+
@_message = message
|
41
|
+
message.arguments['attachments'] ||= { }
|
42
|
+
end
|
43
|
+
|
44
|
+
def []=(filename, attachment)
|
45
|
+
default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''
|
46
|
+
if attachment.is_a?(Hash)
|
47
|
+
content_type = attachment[:content_type] || default_content_type
|
48
|
+
content = Base64.encode64(attachment[:body])
|
49
|
+
else
|
50
|
+
content_type = default_content_type
|
51
|
+
content = Base64.encode64(attachment)
|
52
|
+
end
|
53
|
+
@_message.arguments['attachments'][filename] = {
|
54
|
+
'content_type' => content_type,
|
55
|
+
'content' => content
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Instead of initializing Mail object, we prepare PostageApp::Request
|
61
|
+
def initialize(method_name = nil, *args)
|
62
|
+
super()
|
63
|
+
@_message = PostageApp::Request.new(:send_message)
|
64
|
+
process(method_name, *args) if method_name
|
65
|
+
end
|
66
|
+
|
67
|
+
# Possible to define custom uid. Should be sufficiently unique
|
68
|
+
def postageapp_uid(value = nil)
|
69
|
+
value ? @_message.uid = value : @_message.uid
|
70
|
+
end
|
71
|
+
|
72
|
+
def postageapp_api_key(value = nil)
|
73
|
+
value ? @_message.api_key = value : @_message.api_key
|
74
|
+
end
|
75
|
+
|
76
|
+
# In API call we can specify PostageApp template that will be used
|
77
|
+
# to generate content of the message
|
78
|
+
def postageapp_template(value = nil)
|
79
|
+
value ? @_message.arguments['template'] = value : @_message.arguments['template']
|
80
|
+
end
|
81
|
+
|
82
|
+
# Hash of variables that will be used to inject into the content
|
83
|
+
def postageapp_variables(value = nil)
|
84
|
+
value ? @_message.arguments['variables'] = value : @_message.arguments['variables']
|
85
|
+
end
|
86
|
+
|
87
|
+
def attachments
|
88
|
+
@_attachments ||= Attachments.new(@_message)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Override for headers assignment
|
92
|
+
def headers(args=nil)
|
93
|
+
@_message.headers(args)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Overriding method that prepares Mail object. This time we'll be
|
97
|
+
# contructing PostageApp::Request payload.
|
98
|
+
def mail(headers = {}, &block)
|
99
|
+
# Guard flag to prevent both the old and the new API from firing
|
100
|
+
# Should be removed when old API is removed
|
101
|
+
@_mail_was_called = true
|
102
|
+
m = @_message
|
103
|
+
|
104
|
+
# At the beginning, do not consider class default for parts order neither content_type
|
105
|
+
content_type = headers[:content_type]
|
106
|
+
|
107
|
+
# Call all the procs (if any)
|
108
|
+
class_default = self.class.default
|
109
|
+
default_values = class_default.merge(self.class.default) do |k,v|
|
110
|
+
v.respond_to?(:call) ? v.bind(self).call : v
|
111
|
+
end
|
112
|
+
|
113
|
+
# Handle defaults
|
114
|
+
headers = headers.reverse_merge(default_values)
|
115
|
+
headers[:subject] ||= default_i18n_subject
|
116
|
+
|
117
|
+
# Apply charset at the beginning so all fields are properly quoted
|
118
|
+
charset = headers[:charset]
|
119
|
+
|
120
|
+
# Set configure delivery behavior
|
121
|
+
wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
|
122
|
+
|
123
|
+
# Assigning recipients
|
124
|
+
m.arguments['recipients'] = headers.delete(:to)
|
125
|
+
|
126
|
+
# Assign all headers except parts_order, content_type and body
|
127
|
+
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
128
|
+
m.headers.merge!(assignable)
|
129
|
+
|
130
|
+
# Render the templates and blocks
|
131
|
+
responses = collect_responses(headers, &block)
|
132
|
+
create_parts_from_responses(m, responses)
|
133
|
+
|
134
|
+
m
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
def create_parts_from_responses(m, responses) #:nodoc:
|
139
|
+
map = {
|
140
|
+
'html' => 'text/html',
|
141
|
+
'text' => 'text/plain'
|
142
|
+
}
|
143
|
+
content = m.arguments['content'] ||= {}
|
144
|
+
responses.each do |part|
|
145
|
+
content_type = map[part[:content_type]] || part[:content_type]
|
146
|
+
content[content_type] = part[:body]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
# A set of methods that are useful when request needs to behave as Mail
|
153
|
+
class PostageApp::Request
|
154
|
+
|
155
|
+
attr_accessor :delivery_handler,
|
156
|
+
:perform_deliveries,
|
157
|
+
:raise_delivery_errors
|
158
|
+
|
159
|
+
# Either doing an actual send, or passing it along to Mail::TestMailer
|
160
|
+
# Probably not the best way as we're skipping way too many intermediate methods
|
161
|
+
def deliver
|
162
|
+
if @delivery_method == Mail::TestMailer
|
163
|
+
@delivery_method.deliveries << self
|
164
|
+
else
|
165
|
+
self.send
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Not 100% on this, but I need to assign this so I can properly handle deliver method
|
170
|
+
def delivery_method(method = nil, settings = {})
|
171
|
+
@delivery_method = method
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
data/lib/postageapp/version.rb
CHANGED
data/postageapp.gemspec
CHANGED
@@ -1,101 +1,20 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# encoding: utf-8
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
s.version = "1.0.19"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Oleg Khabarov, The Working Group Inc"]
|
12
|
-
s.date = "2013-03-19"
|
13
|
-
s.description = "Gem that interfaces with PostageApp.com service to send emails from web apps"
|
14
|
-
s.email = "oleg@twg.ca"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".travis.yml",
|
21
|
-
"Gemfile",
|
22
|
-
"LICENSE",
|
23
|
-
"README.md",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"generators/postageapp/postageapp_generator.rb",
|
27
|
-
"generators/postageapp/templates/initializer.rb",
|
28
|
-
"generators/postageapp/templates/postageapp_tasks.rake",
|
29
|
-
"lib/generators/postageapp/postageapp_generator.rb",
|
30
|
-
"lib/postageapp.rb",
|
31
|
-
"lib/postageapp/configuration.rb",
|
32
|
-
"lib/postageapp/failed_request.rb",
|
33
|
-
"lib/postageapp/logger.rb",
|
34
|
-
"lib/postageapp/mailer.rb",
|
35
|
-
"lib/postageapp/mailer/mailer_2.rb",
|
36
|
-
"lib/postageapp/mailer/mailer_3.rb",
|
37
|
-
"lib/postageapp/rails/rails.rb",
|
38
|
-
"lib/postageapp/rails/railtie.rb",
|
39
|
-
"lib/postageapp/request.rb",
|
40
|
-
"lib/postageapp/response.rb",
|
41
|
-
"lib/postageapp/utils.rb",
|
42
|
-
"lib/postageapp/version.rb",
|
43
|
-
"postageapp.gemspec",
|
44
|
-
"rails/init.rb",
|
45
|
-
"test/configuration_test.rb",
|
46
|
-
"test/failed_request_test.rb",
|
47
|
-
"test/gemfiles/Gemfile.rails-2.3.x",
|
48
|
-
"test/gemfiles/Gemfile.rails-3.0.x",
|
49
|
-
"test/gemfiles/Gemfile.rails-3.1.x",
|
50
|
-
"test/gemfiles/Gemfile.rails-3.2.x",
|
51
|
-
"test/gemfiles/Gemfile.rails-4.0.x",
|
52
|
-
"test/helper.rb",
|
53
|
-
"test/live_test.rb",
|
54
|
-
"test/mailer/action_mailer_2/notifier.rb",
|
55
|
-
"test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb",
|
56
|
-
"test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb",
|
57
|
-
"test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb",
|
58
|
-
"test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb",
|
59
|
-
"test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb",
|
60
|
-
"test/mailer/action_mailer_2/notifier/with_simple_view.erb",
|
61
|
-
"test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb",
|
62
|
-
"test/mailer/action_mailer_3/layouts/notifier.html.erb",
|
63
|
-
"test/mailer/action_mailer_3/notifier.rb",
|
64
|
-
"test/mailer/action_mailer_3/notifier/with_custom_postage_variables.html.erb",
|
65
|
-
"test/mailer/action_mailer_3/notifier/with_custom_postage_variables.text.erb",
|
66
|
-
"test/mailer/action_mailer_3/notifier/with_html_and_text_views.html.erb",
|
67
|
-
"test/mailer/action_mailer_3/notifier/with_html_and_text_views.text.erb",
|
68
|
-
"test/mailer/action_mailer_3/notifier/with_old_api.html.erb",
|
69
|
-
"test/mailer/action_mailer_3/notifier/with_old_api.text.erb",
|
70
|
-
"test/mailer/action_mailer_3/notifier/with_simple_view.erb",
|
71
|
-
"test/mailer/action_mailer_3/notifier/with_text_only_view.text.erb",
|
72
|
-
"test/mailer_2_test.rb",
|
73
|
-
"test/mailer_3_test.rb",
|
74
|
-
"test/mailer_helper_methods_test.rb",
|
75
|
-
"test/postageapp_test.rb",
|
76
|
-
"test/rails_initialization_test.rb",
|
77
|
-
"test/request_test.rb",
|
78
|
-
"test/response_test.rb"
|
79
|
-
]
|
80
|
-
s.homepage = "http://github.com/postageapp/postageapp-ruby"
|
81
|
-
s.licenses = ["MIT"]
|
82
|
-
s.require_paths = ["lib"]
|
83
|
-
s.rubygems_version = "1.8.23"
|
84
|
-
s.summary = "Easier way to send email from web apps"
|
85
|
-
|
86
|
-
if s.respond_to? :specification_version then
|
87
|
-
s.specification_version = 3
|
88
|
-
|
89
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
90
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
91
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
92
|
-
else
|
93
|
-
s.add_dependency(%q<json>, [">= 0"])
|
94
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
95
|
-
end
|
96
|
-
else
|
97
|
-
s.add_dependency(%q<json>, [">= 0"])
|
98
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
99
|
-
end
|
100
|
-
end
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'postageapp/version'
|
101
5
|
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "postageapp"
|
8
|
+
s.version = PostageApp::VERSION
|
9
|
+
s.authors = ["Oleg Khabarov", "The Working Group Inc"]
|
10
|
+
s.email = ["oleg@khabarov.ca"]
|
11
|
+
s.homepage = "http://github.com/twg/api_docs"
|
12
|
+
s.summary = "Easier way to send email from web apps"
|
13
|
+
s.description = "Gem that interfaces with PostageApp.com service to send emails from web apps"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'json'
|
20
|
+
end
|
data/test/helper.rb
CHANGED
@@ -8,8 +8,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
8
8
|
require 'postageapp'
|
9
9
|
require 'postageapp/mailer'
|
10
10
|
|
11
|
-
|
12
|
-
require 'mocha'
|
11
|
+
require 'mocha/setup'
|
13
12
|
|
14
13
|
class Test::Unit::TestCase
|
15
14
|
|
data/test/mailer_3_test.rb
CHANGED
@@ -2,69 +2,69 @@ require File.expand_path('../helper', __FILE__)
|
|
2
2
|
|
3
3
|
# tests for ActionMailer bundled with Rails 3
|
4
4
|
class Mailer3Test < Test::Unit::TestCase
|
5
|
-
|
6
|
-
if ActionMailer::VERSION::MAJOR
|
7
|
-
|
5
|
+
|
6
|
+
if ActionMailer::VERSION::MAJOR == 3
|
7
|
+
|
8
8
|
require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
|
9
9
|
puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
|
10
|
-
|
10
|
+
|
11
11
|
def test_create_with_no_content
|
12
12
|
mail = Notifier.with_no_content
|
13
13
|
assert_equal ({}), mail.arguments['content']
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_create_with_simple_view
|
17
17
|
mail = Notifier.with_simple_view
|
18
18
|
assert_equal 'with layout simple view content', mail.arguments['content']['text/html']
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_create_with_text_only_view
|
22
22
|
mail = Notifier.with_text_only_view
|
23
23
|
assert_equal 'text content', mail.arguments['content']['text/plain']
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_create_with_html_and_text_views
|
27
27
|
mail = Notifier.with_html_and_text_views
|
28
28
|
assert_equal 'text content', mail.arguments['content']['text/plain']
|
29
29
|
assert_equal 'with layout html content', mail.arguments['content']['text/html']
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_deliver_with_html_and_text_views
|
33
33
|
mock_successful_send
|
34
|
-
|
34
|
+
|
35
35
|
assert response = Notifier.with_html_and_text_views.deliver
|
36
36
|
assert response.is_a?(PostageApp::Response)
|
37
37
|
assert response.ok?
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_create_with_body_and_attachment_as_file
|
41
41
|
mail = Notifier.with_body_and_attachment_as_file
|
42
42
|
assert_equal 'manual body text', mail.arguments['content']['text/html']
|
43
43
|
assert_equal 'text/plain', mail.arguments['attachments']['sample_file.txt']['content_type']
|
44
44
|
assert_equal "RmlsZSBjb250ZW50\n", mail.arguments['attachments']['sample_file.txt']['content']
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_create_with_body_and_attachment_as_hash
|
48
48
|
mail = Notifier.with_body_and_attachment_as_hash
|
49
49
|
assert_equal 'manual body text', mail.arguments['content']['text/html']
|
50
50
|
assert_equal 'text/rich', mail.arguments['attachments']['sample_file.txt']['content_type']
|
51
51
|
assert_equal "RmlsZSBjb250ZW50\n", mail.arguments['attachments']['sample_file.txt']['content']
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def test_create_with_custom_postage_variables
|
55
55
|
mail = Notifier.with_custom_postage_variables
|
56
56
|
args = mail.arguments_to_send
|
57
|
-
|
57
|
+
|
58
58
|
assert_equal 'custom_uid', args['uid']
|
59
59
|
assert_equal 'custom_api_key', args['api_key']
|
60
|
-
|
60
|
+
|
61
61
|
args = args['arguments']
|
62
|
-
|
62
|
+
|
63
63
|
assert_equal ({
|
64
64
|
'test1@test.test' => { 'name' => 'Test 1'},
|
65
65
|
'test2@test.test' => { 'name' => 'Test 2'}
|
66
66
|
}), args['recipients']
|
67
|
-
|
67
|
+
|
68
68
|
assert_equal 'test-template', args['template']
|
69
69
|
assert_equal ({ 'variable' => 'value' }), args['variables']
|
70
70
|
assert_equal 'CustomValue1', args['headers']['CustomHeader1']
|
@@ -72,23 +72,23 @@ class Mailer3Test < Test::Unit::TestCase
|
|
72
72
|
assert_equal 'text content', args['content']['text/plain']
|
73
73
|
assert_equal 'with layout html content', args['content']['text/html']
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def test_create_with_recipient_override
|
77
77
|
PostageApp.configuration.recipient_override = 'oleg@test.test'
|
78
78
|
assert mail = Notifier.with_html_and_text_views
|
79
79
|
assert_equal 'test@test.test', mail.arguments['recipients']
|
80
80
|
assert_equal 'oleg@test.test', mail.arguments_to_send['arguments']['recipient_override']
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def test_deliver_for_test_mailer
|
84
84
|
mail = Notifier.with_simple_view
|
85
85
|
mail.delivery_method(Mail::TestMailer)
|
86
86
|
mail.deliver
|
87
87
|
assert_equal [mail], ActionMailer::Base.deliveries
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
else
|
91
91
|
puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
|
92
92
|
def test_nothing ; end
|
93
93
|
end
|
94
|
-
end
|
94
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
# tests for ActionMailer bundled with Rails 3
|
4
|
+
class Mailer4Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
if ActionMailer::VERSION::MAJOR == 4
|
7
|
+
|
8
|
+
require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
|
9
|
+
puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
|
10
|
+
|
11
|
+
def test_create_with_simple_view
|
12
|
+
mail = Notifier.with_simple_view
|
13
|
+
assert_equal 'with layout simple view content', mail.arguments['content']['text/html']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_with_text_only_view
|
17
|
+
mail = Notifier.with_text_only_view
|
18
|
+
assert_equal 'text content', mail.arguments['content']['text/plain']
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_create_with_html_and_text_views
|
22
|
+
mail = Notifier.with_html_and_text_views
|
23
|
+
assert_equal 'text content', mail.arguments['content']['text/plain']
|
24
|
+
assert_equal 'with layout html content', mail.arguments['content']['text/html']
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_deliver_with_html_and_text_views
|
28
|
+
mock_successful_send
|
29
|
+
|
30
|
+
assert response = Notifier.with_html_and_text_views.deliver
|
31
|
+
assert response.is_a?(PostageApp::Response)
|
32
|
+
assert response.ok?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create_with_body_and_attachment_as_file
|
36
|
+
mail = Notifier.with_body_and_attachment_as_file
|
37
|
+
assert_equal 'manual body text', mail.arguments['content']['text/html']
|
38
|
+
assert_equal 'text/plain', mail.arguments['attachments']['sample_file.txt']['content_type']
|
39
|
+
assert_equal "RmlsZSBjb250ZW50\n", mail.arguments['attachments']['sample_file.txt']['content']
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_create_with_body_and_attachment_as_hash
|
43
|
+
mail = Notifier.with_body_and_attachment_as_hash
|
44
|
+
assert_equal 'manual body text', mail.arguments['content']['text/html']
|
45
|
+
assert_equal 'text/rich', mail.arguments['attachments']['sample_file.txt']['content_type']
|
46
|
+
assert_equal "RmlsZSBjb250ZW50\n", mail.arguments['attachments']['sample_file.txt']['content']
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_create_with_custom_postage_variables
|
50
|
+
mail = Notifier.with_custom_postage_variables
|
51
|
+
args = mail.arguments_to_send
|
52
|
+
|
53
|
+
assert_equal 'custom_uid', args['uid']
|
54
|
+
assert_equal 'custom_api_key', args['api_key']
|
55
|
+
|
56
|
+
args = args['arguments']
|
57
|
+
|
58
|
+
assert_equal ({
|
59
|
+
'test1@test.test' => { 'name' => 'Test 1'},
|
60
|
+
'test2@test.test' => { 'name' => 'Test 2'}
|
61
|
+
}), args['recipients']
|
62
|
+
|
63
|
+
assert_equal 'test-template', args['template']
|
64
|
+
assert_equal ({ 'variable' => 'value' }), args['variables']
|
65
|
+
assert_equal 'CustomValue1', args['headers']['CustomHeader1']
|
66
|
+
assert_equal 'CustomValue2', args['headers']['CustomHeader2']
|
67
|
+
assert_equal 'text content', args['content']['text/plain']
|
68
|
+
assert_equal 'with layout html content', args['content']['text/html']
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_create_with_recipient_override
|
72
|
+
PostageApp.configuration.recipient_override = 'oleg@test.test'
|
73
|
+
assert mail = Notifier.with_html_and_text_views
|
74
|
+
assert_equal 'test@test.test', mail.arguments['recipients']
|
75
|
+
assert_equal 'oleg@test.test', mail.arguments_to_send['arguments']['recipient_override']
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_deliver_for_test_mailer
|
79
|
+
mail = Notifier.with_simple_view
|
80
|
+
mail.delivery_method(Mail::TestMailer)
|
81
|
+
mail.deliver
|
82
|
+
assert_equal [mail], ActionMailer::Base.deliveries
|
83
|
+
end
|
84
|
+
|
85
|
+
else
|
86
|
+
puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
|
87
|
+
def test_nothing ; end
|
88
|
+
end
|
89
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postageapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Oleg Khabarov
|
8
|
+
- Oleg Khabarov
|
9
|
+
- The Working Group Inc
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: json
|
@@ -27,37 +28,20 @@ dependencies:
|
|
27
28
|
- - ! '>='
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: jeweler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
31
|
description: Gem that interfaces with PostageApp.com service to send emails from web
|
47
32
|
apps
|
48
|
-
email:
|
33
|
+
email:
|
34
|
+
- oleg@khabarov.ca
|
49
35
|
executables: []
|
50
36
|
extensions: []
|
51
|
-
extra_rdoc_files:
|
52
|
-
- LICENSE
|
53
|
-
- README.md
|
37
|
+
extra_rdoc_files: []
|
54
38
|
files:
|
39
|
+
- .gitignore
|
55
40
|
- .travis.yml
|
56
41
|
- Gemfile
|
57
42
|
- LICENSE
|
58
43
|
- README.md
|
59
44
|
- Rakefile
|
60
|
-
- VERSION
|
61
45
|
- generators/postageapp/postageapp_generator.rb
|
62
46
|
- generators/postageapp/templates/initializer.rb
|
63
47
|
- generators/postageapp/templates/postageapp_tasks.rake
|
@@ -69,6 +53,7 @@ files:
|
|
69
53
|
- lib/postageapp/mailer.rb
|
70
54
|
- lib/postageapp/mailer/mailer_2.rb
|
71
55
|
- lib/postageapp/mailer/mailer_3.rb
|
56
|
+
- lib/postageapp/mailer/mailer_4.rb
|
72
57
|
- lib/postageapp/rails/rails.rb
|
73
58
|
- lib/postageapp/rails/railtie.rb
|
74
59
|
- lib/postageapp/request.rb
|
@@ -106,14 +91,14 @@ files:
|
|
106
91
|
- test/mailer/action_mailer_3/notifier/with_text_only_view.text.erb
|
107
92
|
- test/mailer_2_test.rb
|
108
93
|
- test/mailer_3_test.rb
|
94
|
+
- test/mailer_4_test.rb
|
109
95
|
- test/mailer_helper_methods_test.rb
|
110
96
|
- test/postageapp_test.rb
|
111
97
|
- test/rails_initialization_test.rb
|
112
98
|
- test/request_test.rb
|
113
99
|
- test/response_test.rb
|
114
|
-
homepage: http://github.com/
|
115
|
-
licenses:
|
116
|
-
- MIT
|
100
|
+
homepage: http://github.com/twg/api_docs
|
101
|
+
licenses: []
|
117
102
|
post_install_message:
|
118
103
|
rdoc_options: []
|
119
104
|
require_paths:
|
@@ -124,9 +109,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
109
|
- - ! '>='
|
125
110
|
- !ruby/object:Gem::Version
|
126
111
|
version: '0'
|
127
|
-
segments:
|
128
|
-
- 0
|
129
|
-
hash: -4418215173582441535
|
130
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
113
|
none: false
|
132
114
|
requirements:
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.19
|