-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_api.rb
37 lines (31 loc) · 887 Bytes
/
fake_api.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
require 'webrick'
require 'json'
def random_result
[
{
faceAttributes: {
emotion: {
anger: rand.round(3),
contempt: rand.round(3),
disgust: rand.round(3),
fear: rand.round(3),
happiness: rand.round(3),
neutral: rand.round(3),
sadness: rand.round(3),
surprise: rand.round(3),
}
}
}
]
end
server = WEBrick::HTTPServer.new :Port => 8080
trap 'INT' do
server.shutdown
end
server.mount_proc '/face/v1.0/detect' do |req, res|
header = req.header
puts "Received #{header['content-length'][0]} bytes from #{header['user-agent'][0]}"
res['Content-Type'] = 'application/json'
res.body = random_result.to_json
end
server.start