-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapi-client.lua
More file actions
35 lines (29 loc) · 759 Bytes
/
api-client.lua
File metadata and controls
35 lines (29 loc) · 759 Bytes
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
-- -*- coding: utf-8 -*-
--
-- HTTP API Client.
--
-- Copyright 2014 Alexander Tsirel
-- http://noma4i.com
--
-- This code is released under a Apache License Version 2.0:
-- https://www.apache.org/licenses/LICENSE-2.0.txt
http = require("socket.http")
https = require("ssl.https")
json = (loadfile "./libs/JSON.lua")()
loadfile ("./libs/Utils.lua")()
function api_call(...)
local args = {...}
local reqbody = args[3] or ""
local respbody = {}
https.request {
method = args[1],
url = args[2],
source = ltn12.source.string(reqbody),
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Length"] = #reqbody
},
sink = ltn12.sink.table(respbody)
}
return json:decode(table.concat(respbody))
end