From 4af25f6ee07fb3b0a3b4dfbb5f46b0528e994b65 Mon Sep 17 00:00:00 2001 From: Josh Thompson Date: Sat, 8 Jun 2019 17:20:40 -0600 Subject: [PATCH 1/5] Update README with example params submission --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 1a67d18..756eab5 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,38 @@ Action: forward("http://example.com/email_processor") ``` +#### Notes on testing + +If you want to test the functionality of the route, via `rspec` or `minitest` or in Postman, please note that the `to`, `from`, `bcc` and `cc` params you post _must_ be capitalized: + +This would _not_ work: + +```json +{ + "recipient": "recipient@domain.com", + "from": "this wont work ", + "to": "to@domain.com", + "subject": "griddler-mailgun", + "body-plain": "This is some text body", + "body-html": "Supports HTML as well." +} +``` + +On the other hand, this would: + +```json +{ + "recipient": "recipient@domain.com", + "From": "this wont work ", + "To": "to@domain.com", + "subject": "griddler-mailgun", + "body-plain": "This is some text body", + "body-html": "Supports HTML as well." +} +``` +You can explore the expected fields and capitalizations in the [`Griddler::Mailgun::Adapter#normalize_params`](https://github.com/bradpauly/griddler-mailgun/blob/master/lib/griddler/mailgun/adapter.rb#L15) method. + + ## More Information * [mailgun](http://www.mailgun.com) From 8e6afb33ea0302b26cfc086622e97fb0e9b2fbb0 Mon Sep 17 00:00:00 2001 From: Josh Thompson Date: Thu, 27 Jun 2019 19:13:38 -0600 Subject: [PATCH 2/5] failing test for downcased params --- spec/griddler/mailgun/adapter_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/griddler/mailgun/adapter_spec.rb b/spec/griddler/mailgun/adapter_spec.rb index bf78fb9..d066641 100644 --- a/spec/griddler/mailgun/adapter_spec.rb +++ b/spec/griddler/mailgun/adapter_spec.rb @@ -77,6 +77,17 @@ normalized_params = Griddler::Mailgun::Adapter.normalize_params(short_params) expect(normalized_params[:to]).to eq ['johndoe@example.com'] end + + it 'handles downcased params' do + downcased_params = { + cc: "Brandon Stark , Arya Stark ", + from: "Jon Snow ", + subject: "multiple recipients and CCs", + to: "John Doe , Jane Doe " + } + Griddler::Mailgun::Adapter.normalize_params(downcased_params) + expect(normalized_params[:to].to eq['johndoe@example.com']) + end it 'handles message-headers' do params = default_params.merge( From e9729faa5fef2aa844dda628995d986d1686000c Mon Sep 17 00:00:00 2001 From: Josh Thompson Date: Thu, 27 Jun 2019 19:52:34 -0600 Subject: [PATCH 3/5] downcasing all params, as well as references to the new downcased keys --- lib/griddler/mailgun/adapter.rb | 12 ++++++------ spec/griddler/mailgun/adapter_spec.rb | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/griddler/mailgun/adapter.rb b/lib/griddler/mailgun/adapter.rb index de98a25..6227729 100644 --- a/lib/griddler/mailgun/adapter.rb +++ b/lib/griddler/mailgun/adapter.rb @@ -4,7 +4,7 @@ class Adapter attr_reader :params def initialize(params) - @params = params + @params = params.transform_keys(&:downcase) end def self.normalize_params(params) @@ -16,7 +16,7 @@ def normalize_params { to: to_recipients, cc: cc_recipients, - bcc: Array.wrap(param_or_header(:Bcc)), + bcc: Array.wrap(param_or_header(:bcc)), from: determine_sender, subject: params[:subject], text: params['body-plain'], @@ -34,23 +34,23 @@ def normalize_params private def determine_sender - sender = param_or_header(:From) + sender = param_or_header(:from) sender ||= params[:sender] end def to_recipients - to_emails = param_or_header(:To) + to_emails = param_or_header(:to) to_emails ||= params[:recipient] to_emails.split(',').map(&:strip) end def cc_recipients - cc = param_or_header(:Cc) || '' + cc = param_or_header(:cc) || '' cc.split(',').map(&:strip) end def headers - @headers ||= extract_headers + @headers ||= extract_headers.transform_keys(&:downcase) end def extract_headers diff --git a/spec/griddler/mailgun/adapter_spec.rb b/spec/griddler/mailgun/adapter_spec.rb index d066641..0245ea3 100644 --- a/spec/griddler/mailgun/adapter_spec.rb +++ b/spec/griddler/mailgun/adapter_spec.rb @@ -80,13 +80,10 @@ it 'handles downcased params' do downcased_params = { - cc: "Brandon Stark , Arya Stark ", - from: "Jon Snow ", - subject: "multiple recipients and CCs", - to: "John Doe , Jane Doe " + to: "John Doe " } - Griddler::Mailgun::Adapter.normalize_params(downcased_params) - expect(normalized_params[:to].to eq['johndoe@example.com']) + normalized_params = Griddler::Mailgun::Adapter.normalize_params(downcased_params) + expect(normalized_params[:to]).to eq ['John Doe '] end it 'handles message-headers' do From eea3bc0db380d2bc846ff242b24e1bea7b715f65 Mon Sep 17 00:00:00 2001 From: Josh Thompson Date: Thu, 27 Jun 2019 19:52:57 -0600 Subject: [PATCH 4/5] removing duplicate key from default_params hash --- README.md | 32 --------------------------- spec/griddler/mailgun/adapter_spec.rb | 1 - 2 files changed, 33 deletions(-) diff --git a/README.md b/README.md index 756eab5..1a67d18 100644 --- a/README.md +++ b/README.md @@ -45,38 +45,6 @@ Action: forward("http://example.com/email_processor") ``` -#### Notes on testing - -If you want to test the functionality of the route, via `rspec` or `minitest` or in Postman, please note that the `to`, `from`, `bcc` and `cc` params you post _must_ be capitalized: - -This would _not_ work: - -```json -{ - "recipient": "recipient@domain.com", - "from": "this wont work ", - "to": "to@domain.com", - "subject": "griddler-mailgun", - "body-plain": "This is some text body", - "body-html": "Supports HTML as well." -} -``` - -On the other hand, this would: - -```json -{ - "recipient": "recipient@domain.com", - "From": "this wont work ", - "To": "to@domain.com", - "subject": "griddler-mailgun", - "body-plain": "This is some text body", - "body-html": "Supports HTML as well." -} -``` -You can explore the expected fields and capitalizations in the [`Griddler::Mailgun::Adapter#normalize_params`](https://github.com/bradpauly/griddler-mailgun/blob/master/lib/griddler/mailgun/adapter.rb#L15) method. - - ## More Information * [mailgun](http://www.mailgun.com) diff --git a/spec/griddler/mailgun/adapter_spec.rb b/spec/griddler/mailgun/adapter_spec.rb index 0245ea3..12320d5 100644 --- a/spec/griddler/mailgun/adapter_spec.rb +++ b/spec/griddler/mailgun/adapter_spec.rb @@ -182,7 +182,6 @@ def default_params "To"=>"John Doe , Jane Doe ", "body-html"=>"
And attachments. Two of them. An image and a text file.
\r\n", "body-plain"=>"And attachments. Two of them. An image and a text file.\r\n", - "from"=>"Jon Snow ", "recipient"=>"johndoe@example.com", "sender"=>"jon@example.com", "stripped-html"=>"
And attachments. Two of them. An image and a text file.
\r\n", From 7b10c8cc92ef6693135b734793084f3d3131de64 Mon Sep 17 00:00:00 2001 From: Josh Thompson Date: Thu, 27 Jun 2019 20:06:03 -0600 Subject: [PATCH 5/5] resolve hound issues --- lib/griddler/mailgun/adapter.rb | 2 +- spec/griddler/mailgun/adapter_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/griddler/mailgun/adapter.rb b/lib/griddler/mailgun/adapter.rb index 6227729..7e54936 100644 --- a/lib/griddler/mailgun/adapter.rb +++ b/lib/griddler/mailgun/adapter.rb @@ -45,7 +45,7 @@ def to_recipients end def cc_recipients - cc = param_or_header(:cc) || '' + cc = param_or_header(:cc) || "" cc.split(',').map(&:strip) end diff --git a/spec/griddler/mailgun/adapter_spec.rb b/spec/griddler/mailgun/adapter_spec.rb index 12320d5..57d188b 100644 --- a/spec/griddler/mailgun/adapter_spec.rb +++ b/spec/griddler/mailgun/adapter_spec.rb @@ -77,13 +77,13 @@ normalized_params = Griddler::Mailgun::Adapter.normalize_params(short_params) expect(normalized_params[:to]).to eq ['johndoe@example.com'] end - - it 'handles downcased params' do - downcased_params = { + + it "handles downcased params" do + downcased = { to: "John Doe " } - normalized_params = Griddler::Mailgun::Adapter.normalize_params(downcased_params) - expect(normalized_params[:to]).to eq ['John Doe '] + normalized_params = Griddler::Mailgun::Adapter.normalize_params(downcased) + expect(normalized_params[:to]).to eq ["John Doe "] end it 'handles message-headers' do