email-assistant/parsers/package-tracking/main.rb

29 lines
692 B
Ruby
Raw Normal View History

2018-02-02 19:23:52 +00:00
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,
}
2018-02-02 19:23:52 +00:00
})
end
JSON.dump(results)
end