forked from nurelm/sugarcrm_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugarcrm_integration.rb
77 lines (60 loc) · 1.45 KB
/
sugarcrm_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require "sinatra"
require "endpoint_base"
require_all 'lib'
class SugarcrmIntegration < EndpointBase::Sinatra::Base
set :logging, true
# NOTE: Can only be used in development this will break production if left in uncommented.
# configure :development do
# enable :logging, :dump_errors, :raise_errors
# log = File.new("tmp/sinatra.log", "a")
# STDOUT.reopen(log)
# STDERR.reopen(log)
# end
post '/add_customer' do
sugar_action('add_update_customer')
end
post '/update_customer' do
sugar_action('add_update_customer')
end
get '/get_customer' do
"Coming soon ..."
end
post '/add_order' do
sugar_action('add_order')
end
post '/update_order' do
sugar_action('update_order')
end
get '/get_orders' do
"Coming soon ..."
end
post '/add_product' do
sugar_action('add_update_products')
end
post '/update_product' do
sugar_action('add_update_products')
end
get '/get_product' do
"Coming soon ..."
end
post '/add_shipment' do
sugar_action('add_order_shipment_notes')
end
post '/update_shipment' do
sugar_action('add_order_shipment_notes')
end
get '/get_shipment' do
"Coming soon ..."
end
def sugar_action(action)
begin
sugarcrm = Sugarcrm.new(@payload, @config)
response = sugarcrm.send(action)
result 200, response
rescue => e
print e.cause
print e.backtrace.join("\n")
result 500, e.message
end
end
end