metaforce-delivery_method 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ dummy
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salesforce_delivery_method.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Eric J. Holmes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Metaforce Delivery Method
2
+
3
+ A delivery method for the [Mail](https://github.com/mikel/mail) gem using
4
+ [Metaforce#send\_email](https://github.com/ejholmes/metaforce) as a backend.
5
+
6
+ ## Rails Setup
7
+
8
+ Add the gem to your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'metaforce-delivery_method'
12
+ ```
13
+
14
+ Add the following to your config/application.rb:
15
+
16
+ ```ruby
17
+ config.action_mailer.metaforce_settings = {
18
+ :client => Metaforce.new(
19
+ username: 'username',
20
+ password: 'passwrod',
21
+ security_token: 'securty token'
22
+ )
23
+ }
24
+ config.action_mailer.delivery_method = :metaforce
25
+ ```
26
+
27
+ Then use mailers just like you would with any other delivery method:
28
+
29
+ ```ruby
30
+ # app/mailers/user_mailer.rb
31
+ class UserMailer < ActionMailer::Base
32
+ default from: "from@example.com"
33
+
34
+ def welcome_email
35
+ mail(to: 'foo@example.com', subject: 'Welcome!')
36
+ end
37
+ end
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => [:spec]
5
+
6
+ require 'rspec/core/rake_task'
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
@@ -0,0 +1,5 @@
1
+ module Metaforce
2
+ class DeliveryMethod::Railtie < Rails::Railtie
3
+ ActionMailer::Base.add_delivery_method :metaforce, Metaforce::DeliveryMethod
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Metaforce
2
+ class DeliveryMethod
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ module Metaforce
2
+ class DeliveryMethod
3
+ attr_accessor :settings
4
+ attr_accessor :client
5
+
6
+ def initialize(options = {})
7
+ self.settings = options
8
+ self.client = settings[:client]
9
+ end
10
+
11
+ def deliver!(mail)
12
+ options = {
13
+ to_addresses: Array(mail.to),
14
+ cc_addresses: Array(mail.cc),
15
+ bcc_addresses: Array(mail.bcc),
16
+ reply_to: mail.reply_to,
17
+ subject: mail.subject,
18
+ }
19
+ if mail.multipart?
20
+ options.merge!(plain_text_body: mail.text_part.to_s, html_body: mail.html_part.to_s)
21
+ else
22
+ options.merge!(plain_text_body: mail.body.to_s)
23
+ end
24
+ client.send_email options
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require 'metaforce_delivery_method'
@@ -0,0 +1,5 @@
1
+ require 'metaforce'
2
+
3
+ require 'metaforce/delivery_method/version'
4
+ require 'metaforce/delivery_method'
5
+ require 'metaforce/delivery_method/railtie' if defined? Rails
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'metaforce/delivery_method/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'metaforce-delivery_method'
8
+ gem.version = Metaforce::DeliveryMethod::VERSION
9
+ gem.authors = ['Eric J. Holmes']
10
+ gem.email = ['eric@ejholmes.net']
11
+ gem.description = %q{Delivery method for sending emails from Ruby using Salesforce}
12
+ gem.summary = %q{Delivery method for sending emails from Ruby using Salesforce}
13
+ gem.homepage = 'https://github.com/ejholmes/metaforce-delivery_method'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'metaforce', '~> 1.0.0'
21
+
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'mail'
24
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metaforce::DeliveryMethod do
4
+ let(:client) { double('metaforce client') }
5
+
6
+ before do
7
+ context = self
8
+ Mail.defaults do
9
+ delivery_method Metaforce::DeliveryMethod, :client => context.client
10
+ end
11
+ end
12
+
13
+ context 'content' do
14
+ context 'plain' do
15
+ it 'sends the email' do
16
+ client.should_receive(:send_email).with(
17
+ :to_addresses => ['Bar bar@example.com'],
18
+ :cc_addresses => ['barfoo barfoo@example.com'],
19
+ :bcc_addresses => ['foobar foobar@example.com'],
20
+ :reply_to => 'No Reply no-reply@example.com',
21
+ :subject => 'Hello',
22
+ :plain_text_body => 'World!'
23
+ )
24
+ Mail.deliver do
25
+ from 'foo foo@example.com'
26
+ reply_to 'No Reply no-reply@example.com'
27
+ bcc 'foobar foobar@example.com'
28
+ cc 'barfoo barfoo@example.com'
29
+ to 'Bar bar@example.com'
30
+ subject 'Hello'
31
+ body 'World!'
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'html' do
37
+ it 'sends the email' do
38
+ client.should_receive(:send_email).with(
39
+ :to_addresses => ['Bar bar@example.com'],
40
+ :reply_to => 'No Reply no-reply@example.com',
41
+ :cc_addresses => [],
42
+ :bcc_addresses => [],
43
+ :subject => 'Hello',
44
+ :plain_text_body => kind_of(String),
45
+ :html_body => kind_of(String)
46
+ )
47
+ Mail.deliver do
48
+ from 'foo foo@example.com'
49
+ reply_to 'No Reply no-reply@example.com'
50
+ to 'Bar bar@example.com'
51
+ subject 'Hello'
52
+ text_part do
53
+ body 'World!'
54
+ end
55
+ html_part do
56
+ content_type 'text/html; charset=UTF-8'
57
+ body '<h1>This is HTML</h1>'
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default)
4
+
5
+ require 'mail'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metaforce-delivery_method
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric J. Holmes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: metaforce
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
47
+ name: mail
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Delivery method for sending emails from Ruby using Salesforce
63
+ email:
64
+ - eric@ejholmes.net
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/metaforce-delivery_method.rb
77
+ - lib/metaforce/delivery_method.rb
78
+ - lib/metaforce/delivery_method/railtie.rb
79
+ - lib/metaforce/delivery_method/version.rb
80
+ - lib/metaforce_delivery_method.rb
81
+ - metaforce-delivery_method.gemspec
82
+ - spec/lib/delivery_method_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: https://github.com/ejholmes/metaforce-delivery_method
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2949014550329778468
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -2949014550329778468
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.23
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Delivery method for sending emails from Ruby using Salesforce
114
+ test_files:
115
+ - spec/lib/delivery_method_spec.rb
116
+ - spec/spec_helper.rb