griddler-postmark 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +23 -0
- data/README.md +32 -0
- data/Rakefile +5 -0
- data/griddler-postmark.gemspec +27 -0
- data/lib/griddler/postmark.rb +5 -0
- data/lib/griddler/postmark/adapter.rb +65 -0
- data/lib/griddler/postmark/version.rb +5 -0
- data/spec/fixtures/photo1.jpg +0 -0
- data/spec/fixtures/photo2.jpg +0 -0
- data/spec/griddler/postmark/adapter_spec.rb +142 -0
- data/spec/spec_helper.rb +9 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 737c4e094694dd517c842144def66630e0c4ace0
|
4
|
+
data.tar.gz: 45ec7c15513278a65d7661fde4b5462401f4a9f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af37ca3572747f31243ec66fade7f8f0090d8b6c8d9cf88a54466cfb17b58aa7550569574cb0e1dbe5f322760a4cec314144120f0ba59600df24cdfd8040e97a
|
7
|
+
data.tar.gz: 6b7c8b3f1e8bc5de87250dfe4cdcdfde22d30a8b4ea95467e9d87df72e76500d304848b38ed316a40f3f7e3771196ffaa97860b00de3b0b74733cf67142b0cca
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2014 Randy Schmidt
|
2
|
+
Portions copyright (c) 2014 Caleb Thompson, Joel Oliveira and thoughtbot, inc.
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Griddler::Postmark
|
2
|
+
|
3
|
+
An adapter for [Griddler](https://github.com/thoughtbot/griddler) to allow
|
4
|
+
[Postmark](http://developer.postmarkapp.com/developer-inbound-parse.html) to be
|
5
|
+
used with the gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'griddler'
|
13
|
+
gem 'griddler-postmark'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Create an initializer with the following settings:
|
19
|
+
|
20
|
+
```
|
21
|
+
Griddler.configure do |config|
|
22
|
+
config.email_service = :postmark
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Then configure Postmark to use the endpoint specified in Griddler's
|
27
|
+
docs.
|
28
|
+
|
29
|
+
## More Information
|
30
|
+
|
31
|
+
* [Postmark](http://postmarkapp.com)
|
32
|
+
* [Postmark Docs](http://developer.postmarkapp.com/)
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'griddler/postmark/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "griddler-postmark"
|
8
|
+
spec.version = Griddler::Postmark::VERSION
|
9
|
+
spec.authors = ['Randy Schmidt']
|
10
|
+
spec.email = ['me@r38y.com']
|
11
|
+
spec.summary = %q{Postmark adapter for Griddler}
|
12
|
+
spec.description = %q{Adapter to allow the use of Postmark Parse API with Griddler}
|
13
|
+
spec.homepage = "https://github.com/r38y/griddler-postmark"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_dependency "griddler"
|
27
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'active_support/core_ext/string/strip'
|
2
|
+
|
3
|
+
module Griddler
|
4
|
+
module Postmark
|
5
|
+
class Adapter
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.normalize_params(params)
|
11
|
+
adapter = new(params)
|
12
|
+
adapter.normalize_params
|
13
|
+
end
|
14
|
+
|
15
|
+
def normalize_params
|
16
|
+
{
|
17
|
+
to: extract_recipients(:ToFull),
|
18
|
+
cc: extract_recipients(:CcFull),
|
19
|
+
from: full_email(params[:FromFull]),
|
20
|
+
subject: params[:Subject],
|
21
|
+
text: params[:TextBody],
|
22
|
+
html: params[:HtmlBody],
|
23
|
+
attachments: attachment_files,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :params
|
30
|
+
|
31
|
+
def extract_recipients(key)
|
32
|
+
params[key].to_a.map { |recipient| full_email(recipient) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_email(contact_info)
|
36
|
+
email = contact_info[:Email]
|
37
|
+
if contact_info[:Name].present?
|
38
|
+
"#{contact_info[:Name]} <#{email}>"
|
39
|
+
else
|
40
|
+
email
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def attachment_files
|
45
|
+
attachments = Array(params[:Attachments])
|
46
|
+
|
47
|
+
attachments.map do |attachment|
|
48
|
+
ActionDispatch::Http::UploadedFile.new({
|
49
|
+
filename: attachment[:Name],
|
50
|
+
type: attachment[:ContentType],
|
51
|
+
tempfile: create_tempfile(attachment)
|
52
|
+
})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_tempfile(attachment)
|
57
|
+
filename = attachment[:Name]
|
58
|
+
tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit')
|
59
|
+
tempfile.write(Base64.decode64(attachment[:Content]))
|
60
|
+
tempfile.rewind
|
61
|
+
tempfile
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Griddler::Postmark::Adapter, '.normalize_params' do
|
4
|
+
it_should_behave_like 'Griddler adapter', :postmark,
|
5
|
+
{
|
6
|
+
FromFull: {
|
7
|
+
Email: 'there@example.com',
|
8
|
+
Name: 'There',
|
9
|
+
},
|
10
|
+
ToFull: [{
|
11
|
+
Email: 'hi@example.com',
|
12
|
+
Name: 'Hello World',
|
13
|
+
}],
|
14
|
+
CcFull: [{
|
15
|
+
Email: 'emily@example.com',
|
16
|
+
Name: '',
|
17
|
+
}],
|
18
|
+
TextBody: 'hi',
|
19
|
+
}
|
20
|
+
|
21
|
+
it 'normalizes parameters' do
|
22
|
+
expect(Griddler::Postmark::Adapter.normalize_params(default_params)).to be_normalized_to({
|
23
|
+
to: ['Robert Paulson <bob@example.com>'],
|
24
|
+
cc: ['Jack <jack@example.com>'],
|
25
|
+
from: 'Tyler Durden <tdurden@example.com>',
|
26
|
+
subject: 'Reminder: First and Second Rule',
|
27
|
+
text: /Dear bob/,
|
28
|
+
html: %r{<p>Dear bob</p>}
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'handles CcFull of nil' do
|
33
|
+
no_cc_params = default_params
|
34
|
+
no_cc_params[:CcFull] = nil
|
35
|
+
normalized = Griddler::Postmark::Adapter.normalize_params(no_cc_params)
|
36
|
+
|
37
|
+
expect(normalized[:cc]).to eq []
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'passes the received array of files' do
|
41
|
+
params = default_params.merge({ Attachments: [upload_1_params, upload_2_params] })
|
42
|
+
|
43
|
+
normalized_params = Griddler::Postmark::Adapter.normalize_params(params)
|
44
|
+
|
45
|
+
first, second = *normalized_params[:attachments]
|
46
|
+
|
47
|
+
first.original_filename.should eq('photo1.jpg')
|
48
|
+
expect(first.size).to eq(upload_1_params[:ContentLength])
|
49
|
+
|
50
|
+
second.original_filename.should eq('photo2.jpg')
|
51
|
+
expect(second.size).to eq(upload_2_params[:ContentLength])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has no attachments' do
|
55
|
+
params = default_params
|
56
|
+
|
57
|
+
normalized_params = Griddler::Postmark::Adapter.normalize_params(params)
|
58
|
+
|
59
|
+
expect(normalized_params[:attachments]).to be_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'gets rid of the original postmark params' do
|
63
|
+
expect(Griddler::Postmark::Adapter.normalize_params(default_params)).to be_normalized_to({
|
64
|
+
ToFull: nil,
|
65
|
+
FromFull: nil,
|
66
|
+
CcFull: nil,
|
67
|
+
Subject: nil,
|
68
|
+
TextBody: nil,
|
69
|
+
HtmlBody: nil,
|
70
|
+
Attachments: nil
|
71
|
+
})
|
72
|
+
end
|
73
|
+
|
74
|
+
def default_params
|
75
|
+
{
|
76
|
+
FromFull: {
|
77
|
+
Email: 'tdurden@example.com',
|
78
|
+
Name: 'Tyler Durden'
|
79
|
+
},
|
80
|
+
ToFull: [{
|
81
|
+
Email: 'bob@example.com',
|
82
|
+
Name: 'Robert Paulson'
|
83
|
+
}],
|
84
|
+
CcFull: [{
|
85
|
+
Email: 'jack@example.com',
|
86
|
+
Name: 'Jack'
|
87
|
+
}],
|
88
|
+
Subject: 'Reminder: First and Second Rule',
|
89
|
+
TextBody: text_body,
|
90
|
+
HtmlBody: text_html
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def text_body
|
95
|
+
<<-EOS.strip_heredoc.strip
|
96
|
+
Dear bob
|
97
|
+
|
98
|
+
Reply ABOVE THIS LINE
|
99
|
+
|
100
|
+
hey sup
|
101
|
+
EOS
|
102
|
+
end
|
103
|
+
|
104
|
+
def text_html
|
105
|
+
<<-EOS.strip_heredoc.strip
|
106
|
+
<p>Dear bob</p>
|
107
|
+
|
108
|
+
Reply ABOVE THIS LINE
|
109
|
+
|
110
|
+
hey sup
|
111
|
+
EOS
|
112
|
+
end
|
113
|
+
|
114
|
+
def upload_1_params
|
115
|
+
@upload_1_params ||= begin
|
116
|
+
file = fixture_file('photo1.jpg')
|
117
|
+
{
|
118
|
+
Name: 'photo1.jpg',
|
119
|
+
Content: Base64.encode64(file.read),
|
120
|
+
ContentType: 'image/jpeg',
|
121
|
+
ContentLength: file.size
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def upload_2_params
|
127
|
+
@upload_2_params ||= begin
|
128
|
+
file = fixture_file('photo2.jpg')
|
129
|
+
{
|
130
|
+
Name: 'photo2.jpg',
|
131
|
+
Content: Base64.encode64(file.read),
|
132
|
+
ContentType: 'image/jpeg',
|
133
|
+
ContentLength: file.size
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def fixture_file(name)
|
139
|
+
cwd = File.expand_path File.dirname(__FILE__)
|
140
|
+
File.new(File.join(cwd, '..', '..', 'fixtures', name))
|
141
|
+
end
|
142
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: griddler-postmark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randy Schmidt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: griddler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Adapter to allow the use of Postmark Parse API with Griddler
|
84
|
+
email:
|
85
|
+
- me@r38y.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- griddler-postmark.gemspec
|
98
|
+
- lib/griddler/postmark.rb
|
99
|
+
- lib/griddler/postmark/adapter.rb
|
100
|
+
- lib/griddler/postmark/version.rb
|
101
|
+
- spec/fixtures/photo1.jpg
|
102
|
+
- spec/fixtures/photo2.jpg
|
103
|
+
- spec/griddler/postmark/adapter_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/r38y/griddler-postmark
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.0
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Postmark adapter for Griddler
|
129
|
+
test_files:
|
130
|
+
- spec/fixtures/photo1.jpg
|
131
|
+
- spec/fixtures/photo2.jpg
|
132
|
+
- spec/griddler/postmark/adapter_spec.rb
|
133
|
+
- spec/spec_helper.rb
|