-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App set to send emails in development, production variables are also …
…set.
- Loading branch information
1 parent
a5c05b9
commit 38c32f6
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.bundle | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |