From b07c553830c71bfbb7be0f26a502e9421b15b48f Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 10:27:34 -0600 Subject: [PATCH 01/31] added debug statements --- .env.example | 2 -- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 7f29f2b..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -PHAXIO_API_KEY= -PHAXIO_API_SECRET= diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 3646288..93ae2c7 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -77,6 +77,9 @@ class PhaxMachineSinatra < Sinatra::Application end post '/mailgun' do + p "=" * 50 + p params + p "=" * 50 if not params['from'] return [400, "Must include a sender"] elsif not params['recipient'] @@ -110,6 +113,9 @@ class PhaxMachineSinatra < Sinatra::Application post '/fax_received' do @fax = JSON.parse params['fax'] + p "=" * 50 + p @fax + p "=" * 50 recipient_number = Phonelib.parse(@fax['to_number']).e164 begin user_id = db[:users].where(fax_number: recipient_number).first[:id] @@ -118,10 +124,13 @@ class PhaxMachineSinatra < Sinatra::Application db.disconnect end + p "=" * 50 fax_from = @fax['from_number'] + p fax_from fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read email_subject = "Fax received from #{fax_from}" + p "=" * 50 Pony.mail( to: email_addresses, From 95c8e61776f32e830a90358158e2418dc0df3b37 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 10:30:42 -0600 Subject: [PATCH 02/31] added debug statements --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 93ae2c7..c297970 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -80,6 +80,8 @@ class PhaxMachineSinatra < Sinatra::Application p "=" * 50 p params p "=" * 50 + p params['recipient'] + p params['from'] if not params['from'] return [400, "Must include a sender"] elsif not params['recipient'] @@ -103,6 +105,7 @@ class PhaxMachineSinatra < Sinatra::Application end sender = Mail::AddressList.new(params['from']).addresses.first.address + p sender sendFax(sender, params['recipient'],files) "OK" end From 6509e37b82f3e1cdd76ae8c7ee53aacb67f18052 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 10:38:11 -0600 Subject: [PATCH 03/31] added debug statements --- config/environments/production.rb | 3 +++ lib/phax_machine_sinatra/phax_machine_sinatra.rb | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index f5ef1cf..779d91a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -88,4 +88,7 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + #ADDED BY MATT + config.action_mailer.default_url_options = { :host => "https://sheltered-depths-39549.herokuapp.com/" } end diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index c297970..c49e92d 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -77,11 +77,6 @@ class PhaxMachineSinatra < Sinatra::Application end post '/mailgun' do - p "=" * 50 - p params - p "=" * 50 - p params['recipient'] - p params['from'] if not params['from'] return [400, "Must include a sender"] elsif not params['recipient'] @@ -105,7 +100,6 @@ class PhaxMachineSinatra < Sinatra::Application end sender = Mail::AddressList.new(params['from']).addresses.first.address - p sender sendFax(sender, params['recipient'],files) "OK" end From c3daca80f6898835dd90dd6448ea59527cffb8ff Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 10:42:38 -0600 Subject: [PATCH 04/31] added debug statements --- config/environments/production.rb | 3 --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 779d91a..f5ef1cf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -88,7 +88,4 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - - #ADDED BY MATT - config.action_mailer.default_url_options = { :host => "https://sheltered-depths-39549.herokuapp.com/" } end diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index c49e92d..6ec2661 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,6 +109,7 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do + p "FAX RECEIVED" @fax = JSON.parse params['fax'] p "=" * 50 p @fax From 6d9659ad24286678fe8e3a1ca41035231fa89b27 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 13:00:45 -0600 Subject: [PATCH 05/31] debug statements --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 6ec2661..6c21685 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,11 +109,7 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do - p "FAX RECEIVED" @fax = JSON.parse params['fax'] - p "=" * 50 - p @fax - p "=" * 50 recipient_number = Phonelib.parse(@fax['to_number']).e164 begin user_id = db[:users].where(fax_number: recipient_number).first[:id] @@ -121,14 +117,14 @@ class PhaxMachineSinatra < Sinatra::Application ensure db.disconnect end - - p "=" * 50 + p "*" * 55 + p @fax fax_from = @fax['from_number'] p fax_from + p "*" * 55 fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read email_subject = "Fax received from #{fax_from}" - p "=" * 50 Pony.mail( to: email_addresses, From fe7ca2660a66b54929aa9b416fb0cbd0763016e4 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 15:11:43 -0600 Subject: [PATCH 06/31] Debug statements --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 6c21685..acf9d4e 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,7 +109,13 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do + p "FAX_RECEIVED" @fax = JSON.parse params['fax'] + p @fax + p "*" * 55 + p params['fax'] + p "*" * 55 + p params recipient_number = Phonelib.parse(@fax['to_number']).e164 begin user_id = db[:users].where(fax_number: recipient_number).first[:id] @@ -117,11 +123,9 @@ class PhaxMachineSinatra < Sinatra::Application ensure db.disconnect end - p "*" * 55 - p @fax + fax_from = @fax['from_number'] p fax_from - p "*" * 55 fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read email_subject = "Fax received from #{fax_from}" From ed6aaaae90ce4d729fd0d464581aeb40d272d713 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 17:15:10 -0600 Subject: [PATCH 07/31] added additional statements --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index acf9d4e..8aa38e4 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -119,6 +119,8 @@ class PhaxMachineSinatra < Sinatra::Application recipient_number = Phonelib.parse(@fax['to_number']).e164 begin user_id = db[:users].where(fax_number: recipient_number).first[:id] + p user_id + p "========================================================" email_addresses = db[:user_emails].where(user_id: user_id).all.map { |user_email| user_email[:email] } ensure db.disconnect From b0c07f1a539a0a4c176c839a8e1ca97610fcbb37 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 17:21:50 -0600 Subject: [PATCH 08/31] debug --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 8aa38e4..0a53b40 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -127,9 +127,13 @@ class PhaxMachineSinatra < Sinatra::Application end fax_from = @fax['from_number'] + p "========================================================" p fax_from fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read + p fax_file_name + p fax_file_contents + p "========================================================" email_subject = "Fax received from #{fax_from}" Pony.mail( From 2fcede5fd68d2264928229a9881a2699e4a68db5 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Tue, 4 Dec 2018 17:31:10 -0600 Subject: [PATCH 09/31] debug --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 0a53b40..cf2afe7 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -117,11 +117,13 @@ class PhaxMachineSinatra < Sinatra::Application p "*" * 55 p params recipient_number = Phonelib.parse(@fax['to_number']).e164 + p recipient_number begin user_id = db[:users].where(fax_number: recipient_number).first[:id] p user_id p "========================================================" email_addresses = db[:user_emails].where(user_id: user_id).all.map { |user_email| user_email[:email] } + p email_addresses ensure db.disconnect end From f886b55d921f36e2ffbae1806738d486ee902709 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:16:48 -0600 Subject: [PATCH 10/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index cf2afe7..cc3b0d2 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -131,8 +131,10 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] p "========================================================" p fax_from - fax_file_name = params['filename']['filename'] - fax_file_contents = params['filename']['tempfile'].read + if params['filename']['filename'] + fax_file_name = params['filename']['filename'] + fax_file_contents = params['filename']['tempfile'].read + end p fax_file_name p fax_file_contents p "========================================================" From e8f84ec0103cf013e68febdd06abb3c98835308e Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:19:02 -0600 Subject: [PATCH 11/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index cc3b0d2..3fe17cb 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -131,7 +131,7 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] p "========================================================" p fax_from - if params['filename']['filename'] + if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read end From b07c9933555baff75da70369fb0566e99825716c Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:22:25 -0600 Subject: [PATCH 12/31] debugging no file attached --- .../phax_machine_sinatra.rb | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 3fe17cb..01f597d 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -131,26 +131,30 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] p "========================================================" p fax_from + fax_received_mail_options = { + to: email_addresses, + from: smtp_from_address, + subject: email_subject, + html_body: erb(:fax_email, layout: false), + via: :smtp, + via_options: smtp_options + } + if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read + + fax_received_mail_options[:attachments] = { + fax_file_name => fax_file_contents + }, end + p fax_file_name p fax_file_contents p "========================================================" email_subject = "Fax received from #{fax_from}" - Pony.mail( - to: email_addresses, - from: smtp_from_address, - subject: email_subject, - html_body: erb(:fax_email, layout: false), - attachments: { - fax_file_name => fax_file_contents - }, - via: :smtp, - via_options: smtp_options - ) + Pony.mail(fax_received_mail_options) end post '/fax_sent' do From 129e32801e926bab2b2b1ec339bd5f3753717ab0 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:22:46 -0600 Subject: [PATCH 13/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 01f597d..21efe1e 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -143,10 +143,10 @@ class PhaxMachineSinatra < Sinatra::Application if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - + fax_received_mail_options[:attachments] = { fax_file_name => fax_file_contents - }, + } end p fax_file_name From e3b49e1e5c59ef2a04164b49a3e3e9910a5d2431 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:26:07 -0600 Subject: [PATCH 14/31] debugging no file attached --- .../phax_machine_sinatra.rb | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 21efe1e..724a92b 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -131,30 +131,28 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] p "========================================================" p fax_from - fax_received_mail_options = { - to: email_addresses, - from: smtp_from_address, - subject: email_subject, - html_body: erb(:fax_email, layout: false), - via: :smtp, - via_options: smtp_options - } - if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - - fax_received_mail_options[:attachments] = { - fax_file_name => fax_file_contents - } + else + fax_file_contents = '' end - p fax_file_name p fax_file_contents p "========================================================" email_subject = "Fax received from #{fax_from}" - Pony.mail(fax_received_mail_options) + Pony.mail({ + to: email_addresses, + from: smtp_from_address, + subject: email_subject, + html_body: erb(:fax_email, layout: false), + attachments: { + fax_file_name => fax_file_contents + }, + via: :smtp, + via_options: smtp_options + }) end post '/fax_sent' do From 93ccdaccd364767e86194d3bff096e6f056d6a92 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:32:14 -0600 Subject: [PATCH 15/31] debugging no file attached --- .../phax_machine_sinatra.rb | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 724a92b..ae00f64 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -129,30 +129,34 @@ class PhaxMachineSinatra < Sinatra::Application end fax_from = @fax['from_number'] + fax_file_contents = '' + + + pony_options = { + to: email_addresses, + from: smtp_from_address, + subject: email_subject, + html_body: erb(:fax_email, layout: false), + via: :smtp, + via_options: smtp_options + } p "========================================================" p fax_from + if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - else - fax_file_contents = '' + pony_options[:attachments} = { + fax_file_name => fax_file_contents + }, end + p pony_options p fax_file_name p fax_file_contents p "========================================================" email_subject = "Fax received from #{fax_from}" - Pony.mail({ - to: email_addresses, - from: smtp_from_address, - subject: email_subject, - html_body: erb(:fax_email, layout: false), - attachments: { - fax_file_name => fax_file_contents - }, - via: :smtp, - via_options: smtp_options - }) + Pony.mail(pony_options) end post '/fax_sent' do From c3da202caf21eb87d56ad38689d7b33c0bdf4e82 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:33:21 -0600 Subject: [PATCH 16/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index ae00f64..5b31bf5 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -146,10 +146,9 @@ class PhaxMachineSinatra < Sinatra::Application if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - pony_options[:attachments} = { - fax_file_name => fax_file_contents - }, + pony_options[:attachments} = {fax_file_name => fax_file_contents} end + p pony_options p fax_file_name p fax_file_contents From 1b2725c26552dff4fe05510b9d94477b36cc4f4b Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:34:23 -0600 Subject: [PATCH 17/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 5b31bf5..94b4516 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -146,9 +146,9 @@ class PhaxMachineSinatra < Sinatra::Application if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - pony_options[:attachments} = {fax_file_name => fax_file_contents} + pony_options[:attachments] = {fax_file_name => fax_file_contents} end - + p pony_options p fax_file_name p fax_file_contents From 2059e91af860410b9ec91345da5b3f6e297c1bef Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:35:54 -0600 Subject: [PATCH 18/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 94b4516..bd32e4c 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -131,6 +131,7 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] fax_file_contents = '' + email_subject = "Fax received from #{fax_from}" pony_options = { to: email_addresses, @@ -153,7 +154,6 @@ class PhaxMachineSinatra < Sinatra::Application p fax_file_name p fax_file_contents p "========================================================" - email_subject = "Fax received from #{fax_from}" Pony.mail(pony_options) end From bb861c962838763337a268fd6d2d9e640d718d20 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:47:54 -0600 Subject: [PATCH 19/31] debugging no file attached --- .../phax_machine_sinatra.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index bd32e4c..45fcb9c 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,15 +109,8 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do - p "FAX_RECEIVED" @fax = JSON.parse params['fax'] - p @fax - p "*" * 55 - p params['fax'] - p "*" * 55 - p params recipient_number = Phonelib.parse(@fax['to_number']).e164 - p recipient_number begin user_id = db[:users].where(fax_number: recipient_number).first[:id] p user_id @@ -130,9 +123,14 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] fax_file_contents = '' + + if @fax['status'] == "success" ? : + email_subject = "Fax received from #{fax_from}" + else + email_subject = "#{fax_from} attempted to fax #{@fax['to_number']}" + @fax['most_common_error'] = @fax['error_code'] + end - email_subject = "Fax received from #{fax_from}" - pony_options = { to: email_addresses, from: smtp_from_address, @@ -142,7 +140,6 @@ class PhaxMachineSinatra < Sinatra::Application via_options: smtp_options } p "========================================================" - p fax_from if params['filename'] fax_file_name = params['filename']['filename'] From 0349e625dae0aa642dd5241155c58c45177d47b8 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:48:45 -0600 Subject: [PATCH 20/31] debugging no file attached --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 45fcb9c..574cf9a 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -123,8 +123,8 @@ class PhaxMachineSinatra < Sinatra::Application fax_from = @fax['from_number'] fax_file_contents = '' - - if @fax['status'] == "success" ? : + + if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" else email_subject = "#{fax_from} attempted to fax #{@fax['to_number']}" From bf4b757f208abfa068455cec6cd82ca607e7e09c Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 13:57:53 -0600 Subject: [PATCH 21/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 2 +- lib/phax_machine_sinatra/views/fax_email.erb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 574cf9a..0c022d1 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -127,7 +127,7 @@ class PhaxMachineSinatra < Sinatra::Application if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" else - email_subject = "#{fax_from} attempted to fax #{@fax['to_number']}" + email_subject = "#{fax_from} attempted to fax you" @fax['most_common_error'] = @fax['error_code'] end diff --git a/lib/phax_machine_sinatra/views/fax_email.erb b/lib/phax_machine_sinatra/views/fax_email.erb index b7aac66..5ff8d5f 100644 --- a/lib/phax_machine_sinatra/views/fax_email.erb +++ b/lib/phax_machine_sinatra/views/fax_email.erb @@ -1,5 +1,9 @@ <% if @fax["direction"] == "received" %> -

You've received a new fax!

+ <% if @fax['status'] == 'success' %> +

You've received a new fax!

+ <% else %> +

<%= @fax['from_number'] %> attempted to fax you.

+ <% end %> <% else %> <% if @fax["status"] == "success" %>

Your fax was sent successfully

@@ -20,7 +24,9 @@ <% end %> <% if @fax["direction"] == "received" %> -

The document has been attached to this email.

+ <% if @fax["status"] == "success" %> +

The document has been attached to this email.

+ <% end %> <% else %>

Recipients

<% @fax["recipients"].each do |recipient| %> From c4bd8f49878c21f96fdd395a9f224e922a57f5a5 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 14:30:17 -0600 Subject: [PATCH 22/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 16 ++++++---------- lib/phax_machine_sinatra/views/fax_email.erb | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 0c022d1..8b6837b 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,20 +109,19 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do + p "=" * 60 + p params['fax'] + p "=" * 60 @fax = JSON.parse params['fax'] recipient_number = Phonelib.parse(@fax['to_number']).e164 begin user_id = db[:users].where(fax_number: recipient_number).first[:id] - p user_id - p "========================================================" email_addresses = db[:user_emails].where(user_id: user_id).all.map { |user_email| user_email[:email] } - p email_addresses ensure db.disconnect end fax_from = @fax['from_number'] - fax_file_contents = '' if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" @@ -139,19 +138,16 @@ class PhaxMachineSinatra < Sinatra::Application via: :smtp, via_options: smtp_options } - p "========================================================" if params['filename'] + # The Pony gem will attempt to run gsub() on the attachment at some point, so I've moved the options + # out of the method arguments and placed them above. The key with attachment data is added to + # pony_options if an attachment is present. This shuffling prevents errors if a user has no attachment fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read pony_options[:attachments] = {fax_file_name => fax_file_contents} end - p pony_options - p fax_file_name - p fax_file_contents - p "========================================================" - Pony.mail(pony_options) end diff --git a/lib/phax_machine_sinatra/views/fax_email.erb b/lib/phax_machine_sinatra/views/fax_email.erb index 5ff8d5f..1ee8adc 100644 --- a/lib/phax_machine_sinatra/views/fax_email.erb +++ b/lib/phax_machine_sinatra/views/fax_email.erb @@ -1,5 +1,5 @@ <% if @fax["direction"] == "received" %> - <% if @fax['status'] == 'success' %> + <% if @fax['status'] == "success" %>

You've received a new fax!

<% else %>

<%= @fax['from_number'] %> attempted to fax you.

From 3697f1b3b1621a3a012b5ef5846967a11ce5f6bc Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 14:58:00 -0600 Subject: [PATCH 23/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 8b6837b..1cf0e92 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,9 +109,7 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do - p "=" * 60 p params['fax'] - p "=" * 60 @fax = JSON.parse params['fax'] recipient_number = Phonelib.parse(@fax['to_number']).e164 begin @@ -140,12 +138,11 @@ class PhaxMachineSinatra < Sinatra::Application } if params['filename'] - # The Pony gem will attempt to run gsub() on the attachment at some point, so I've moved the options - # out of the method arguments and placed them above. The key with attachment data is added to - # pony_options if an attachment is present. This shuffling prevents errors if a user has no attachment + # The Pony gem will attempt to run gsub() on the attachment at some point, so I've moved the options out + # of the method arguments and placed them above. This shuffling prevents errors if a user has no attachment fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read - pony_options[:attachments] = {fax_file_name => fax_file_contents} + pony_options[:attachments] = { fax_file_name => fax_file_contents } end Pony.mail(pony_options) From b103421e7f22946f89111ec3f7a324c6d9bfd761 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:01:17 -0600 Subject: [PATCH 24/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 1cf0e92..e39209d 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,7 +109,8 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do - p params['fax'] + p "*******" + p params @fax = JSON.parse params['fax'] recipient_number = Phonelib.parse(@fax['to_number']).e164 begin From 7839cd45a306bc308eb27f33008a2efb1ae9648a Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:19:50 -0600 Subject: [PATCH 25/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index e39209d..364a269 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -109,8 +109,6 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_received' do - p "*******" - p params @fax = JSON.parse params['fax'] recipient_number = Phonelib.parse(@fax['to_number']).e164 begin @@ -150,6 +148,8 @@ class PhaxMachineSinatra < Sinatra::Application end post '/fax_sent' do + p "=========================" + p params @fax = JSON.parse params['fax'] fax_tag = @fax['tags']['user'] begin From bb6c8f05f81986707c80b2ab696dbb608757a324 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:30:04 -0600 Subject: [PATCH 26/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 364a269..305c82f 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -136,20 +136,18 @@ class PhaxMachineSinatra < Sinatra::Application via_options: smtp_options } - if params['filename'] # The Pony gem will attempt to run gsub() on the attachment at some point, so I've moved the options out # of the method arguments and placed them above. This shuffling prevents errors if a user has no attachment + if params['filename'] fax_file_name = params['filename']['filename'] fax_file_contents = params['filename']['tempfile'].read pony_options[:attachments] = { fax_file_name => fax_file_contents } end - + Pony.mail(pony_options) end post '/fax_sent' do - p "=========================" - p params @fax = JSON.parse params['fax'] fax_tag = @fax['tags']['user'] begin From 5669a6357fe61f35244b67e6b1ad8cf292bd3785 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:32:43 -0600 Subject: [PATCH 27/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 305c82f..6ffa965 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -123,6 +123,8 @@ class PhaxMachineSinatra < Sinatra::Application if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" else + # Not running the most_common_error method because this is intended for when a landline/cellphones attempts + # to fax with no attachment. An email with no attachment is caught in the /mailgun route before it gets here email_subject = "#{fax_from} attempted to fax you" @fax['most_common_error'] = @fax['error_code'] end @@ -143,7 +145,7 @@ class PhaxMachineSinatra < Sinatra::Application fax_file_contents = params['filename']['tempfile'].read pony_options[:attachments] = { fax_file_name => fax_file_contents } end - + Pony.mail(pony_options) end From 11ecc3ce787e0d887075c36a0c04e470675e1d14 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:42:46 -0600 Subject: [PATCH 28/31] Added condition in fax received for a user forgetting to attach an attachment --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 6ffa965..1cc08bb 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -122,11 +122,9 @@ class PhaxMachineSinatra < Sinatra::Application if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" - else - # Not running the most_common_error method because this is intended for when a landline/cellphones attempts - # to fax with no attachment. An email with no attachment is caught in the /mailgun route before it gets here - email_subject = "#{fax_from} attempted to fax you" - @fax['most_common_error'] = @fax['error_code'] + # else + # email_subject = "#{fax_from} attempted to fax you" + # @fax['most_common_error'] = @fax['error_code'] end pony_options = { @@ -146,7 +144,11 @@ class PhaxMachineSinatra < Sinatra::Application pony_options[:attachments] = { fax_file_name => fax_file_contents } end - Pony.mail(pony_options) + # Comment out the 'if @fax['status'] == 'success' if the user would like to receive + # emails stating a landline tried to fax them. + if @fax['status'] == "success" + Pony.mail(pony_options) + end end post '/fax_sent' do From 67f8d01e2664635b04e58b6efaa65ff5de03b258 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:50:54 -0600 Subject: [PATCH 29/31] Added logger statement, rearranged the options used within Pony mailer to add in an attachment after it is verified that one exists --- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index 1cc08bb..f4cde83 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -122,7 +122,8 @@ class PhaxMachineSinatra < Sinatra::Application if @fax['status'] == "success" email_subject = "Fax received from #{fax_from}" - # else + else + logger.info "#{recipient_number} received a fax with a failure status from #{fax_from} with no attachment" # email_subject = "#{fax_from} attempted to fax you" # @fax['most_common_error'] = @fax['error_code'] end From f206c92746815d7a07a34a8613a08baa6672b433 Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 15:58:42 -0600 Subject: [PATCH 30/31] Added logger statement, rearranged the options used within Pony mailer to add in an attachment after it is verified that one exists --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..5b329f7 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +PHAXIO_API_KEY= +PHAXIO_API_SECRET= + + From 0b30852c8b021a3de51b4b4a35e59cf0ad8974fa Mon Sep 17 00:00:00 2001 From: Matt Mayerle Date: Thu, 6 Dec 2018 16:15:05 -0600 Subject: [PATCH 31/31] Added logger statement, rearranged the options used within Pony mailer to add in an attachment after it is verified that one exists --- .env.example | 4 ---- lib/phax_machine_sinatra/phax_machine_sinatra.rb | 10 +++------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 5b329f7..e69de29 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +0,0 @@ -PHAXIO_API_KEY= -PHAXIO_API_SECRET= - - diff --git a/lib/phax_machine_sinatra/phax_machine_sinatra.rb b/lib/phax_machine_sinatra/phax_machine_sinatra.rb index f4cde83..58bd455 100644 --- a/lib/phax_machine_sinatra/phax_machine_sinatra.rb +++ b/lib/phax_machine_sinatra/phax_machine_sinatra.rb @@ -124,8 +124,8 @@ class PhaxMachineSinatra < Sinatra::Application email_subject = "Fax received from #{fax_from}" else logger.info "#{recipient_number} received a fax with a failure status from #{fax_from} with no attachment" - # email_subject = "#{fax_from} attempted to fax you" - # @fax['most_common_error'] = @fax['error_code'] + @fax['most_common_error'] = @fax['error_code'] + email_subject = "Your fax failed because: #{@fax["most_common_error"]}" end pony_options = { @@ -145,11 +145,7 @@ class PhaxMachineSinatra < Sinatra::Application pony_options[:attachments] = { fax_file_name => fax_file_contents } end - # Comment out the 'if @fax['status'] == 'success' if the user would like to receive - # emails stating a landline tried to fax them. - if @fax['status'] == "success" - Pony.mail(pony_options) - end + Pony.mail(pony_options) end post '/fax_sent' do