forked from peterberkenbosch/fosdick_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fosdick_endpoint.rb
69 lines (58 loc) · 1.51 KB
/
fosdick_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'securerandom'
Dir['./lib/**/*.rb'].each { |f| require f }
class FosdickEndpoint < EndpointBase::Sinatra::Base
before do
AWS.config(access_key_id: @config['amazon_key'],
secret_access_key: @config['amazon_secret_key']) if @config
end
post '/add_shipment' do
begin
msg = Processor.send_shipment(@payload[:shipment], @config)
code = 200
rescue => e
Raven.capture_exception(e)
msg = e.message
code = 500
end
set_summary msg
process_result code
end
post '/get_shipments' do
begin
shipments = Processor.receive_results(@config['bucket'], 'ship', "shipments")
code = 200
rescue => e
Raven.capture_exception(e)
msg = e.message
code = 500
end
if shipments.is_a?(Array)
shipments.each do |shipment|
add_object :shipment, shipment
end
set_summary "#{shipments.length} shipments imported from Fosdick."
else
set_summary shipments
end
process_result code
end
post '/get_inventory' do
begin
inventories = Processor.receive_results(@config['bucket'], 'inventory')
code = 200
rescue => e
Raven.capture_exception(e)
msg = e.message
code = 500
end
if inventories.is_a?(Array)
inventories.each do |inventory|
add_object :inventory, inventory
end
set_summary "#{inventories.length} inventory imported from Fosdick."
else
set_summary inventories
end
process_result code
end
end