griddler-sendgrid 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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +4 -0
- data/griddler-sendgrid.gemspec +24 -0
- data/lib/griddler/sendgrid.rb +10 -0
- data/lib/griddler/sendgrid/adapter.rb +39 -0
- data/lib/griddler/sendgrid/version.rb +5 -0
- data/spec/fixtures/photo1.jpg +0 -0
- data/spec/fixtures/photo2.jpg +0 -0
- data/spec/griddler/sendgrid/adapter_spec.rb +81 -0
- data/spec/spec_helper.rb +10 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be5d9a9db3c7daa2c8becdb06c09410bfeea98e1
|
4
|
+
data.tar.gz: bf3746c3b5e995637e8e54c8e2839ccd281823fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52805795500e3655a05eb660069a094348f767e44940a4182f1ec110b5a0c5793607dbbebcb1ce27d1ce5b6947fbf530327233f2604aa6eabb0dd8cd6a3bd170
|
7
|
+
data.tar.gz: 46432b91937362c31bc53aa4b62609d823bb7812e2f396c4ec38da585dac8d78bb360c699d99de6f799aeb996e8cf8422bc641221b405f38a3e2871b0ffcf816
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Caleb Thompson
|
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,54 @@
|
|
1
|
+
Griddler::Sendgrid
|
2
|
+
==================
|
3
|
+
|
4
|
+
This is an adapter that allows [Griddler](/thoughtbot/griddler) to be used with
|
5
|
+
[SendGrid's Parse API].
|
6
|
+
|
7
|
+
[SendGrid's Parse API]: http://sendgrid.com/docs/API%20Reference/Webhooks/parse.html
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'griddler'
|
16
|
+
gem 'griddler-sendgrid'
|
17
|
+
```
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
* SendGrid has done a [great
|
23
|
+
tutorial](http://blog.sendgrid.com/receiving-email-in-your-rails-app-with-griddler/)
|
24
|
+
on integrating Griddler with your application.
|
25
|
+
* And of course, view our own blog post on the subject over at [Giant
|
26
|
+
Robots](http://robots.thoughtbot.com/handle-incoming-email-with-griddler).
|
27
|
+
|
28
|
+
More Information
|
29
|
+
----------------
|
30
|
+
|
31
|
+
* [SendGrid](http://www.sendgrid.com)
|
32
|
+
* [SendGrid Parse API](http://www.sendgrid.com/docs/API Reference/Webhooks/parse.html)
|
33
|
+
|
34
|
+
Credits
|
35
|
+
-------
|
36
|
+
|
37
|
+
Griddler::Sendgrid was extracted from Griddler.
|
38
|
+
|
39
|
+
Griddler was written by Caleb Thompson and Joel Oliveira.
|
40
|
+
|
41
|
+

|
42
|
+
|
43
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
44
|
+
|
45
|
+
License
|
46
|
+
-------
|
47
|
+
|
48
|
+
Griddler is Copyright © 2014 Caleb Thompson, Joel Oliveira and thoughtbot. It is
|
49
|
+
free software, and may be redistributed under the terms specified in the LICENSE
|
50
|
+
file.
|
51
|
+
|
52
|
+
Griddler::Sendgrid is Copyright © 2014 Caleb Thompson and thoughtbot. It is free
|
53
|
+
software, and may be redistributed under the terms specified in the LICENSE
|
54
|
+
file.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'griddler/sendgrid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'griddler-sendgrid'
|
8
|
+
spec.version = Griddler::Sendgrid::VERSION
|
9
|
+
spec.authors = ['Caleb Thompson']
|
10
|
+
spec.email = ['caleb@calebthompson.io']
|
11
|
+
spec.summary = 'SendGrid adapter for Griddler'
|
12
|
+
spec.description = 'Adapter to allow the use of SendGrid Parse API with Griddler'
|
13
|
+
spec.homepage = 'https://github.com/thoughtbot/griddler'
|
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_dependency 'griddler'
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Griddler
|
2
|
+
module Sendgrid
|
3
|
+
class Adapter
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.normalize_params(params)
|
9
|
+
adapter = new(params)
|
10
|
+
adapter.normalize_params
|
11
|
+
end
|
12
|
+
|
13
|
+
def normalize_params
|
14
|
+
params.merge(
|
15
|
+
to: recipients(:to),
|
16
|
+
cc: recipients(:cc),
|
17
|
+
attachments: attachment_files,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :params
|
24
|
+
|
25
|
+
def recipients(key)
|
26
|
+
( params[key] || '' ).split(',')
|
27
|
+
end
|
28
|
+
|
29
|
+
def attachment_files
|
30
|
+
params.delete('attachment-info')
|
31
|
+
attachment_count = params[:attachments].to_i
|
32
|
+
|
33
|
+
attachment_count.times.map do |index|
|
34
|
+
params.delete("attachment#{index + 1}".to_sym)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Griddler::Sendgrid::Adapter do
|
4
|
+
it 'registers itself with griddler' do
|
5
|
+
Griddler.adapter_registry[:sendgrid].should eq Griddler::Sendgrid::Adapter
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Griddler::Sendgrid::Adapter, '.normalize_params' do
|
10
|
+
it_should_behave_like 'Griddler adapter',
|
11
|
+
:sendgrid,
|
12
|
+
{
|
13
|
+
text: 'hi',
|
14
|
+
to: 'Hello World <hi@example.com>',
|
15
|
+
cc: 'emily@example.com',
|
16
|
+
from: 'There <there@example.com>',
|
17
|
+
}
|
18
|
+
|
19
|
+
it 'changes attachments to an array of files' do
|
20
|
+
params = default_params.merge(
|
21
|
+
attachments: '2',
|
22
|
+
attachment1: upload_1,
|
23
|
+
attachment2: upload_2,
|
24
|
+
'attachment-info' => <<-eojson
|
25
|
+
{
|
26
|
+
'attachment2': {
|
27
|
+
'filename': 'photo2.jpg',
|
28
|
+
'name': 'photo2.jpg',
|
29
|
+
'type': 'image/jpeg'
|
30
|
+
},
|
31
|
+
'attachment1': {
|
32
|
+
'filename': 'photo1.jpg',
|
33
|
+
'name': 'photo1.jpg',
|
34
|
+
'type': 'image/jpeg'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
eojson
|
38
|
+
)
|
39
|
+
|
40
|
+
normalized_params = normalize_params(params)
|
41
|
+
normalized_params[:attachments].should eq [upload_1, upload_2]
|
42
|
+
normalized_params.should_not have_key(:attachment1)
|
43
|
+
normalized_params.should_not have_key(:attachment2)
|
44
|
+
normalized_params.should_not have_key(:attachment_info)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'has no attachments' do
|
48
|
+
params = default_params.merge(attachments: '0')
|
49
|
+
|
50
|
+
normalized_params = normalize_params(params)
|
51
|
+
normalized_params[:attachments].should be_empty
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'wraps to in an array' do
|
55
|
+
normalized_params = normalize_params(default_params)
|
56
|
+
|
57
|
+
normalized_params[:to].should eq [default_params[:to]]
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'wraps cc in an array' do
|
61
|
+
normalized_params = normalize_params(default_params)
|
62
|
+
|
63
|
+
normalized_params[:cc].should eq [default_params[:cc]]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns an array even if cc is empty' do
|
67
|
+
params = default_params.merge(cc: nil)
|
68
|
+
normalized_params = normalize_params(params)
|
69
|
+
|
70
|
+
normalized_params[:cc].should eq []
|
71
|
+
end
|
72
|
+
|
73
|
+
def default_params
|
74
|
+
{
|
75
|
+
text: 'hi',
|
76
|
+
to: 'hi@example.com',
|
77
|
+
cc: 'cc@example.com',
|
78
|
+
from: 'there@example.com',
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'griddler/testing'
|
2
|
+
require 'griddler/sendgrid'
|
3
|
+
require 'action_dispatch'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.order = 'random'
|
9
|
+
config.include Griddler::Testing
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: griddler-sendgrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Thompson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-16 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
|
+
description: Adapter to allow the use of SendGrid Parse API with Griddler
|
56
|
+
email:
|
57
|
+
- caleb@calebthompson.io
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- griddler-sendgrid.gemspec
|
69
|
+
- lib/griddler/sendgrid.rb
|
70
|
+
- lib/griddler/sendgrid/adapter.rb
|
71
|
+
- lib/griddler/sendgrid/version.rb
|
72
|
+
- spec/fixtures/photo1.jpg
|
73
|
+
- spec/fixtures/photo2.jpg
|
74
|
+
- spec/griddler/sendgrid/adapter_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/thoughtbot/griddler
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: SendGrid adapter for Griddler
|
100
|
+
test_files:
|
101
|
+
- spec/fixtures/photo1.jpg
|
102
|
+
- spec/fixtures/photo2.jpg
|
103
|
+
- spec/griddler/sendgrid/adapter_spec.rb
|
104
|
+
- spec/spec_helper.rb
|