griddler-sendgrid 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4b568d22d80b71487ec2d7b13f4c454ce5795908
4
- data.tar.gz: a7891f96d709940be229de73879869907a537a03
2
+ SHA256:
3
+ metadata.gz: 65ae6c3ebf35cf02589f969037d6d460e1081283d0cf12eaef22870a5ac2578e
4
+ data.tar.gz: c3d1e54b5de5a4ddb9e2d37f44e78f80d32e25a7e2ce3ef0e6da24a302b8b793
5
5
  SHA512:
6
- metadata.gz: 6250647638cd35e7c6cb4d4c2ad3268599f0ac2c8a0e5964bdf222b9085f9727f0368ffb47833bf8800b2232d87925881a99d575e44b98cfee5a8339beb27405
7
- data.tar.gz: 5826f196ea5320f164c3a693f3795705e1748bddea5d64a1c5c67553b00fbc4b902fd24f39cad8ef7b8ad327383bc7075a2a45c0a75617178ee504f09c94fbd1
6
+ metadata.gz: 1989291c64a64e26680b7d0f0c1062405acc1e83046e00c62c62c372d1999a3710af0c0b2322de322d3ef4f1b232e49e42edc4a2dab015e0f16b28fa9b4d0ded
7
+ data.tar.gz: 467cefd0678c4f72db660121594da6d658f7885dd7273e59ec5f268513d5b28c0c604915d32dda867854d45ff216d6b0e9510c4db84aeb39fc379508d78aa20b
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## HEAD (unreleased)
2
+
3
+ ## 1.1.0
4
+ * Expose charsets as Hash in normalized params ([#29](https://github.com/thoughtbot/griddler-sendgrid/pull/29/))
5
+ * Add support for Sendgrid spam check ([#30](https://github.com/thoughtbot/griddler-sendgrid/pull/30))
6
+ * Set minimum version of `mail` to be `2.7.0` so that UTF-8 encoded emails continue to work properly
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency 'rake'
21
21
  spec.add_development_dependency 'rspec', '~> 3.5'
22
22
 
23
- spec.add_dependency 'griddler'
23
+ spec.add_dependency 'griddler', '>= 1.5.2'
24
+ spec.add_dependency 'mail', '>= 2.7.0'
24
25
  end
@@ -16,6 +16,12 @@ module Griddler
16
16
  cc: recipients(:cc).map(&:format),
17
17
  bcc: get_bcc,
18
18
  attachments: attachment_files,
19
+ charsets: charsets,
20
+ spam_report: {
21
+ report: params[:spam_report],
22
+ score: params[:spam_score],
23
+ }
24
+
19
25
  )
20
26
  end
21
27
 
@@ -24,8 +30,7 @@ module Griddler
24
30
  attr_reader :params
25
31
 
26
32
  def recipients(key)
27
- encoded = Mail::Encodings.address_encode(params[key] || '')
28
- Mail::AddressList.new(encoded).addresses
33
+ Mail::AddressList.new(params[key] || '').addresses
29
34
  end
30
35
 
31
36
  def get_bcc
@@ -40,6 +45,14 @@ module Griddler
40
45
  JSON.parse(params[:envelope])["to"] if params[:envelope].present?
41
46
  end
42
47
 
48
+ def charsets
49
+ return {} unless params[:charsets].present?
50
+ JSON.parse(params[:charsets]).symbolize_keys
51
+ rescue JSON::ParserError
52
+ {}
53
+ end
54
+
55
+
43
56
  def attachment_files
44
57
  attachment_count.times.map do |index|
45
58
  extract_file_at(index)
@@ -1,5 +1,5 @@
1
1
  module Griddler
2
2
  module Sendgrid
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ describe Griddler::Sendgrid::Adapter, '.normalize_params' do
14
14
  to: 'Hello World <hi@example.com>',
15
15
  cc: 'emily@example.com',
16
16
  from: 'There <there@example.com>',
17
+ charsets: { to: 'UTF-8', text: 'iso-8859-1' }.to_json
17
18
  }
18
19
 
19
20
  it 'changes attachments to an array of files' do
@@ -129,6 +130,35 @@ describe Griddler::Sendgrid::Adapter, '.normalize_params' do
129
130
  normalized_params[:bcc].should eq []
130
131
  end
131
132
 
133
+ it 'returns the charsets as a hash' do
134
+ normalized_params = normalize_params(default_params)
135
+ charsets = normalized_params[:charsets]
136
+
137
+ charsets.should be_present
138
+ charsets[:text].should eq 'iso-8859-1'
139
+ charsets[:to].should eq 'UTF-8'
140
+ end
141
+
142
+ it 'does not explode if charsets is not JSON-able' do
143
+ params = default_params.merge(charsets: 'This is not JSON')
144
+
145
+ normalize_params(params)[:charsets].should eq({})
146
+ end
147
+
148
+ it 'defaults charsets to an empty hash if it is not specified in params' do
149
+ params = default_params.except(:charsets)
150
+ normalize_params(params)[:charsets].should eq({})
151
+ end
152
+
153
+ it 'normalizes the spam report into a griddler friendly format' do
154
+ normalized_params = normalize_params(default_params)
155
+
156
+ normalized_params[:spam_report].should eq({
157
+ score: '1.234',
158
+ report: 'Some spam report',
159
+ })
160
+ end
161
+
132
162
  def default_params
133
163
  {
134
164
  text: 'hi',
@@ -136,6 +166,9 @@ describe Griddler::Sendgrid::Adapter, '.normalize_params' do
136
166
  cc: 'cc@example.com',
137
167
  from: 'there@example.com',
138
168
  envelope: "{\"to\":[\"johny@example.com\"], \"from\": [\"there@example.com\"]}",
169
+ charsets: { to: 'UTF-8', text: 'iso-8859-1' }.to_json,
170
+ spam_score: '1.234',
171
+ spam_report: 'Some spam report'
139
172
  }
140
173
  end
141
174
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Griddler::Email, '#to_h' do
4
+ it 'accepts normalized params from Griddler::Sendgrid::Adapter' do
5
+ normalized_params = Griddler::Sendgrid::Adapter.normalize_params(default_params)
6
+ email = Griddler::Email.new(normalized_params)
7
+
8
+ email_properties = email.to_h
9
+
10
+ expect(email_properties[:subject]).to eq 'Some subject'
11
+ expect(email_properties[:spam_score]).to eq '1.234'
12
+ end
13
+
14
+ def default_params
15
+ {
16
+ subject: 'Some subject',
17
+ text: 'hi',
18
+ to: '"Mr Fugushima at Fugu, Inc" <hi@example.com>, Foo bar <foo@example.com>, Eichhörnchen <squirrel@example.com>, <no-name@example.com>',
19
+ cc: 'cc@example.com',
20
+ from: 'there@example.com',
21
+ envelope: "{\"to\":[\"johny@example.com\"], \"from\": [\"there@example.com\"]}",
22
+ spam_score: '1.234',
23
+ spam_report: 'Some spam report',
24
+ }
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griddler-sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2018-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.5.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.5.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: mail
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.7.0
55
69
  description: Adapter to allow the use of SendGrid Parse API with Griddler
56
70
  email:
57
71
  - caleb@calebthompson.io
@@ -61,6 +75,7 @@ extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
63
77
  - ".rspec"
78
+ - CHANGELOG.md
64
79
  - Gemfile
65
80
  - LICENSE.txt
66
81
  - README.md
@@ -72,6 +87,7 @@ files:
72
87
  - spec/fixtures/photo1.jpg
73
88
  - spec/fixtures/photo2.jpg
74
89
  - spec/griddler/sendgrid/adapter_spec.rb
90
+ - spec/integration/email_spec.rb
75
91
  - spec/spec_helper.rb
76
92
  homepage: https://github.com/thoughtbot/griddler
77
93
  licenses:
@@ -93,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
109
  version: '0'
94
110
  requirements: []
95
111
  rubyforge_project:
96
- rubygems_version: 2.6.11
112
+ rubygems_version: 2.7.3
97
113
  signing_key:
98
114
  specification_version: 4
99
115
  summary: SendGrid adapter for Griddler
@@ -101,4 +117,5 @@ test_files:
101
117
  - spec/fixtures/photo1.jpg
102
118
  - spec/fixtures/photo2.jpg
103
119
  - spec/griddler/sendgrid/adapter_spec.rb
120
+ - spec/integration/email_spec.rb
104
121
  - spec/spec_helper.rb