Skip to content

Commit

Permalink
App set to send emails in development, production variables are also …
Browse files Browse the repository at this point in the history
…set.
  • Loading branch information
Besermenji committed Jun 12, 2016
1 parent a5c05b9 commit 38c32f6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle
tmp
14 changes: 13 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
require 'rubygems'
require 'bundler'
require 'pony'

Bundler.require
Bundler.require(:default, ENV['RACK_ENV'].to_sym)
if ENV['RACK_ENV'] == 'production'
Pony.options = { :via => :smtp,
:via_options => { :address => 'smtp.sendgrid.net',
:port => '587',
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => 'ry-report-generator.herokuapp.com' } }
else
Pony.options = { :via => LetterOpener::DeliveryMethod,
:via_options => { :location => File.expand_path('../tmp/letter_opener', __FILE__)} }
end

require './report_generator'
run ReportGenerator
46 changes: 44 additions & 2 deletions report_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
require 'sinatra'
require 'letter_opener'
require 'pony'
require 'json'


class ReportGenerator < Sinatra::Base
get '/hi' do
"Hello World!"

before do
unless request.body.read == ""
request.body.rewind
@request_payload ||= JSON.parse request.body.read
end
end

get '/' do
"Hello World! Im just a poor app, nobody loves me."
end

get '/report_sent' do
"Report sent!"
end

get '/something_went_wrong' do
"Oh noes!
You don't like the smell?
Maybe I don't like the smell that some cars produce?
I sure as hell don't like it when
people fart near me or if someone has
bad body odor. You get a sore throat,
maybe I get a headache
from prolonged exposure to
those smells. Should we make
everything that doesn't smell good illegal?"
end

post '/send_report' do
if @request_payload && @request_payload["email"]
Pony.mail(:to => @request_payload["email"],
:from => '[email protected]',
:subject => 'hi',
:body => "Hello there. It is #{DateTime.now}. This is just a test.")
redirect '/report_sent'
else
redirect '/something_went_wrong'
end
end

end

0 comments on commit 38c32f6

Please sign in to comment.