griddler-sparkpost 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8303de5ff6f8764fbbffe72a1082592015f358c
4
+ data.tar.gz: f0be05682875dc41f5498bc2f3a0383217caa686
5
+ SHA512:
6
+ metadata.gz: 85d98edb223c41c0b80759afeaea246336a2cda98fa0a8456d9f84d8a35e2a180b7f91e43fdc29fcc5b5adf14073c093796d74b415a2a9f120424333ac0da989
7
+ data.tar.gz: 96ddd40c9b0274b520b79b797cbee98019fc62fdc8d4a6a45b599a39a91f7f63a26abed6f1e655194fab11aa3dcd1efea65fa686b9e4d70178c7fe53daf466ae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'griddler', github: 'thoughtbot/griddler'
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Kyle Powers
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,50 @@
1
+ Griddler::Sparkpost
2
+ ==================
3
+
4
+ This is an adapter that allows [Griddler](https://github.com/thoughtbot/griddler) to be used with
5
+ [SparkPost's Inbound Email Relay].
6
+
7
+ [SparkPost's Inbound Email Relay]: https://support.sparkpost.com/customer/portal/articles/2039614-enabling-inbound-email-relaying-relay-webhooks
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'griddler'
16
+ gem 'griddler-sparkpost'
17
+ ```
18
+
19
+ Usage
20
+ -----
21
+
22
+ * Coming Soon
23
+
24
+ More Information
25
+ ----------------
26
+
27
+ * [SparkPost](https://www.sparkpost.com/)
28
+ * [SparkPost's Inbound Email Relay](https://support.sparkpost.com/customer/portal/articles/2039614-enabling-inbound-email-relaying-relay-webhooks)
29
+
30
+ Credits
31
+ -------
32
+
33
+ Griddler::Sparkpost is based off of [Griddler::Sendgrid](https://github.com/thoughtbot/griddler-sendgrid) by Caleb Thompson.
34
+
35
+ Griddler was written by Caleb Thompson and Joel Oliveira.
36
+
37
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
38
+
39
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
40
+
41
+ License
42
+ -------
43
+
44
+ Griddler is Copyright © 2014 Caleb Thompson, Joel Oliveira and thoughtbot. It is
45
+ free software, and may be redistributed under the terms specified in the LICENSE
46
+ file.
47
+
48
+ Griddler::Sparkpost is Copyright © 2016 Kyle Powers and PrestoDoctor. It is free
49
+ software, and may be redistributed under the terms specified in the LICENSE
50
+ file.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'griddler/sparkpost/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'griddler-sparkpost'
8
+ spec.version = Griddler::Sparkpost::VERSION
9
+ spec.authors = ['Kyle Powers']
10
+ spec.email = ['kylepowers@gmail.com']
11
+ spec.summary = 'SparkPost adapter for Griddler'
12
+ spec.description = 'Adapter to allow the use of SparkPost Inbound Email Relay with Griddler'
13
+ spec.homepage = 'https://github.com/PrestoDoctor/griddler-sparkpost'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'rake'
21
+ spec.add_development_dependency 'rspec'
22
+
23
+ spec.add_runtime_dependency 'griddler'
24
+ spec.add_runtime_dependency 'mail'
25
+ end
@@ -0,0 +1,63 @@
1
+ require 'mail'
2
+
3
+ module Griddler
4
+ module Sparkpost
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
+ msg = params['_json'][0]['msys']['relay_message']
17
+ content = msg['content']
18
+ mail = Mail.read_from_string(content['email_rfc822'])
19
+ params.merge(
20
+ to: content['to'],
21
+ from: msg['msg_from'],
22
+ cc: content['cc'].nil? ? [] : content['cc'],
23
+ subject: content['subject'],
24
+ text: content['text'],
25
+ html: content['html'],
26
+ headers: headers_raw(content['headers']), # spec calls for raw headers, so convert back
27
+ attachments: attachment_files(mail)
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :params
34
+
35
+ def headers_raw(arr)
36
+ # sparkpost gives us an array of header maps, with just one key and value (to preserve order)
37
+ # we will convert them back to the raw headers here
38
+ arr.inject([]) { |raw_headers, obj|
39
+ raw_headers.push("#{obj.keys.first}: #{obj.values.first}")
40
+ }.join("\r\n")
41
+ end
42
+
43
+ def attachment_files(mail)
44
+ mail.attachments.map { |attachment|
45
+ ActionDispatch::Http::UploadedFile.new({
46
+ filename: attachment.filename,
47
+ type: attachment.mime_type,
48
+ tempfile: create_tempfile(attachment)
49
+ })
50
+ }
51
+ end
52
+
53
+ def create_tempfile(attachment)
54
+ filename = attachment.filename.gsub(/\/|\\/, '_')
55
+ tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit')
56
+ content = attachment.body.decoded
57
+ tempfile.write(content)
58
+ tempfile.rewind
59
+ tempfile
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module Griddler
2
+ module Sparkpost
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'griddler'
2
+ require 'griddler/sparkpost/version'
3
+ require 'griddler/sparkpost/adapter'
4
+
5
+ module Griddler
6
+ module Sparkpost
7
+ end
8
+ end
9
+
10
+ Griddler.adapter_registry.register(:sparkpost, Griddler::Sparkpost::Adapter)
Binary file
Binary file
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+ require 'active_support/all'
3
+
4
+ describe Griddler::Sparkpost::Adapter do
5
+ it 'registers itself with griddler' do
6
+ Griddler.adapter_registry[:sparkpost].should eq Griddler::Sparkpost::Adapter
7
+ end
8
+ end
9
+
10
+ describe Griddler::Sparkpost::Adapter, '.normalize_params' do
11
+ # it_should_behave_like 'Griddler adapter',
12
+ # :sparkpost,
13
+ # {
14
+ # text: 'hi',
15
+ # to: 'Hello World <hi@example.com>',
16
+ # cc: 'emily@example.com',
17
+ # from: 'There <there@example.com>',
18
+ # }
19
+
20
+ # it 'changes attachments to an array of files' do
21
+ # params = default_params.merge(
22
+ # attachments: '2',
23
+ # attachment1: upload_1,
24
+ # attachment2: upload_2,
25
+ # 'attachment-info' => <<-eojson
26
+ # {
27
+ # 'attachment2': {
28
+ # 'filename': 'photo2.jpg',
29
+ # 'name': 'photo2.jpg',
30
+ # 'type': 'image/jpeg'
31
+ # },
32
+ # 'attachment1': {
33
+ # 'filename': 'photo1.jpg',
34
+ # 'name': 'photo1.jpg',
35
+ # 'type': 'image/jpeg'
36
+ # }
37
+ # }
38
+ # eojson
39
+ # )
40
+
41
+ # normalized_params = Griddler::Sparkpost::Adapter.normalize_params(params)
42
+ # normalized_params[:attachments].should eq [upload_1, upload_2]
43
+ # normalized_params.should_not have_key(:attachment1)
44
+ # normalized_params.should_not have_key(:attachment2)
45
+ # normalized_params.should_not have_key(:attachment_info)
46
+ # end
47
+
48
+ it 'has no attachments' do
49
+ params = default_params.merge(attachments: '0')
50
+
51
+ normalized_params = Griddler::Sparkpost::Adapter.normalize_params(params)
52
+ normalized_params[:attachments].should be_empty
53
+ end
54
+
55
+ it 'wraps to in an array' do
56
+ normalized_params = Griddler::Sparkpost::Adapter.normalize_params(default_params)
57
+
58
+ normalized_params[:to].should eq default_params['_json'][0]['msys']['relay_message']['content']['to']
59
+ end
60
+
61
+ it 'wraps cc in an array' do
62
+ normalized_params = Griddler::Sparkpost::Adapter.normalize_params(default_params)
63
+
64
+ normalized_params[:cc].should eq default_params['_json'][0]['msys']['relay_message']['content']['cc']
65
+ end
66
+
67
+ it 'returns an array even if cc is empty' do
68
+ params = default_params
69
+ params['_json'][0]['msys']['relay_message']['content']['cc'] = nil
70
+ normalized_params = Griddler::Sparkpost::Adapter.normalize_params(params)
71
+
72
+ normalized_params[:cc].should eq []
73
+ end
74
+
75
+ def default_params
76
+ {
77
+ "_json": [{
78
+ "msys": {
79
+ "relay_message": {
80
+ "rcpt_to": "hi@example.com",
81
+ "friendly_from": "there@example.com",
82
+ "customer_id": "12345",
83
+ "content": {
84
+ "text": "What up what up",
85
+ "subject": "sup wit it",
86
+ "html": "<div>hello</div>",
87
+ "headers": [{
88
+ "Return-Path": "<there@example.com>"
89
+ }, {
90
+ "From": "Test User <there@example.com>"
91
+ }, {
92
+ "To": "hi@example.com"
93
+ }],
94
+ "email_rfc822": "XXX",
95
+ "email_rfc822_is_base64": false,
96
+ "to": ["hi@example.com"],
97
+ "cc": ["cc@example.com"]
98
+ },
99
+ "msg_from": "there@example.com",
100
+ "webhook_id": "123456789"
101
+ }
102
+ }
103
+ }]
104
+ }.with_indifferent_access
105
+ end
106
+ end
@@ -0,0 +1,11 @@
1
+ require 'griddler'
2
+ require 'griddler/testing'
3
+ require 'griddler/sparkpost'
4
+ require 'action_dispatch'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.order = 'random'
10
+ config.include Griddler::Testing
11
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: griddler-sparkpost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Powers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
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: griddler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: mail
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Adapter to allow the use of SparkPost Inbound Email Relay with Griddler
70
+ email:
71
+ - kylepowers@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - griddler-sparkpost.gemspec
83
+ - lib/griddler/sparkpost.rb
84
+ - lib/griddler/sparkpost/adapter.rb
85
+ - lib/griddler/sparkpost/version.rb
86
+ - spec/fixtures/photo1.jpg
87
+ - spec/fixtures/photo2.jpg
88
+ - spec/griddler/sparkpost/adapter_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/PrestoDoctor/griddler-sparkpost
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: SparkPost adapter for Griddler
114
+ test_files:
115
+ - spec/fixtures/photo1.jpg
116
+ - spec/fixtures/photo2.jpg
117
+ - spec/griddler/sparkpost/adapter_spec.rb
118
+ - spec/spec_helper.rb