am-sendgrid 0.1.0

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .idea
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 SharesPost
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,17 @@
1
+ = am-sendgrid
2
+
3
+ This gem makes the sendgrid smtp api a little nice to use from within ActionMailer. See the test cases for an example.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 SharesPost. See LICENSE for details.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "am-sendgrid"
8
+ gem.summary = %Q{Makes it easy to call the sendgrid SMTP api from ActionMailer}
9
+ gem.email = "chris@gaslightsoftware.com"
10
+ gem.homepage = "http://github.com/sharespost/am-sendgrid"
11
+ gem.authors = ["Chris Nelson"]
12
+ gem.add_dependency "actionmailer", ">= 2.3.2"
13
+ gem.add_dependency "json_pure"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "am-sendgrid #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,27 @@
1
+ require 'actionmailer'
2
+ require 'smtp_api_header'
3
+
4
+ module ActionMailer
5
+ class Base
6
+
7
+ def sendgrid_header
8
+ @sendgrid_header ||= SmtpApiHeader.new
9
+ end
10
+
11
+ def create_mail_with_sendgrid_header
12
+ headers["X-SMTPAPI"] = sendgrid_header.asJSON if sendgrid_header
13
+ create_mail_without_sendgrid_header
14
+ end
15
+
16
+ alias_method_chain :create_mail, :sendgrid_header
17
+
18
+ def sendgrid_filter_setting(*args)
19
+ sendgrid_header.addFilterSetting *args
20
+ end
21
+
22
+ def sendgrid_category(category)
23
+ sendgrid_header.setCategory category
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+
3
+ class SmtpApiHeader
4
+
5
+ def initialize()
6
+ @data = {}
7
+ end
8
+
9
+ def addTo(to)
10
+ if not @data['to']
11
+ @data['to'] = []
12
+ end
13
+ if to.instance_of?(Array)
14
+ @data['to'] = @data['to'] | to
15
+ else
16
+ @data['to'].push to
17
+ end
18
+ end
19
+
20
+ def addSubVal(var, val)
21
+ if not @data['sub']
22
+ @data['sub'] = {}
23
+ end
24
+ if val.instance_of?(Array)
25
+ @data['sub'][var] = val
26
+ else
27
+ @data['sub'][var] = [val]
28
+ end
29
+ end
30
+
31
+ def setUniqueArgs(val)
32
+ if val.instance_of?(Hash)
33
+ @data['unique_args'] = val
34
+ end
35
+ end
36
+
37
+ def setCategory(cat)
38
+
39
+ @data['category'] = cat
40
+ end
41
+
42
+ def addFilterSetting(fltr, setting, val)
43
+ if not @data['filters']
44
+ @data['filters'] = {}
45
+ end
46
+ if not @data['filters'][fltr]
47
+ @data['filters'][fltr] = {}
48
+ end
49
+ if not @data['filters'][fltr]['settings']
50
+ @data['filters'][fltr]['settings'] = {}
51
+ end
52
+ @data['filters'][fltr]['settings'][setting] = val
53
+ end
54
+
55
+ def asJSON()
56
+ json = @data.to_json
57
+ return json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
58
+ end
59
+
60
+ def as_string()
61
+ json = asJSON()
62
+ str = 'X-SMTPAPI: %s' % json.gsub(/(.{1,72})( +|$\n?)|(.{1,72})/,"\\1\\3\n")
63
+ return str
64
+ end
65
+
66
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ class TestMailer < ActionMailer::Base
4
+ def category_message
5
+ sendgrid_category "a_category"
6
+ recipients "foo@example.com"
7
+ end
8
+ def filter_message
9
+ sendgrid_filter_setting "filter", "enabled", 1
10
+ recipients "foo@example.com"
11
+ end
12
+ end
13
+
14
+ class SendGridTest < Test::Unit::TestCase
15
+
16
+ def sendgrid_options
17
+ mail = ActionMailer::Base.deliveries[0]
18
+ sendgrid_options = JSON.parse(mail["X-SMTPAPI"].to_s)
19
+ end
20
+
21
+ def test_sendgrid_category
22
+ TestMailer.deliver_category_message
23
+ assert_equal "a_category", sendgrid_options["category"]
24
+ end
25
+
26
+ def test_sendgrid_filter_settings
27
+ TestMailer.deliver_filter_message
28
+ assert_equal sendgrid_options["filters"]["filter"]["settings"]["enabled"], 1
29
+ end
30
+
31
+ def teardown
32
+ ActionMailer::Base.deliveries.clear
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'am-sendgrid'
7
+
8
+ ActionMailer::Base.template_root = File.join(File.dirname(__FILE__))
9
+ ActionMailer::Base.delivery_method = :test
10
+
@@ -0,0 +1 @@
1
+ Blah blah blah.
@@ -0,0 +1 @@
1
+ Blah blah blah.
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: am-sendgrid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Nelson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-23 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionmailer
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json_pure
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description:
36
+ email: chris@gaslightsoftware.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/am-sendgrid.rb
52
+ - lib/smtp_api_header.rb
53
+ - test/am_sendgrid_test.rb
54
+ - test/helper.rb
55
+ - test/test_mailer/category_message.html.erb
56
+ - test/test_mailer/filter_message.html.erb
57
+ has_rdoc: true
58
+ homepage: http://github.com/sharespost/am-sendgrid
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Makes it easy to call the sendgrid SMTP api from ActionMailer
85
+ test_files:
86
+ - test/am_sendgrid_test.rb
87
+ - test/helper.rb