forked from iloveitaly/shipwire_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipwire_endpoint.rb
43 lines (34 loc) · 1.09 KB
/
shipwire_endpoint.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require "sinatra"
require "endpoint_base"
require File.expand_path(File.dirname(__FILE__) + '/lib/ship_wire.rb')
Dir['./lib/**/*.rb'].each { |f| require f }
class ShipwireEndpoint < EndpointBase::Sinatra::Base
endpoint_key ENV["ENDPOINT_KEY"]
Honeybadger.configure do |config|
config.api_key = ENV['HONEYBADGER_KEY']
config.environment_name = ENV['RACK_ENV']
end if ENV['HONEYBADGER_KEY'].present?
set :logging, true
post '/add_shipment' do
begin
shipment_entry = ShipmentEntry.new(@payload, @config)
response = shipment_entry.consume
result 200, 'Successfully sent shipment to Shipwire'
rescue => e
result 500, e.message
end
end
post '/get_shipments' do
begin
shipment_tracking = ShipmentTracking.new(@payload, @config)
response = shipment_tracking.consume
if messages = response[:messages]
messages.each { |m| add_object :shipment, m }
set_summary "Successfully received #{messages.count} shipment(s) from Shipwire"
end
result 200
rescue => e
result 500, e.message
end
end
end