email-assistant/parsers/package-tracking/main.rb
Ian Fijolek 271513312f Update package tracking parser version
Update of the version to > 1.0 to include carrier names
2018-02-05 17:52:39 -08:00

29 lines
692 B
Ruby

require 'sinatra'
require 'tracking_number'
set :bind, "0.0.0.0"
set :port, 3000
# Simple status endpoint on root
get '/' do
'OK'
end
# Standard parser api receives PUT {"message": "Email body"} /parse
# Returns [{"token": "extracted token", "type": "token type", "metadata": {}]
post '/parse' do
body = JSON.parse(request.body.read)
trackers = TrackingNumber.search(body["message"])
results = []
for tracker in trackers do
results.push({
:token => tracker.tracking_number,
:type => "SHIPPING",
:metadata => {
:carrier_name => tracker.courier_name,
}
})
end
JSON.dump(results)
end