-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mds_integration.rb
48 lines (34 loc) · 1.31 KB
/
mds_integration.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
44
45
46
47
48
require 'httparty'
require 'nokogiri'
require_relative 'lib/mds/mds'
class MDSIntegration < EndpointBase::Sinatra::Base
set :logging, true
post '/add_shipment' do
if @payload[:shipment][:status] == "shipped"
result 200, "Ignoring shipment #{@payload[:shipment][:id]}, it's already shipped."
else
response = MDS::Services::SubmitOrder.new(@config).query(@payload[:shipment])
result status_from_response(response), response.message
end
end
post '/get_shipments' do
response = MDS::Services::ShippingStatus::Tracking.new(@config).query
response.objects.each { |shipment| add_object :shipment, shipment}
result status_from_response(response), response.message
end
post '/get_inventory' do
response = MDS::Services::FullInventory.new(@config).query
response.objects.each { |inventory| add_object :inventory, inventory }
result status_from_response(response), response.message
end
post '/get_shipment_details' do
order_ids = Array(@payload[:shipment][:id])
response = MDS::Services::OrderDetails.new(@config).query(order_ids)
response.objects.each { |shipment| add_object :shipment, shipment}
result status_from_response(response), response.message
end
private
def status_from_response(response)
response.success?? 200 : 500
end
end