-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-old.rb
48 lines (37 loc) · 1.09 KB
/
server-old.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
#!/usr/bin/env ruby
require "webrick"
require "cachy"
require "fetchProducts"
require "ProductGroupList"
require "SearchProduct"
require "rubygems"
require "faraday"
require "json"
class MyServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET (request, response)
response.status = 200
response.content_type = "text/json"
result = nil
case request.path
when "/getPrices"
if !request.query['id'] or request.query['id'] === '' then
raise 'groupId id is missing!';
end
productContainer = FetchProducts.new();
productData = productContainer.get(request.query['id']);
result = productData.to_json;
when "/groupList"
productGroup = ProductGroupList.new();
result = productGroup.get().to_json;
else
result = "No such method"
end
response.body = "{ \"value\": " + result.to_s + " }"
end
end
server = WEBrick::HTTPServer.new(:Port => 1235)
server.mount "/", MyServlet
trap("INT") {
server.shutdown
}
server.start