· 7 years ago · Aug 20, 2018, 12:46 AM
1spun = (msg) ->
2 timestamp = gmdatenow()
3 signature = get_signature(host, path, secret_key, access_key, timestamp, version)
4 msg.http(scheme + "://" + host + path)
5 .query
6 timestamp: timestamp
7 version: version
8 access_key: access_key
9 signature: signature
10 type: 'json'
11 .post(msg.match[1]) (err, res, body) ->
12 if err
13 msg.send err
14 else if res.statusCode is not 200
15 msg.send "Service not available! Status code: " + res.statusCode
16 else
17 # set to the memory so user can spin it with separate "spin the last spun" command
18 body = JSON.parse(body)
19 if body.response is 'error'
20 msg.send body.message
21 msg.send body.data
22 else
23 msg.send body.message
24 body.message