Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b07c553
added debug statements
mwmayerle Dec 4, 2018
95c8e61
added debug statements
mwmayerle Dec 4, 2018
6509e37
added debug statements
mwmayerle Dec 4, 2018
c3daca8
added debug statements
mwmayerle Dec 4, 2018
6d9659a
debug statements
mwmayerle Dec 4, 2018
fe7ca26
Debug statements
mwmayerle Dec 4, 2018
ed6aaaa
added additional statements
mwmayerle Dec 4, 2018
b0c07f1
debug
mwmayerle Dec 4, 2018
2fcede5
debug
mwmayerle Dec 4, 2018
f886b55
debugging no file attached
mwmayerle Dec 6, 2018
e8f84ec
debugging no file attached
mwmayerle Dec 6, 2018
b07c993
debugging no file attached
mwmayerle Dec 6, 2018
129e328
debugging no file attached
mwmayerle Dec 6, 2018
e3b49e1
debugging no file attached
mwmayerle Dec 6, 2018
93ccdac
debugging no file attached
mwmayerle Dec 6, 2018
c3da202
debugging no file attached
mwmayerle Dec 6, 2018
1b2725c
debugging no file attached
mwmayerle Dec 6, 2018
2059e91
debugging no file attached
mwmayerle Dec 6, 2018
bb861c9
debugging no file attached
mwmayerle Dec 6, 2018
0349e62
debugging no file attached
mwmayerle Dec 6, 2018
bf4b757
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
c4bd8f4
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
3697f1b
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
b103421
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
7839cd4
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
bb6c8f0
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
5669a63
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
11ecc3c
Added condition in fax received for a user forgetting to attach an at…
mwmayerle Dec 6, 2018
67f8d01
Added logger statement, rearranged the options used within Pony maile…
mwmayerle Dec 6, 2018
f206c92
Added logger statement, rearranged the options used within Pony maile…
mwmayerle Dec 6, 2018
0b30852
Added logger statement, rearranged the options used within Pony maile…
mwmayerle Dec 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
PHAXIO_API_KEY=
PHAXIO_API_SECRET=
28 changes: 20 additions & 8 deletions lib/phax_machine_sinatra/phax_machine_sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,33 @@ class PhaxMachineSinatra < Sinatra::Application
end

fax_from = @fax['from_number']
fax_file_name = params['filename']['filename']
fax_file_contents = params['filename']['tempfile'].read
email_subject = "Fax received from #{fax_from}"

Pony.mail(
if @fax['status'] == "success"
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"
@fax['most_common_error'] = @fax['error_code']
email_subject = "Your fax failed because: #{@fax["most_common_error"]}"
end

pony_options = {
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
)
}

# 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
Expand Down
10 changes: 8 additions & 2 deletions lib/phax_machine_sinatra/views/fax_email.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% if @fax["direction"] == "received" %>
<h1>You've received a new fax!</h1>
<% if @fax['status'] == "success" %>
<h1>You've received a new fax!</h1>
<% else %>
<h1><%= @fax['from_number'] %> attempted to fax you.</h1>
<% end %>
<% else %>
<% if @fax["status"] == "success" %>
<h1>Your fax was sent successfully</h1>
Expand All @@ -20,7 +24,9 @@
<% end %>

<% if @fax["direction"] == "received" %>
<p>The document has been attached to this email.</p>
<% if @fax["status"] == "success" %>
<p>The document has been attached to this email.</p>
<% end %>
<% else %>
<h2>Recipients</h2>
<% @fax["recipients"].each do |recipient| %>
Expand Down