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",
|
2018-02-06 01:52:39 +00:00
|
|
|
:metadata => {
|
|
|
|
:carrier_name => tracker.courier_name,
|
|
|
|
}
|
2018-02-02 19:23:52 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
JSON.dump(results)
|
|
|
|
end
|