Skip to content

Instantly share code, notes, and snippets.

@xavdid xavdid/ README.md
Last active Aug 29, 2015

Embed
What would you like to do?
Shirt Bouncer

#Shirt Bounce

A simple Sinatra app that acts as a step for an IFTTT recipe that parses Paypal emails about shirt orders and puts them into a database.

Read more about it here.

The live version is here.

require './main.rb'
run Sinatra::Application
source 'https://rubygems.org'
gem 'sinatra'
gem 'json'
gem 'mail'
GEM
remote: https://rubygems.org/
specs:
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
polyglot (0.3.3)
rack (1.5.2)
rack-protection (1.5.2)
rack
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
PLATFORMS
ruby
DEPENDENCIES
json
mail
sinatra
require 'sinatra'
require 'json'
require 'mail'
get '/' do
'<style>body{font-family:sans-serif;} a:visited{color:blue;}</style><h1> A little app that parses PayPal emails for an IFTTT trigger </h1><br><br>
Made by <a href="http://www.davidbrownman.com">David Brownman</a> for <a href="http://www.umichquidditch.com">Michigan Quidditch</a>. More info can be found <a href="http://blog.davidbrownman.com/post/76440404792/if-shirt-then-bounce-that-email">here</a>. The source is <a href="https://gist.github.com/Xavdidtheshadow/8930419">here</a>.'
end
post '/' do
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
data = JSON.parse(request.body.read)["title"]
reg = data.match(/onfirmed([A-z ]*)([0-9 A-z]*),\W*([A-z]{2})\W*([0-9]{5})/)
# name = reg[1]
# address = reg[2]
# state = reg[3]
# zip = reg[4]
email = data.match(/from \(([\w.@]*)\)/)[1]
a = [email,reg[1],reg[2],reg[3],reg[4]]
reg2 = data.scan(/zes: ([A-Z]+)/)
# scan returns all in nested array
# [["L"], ["M"]]
sizes = reg2.join(', ')
# "L, M"
a << sizes << 'N' << 'N' << '#quid'
subject_text = a.join('|||')
# subject_text = "name@gmail.com|||12345 N Main StAnn Arbor|||MI|||48104|||L, M, M|||N|||N|||#quid"
mail = Mail.deliver do
to 'trigger@ifttt.com'
from ENV['EMAIL']
subject subject_text
text_part do
body 'empty'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.