blob: a733f954825c157f756224b4a8b868bfae44f0fc (
plain)
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
|
--[[
_____ _ _
|_ _| __ ___ _ __ ___ _ _| | ___ _ _ ___ | | _ _ __ _
| || '__/ _ \ '_ ` _ \| | | | |/ _ \| | | / __|_____| | | | | |/ _` |
| || | | __/ | | | | | |_| | | (_) | |_| \__ \_____| |__| |_| | (_| |
|_||_| \___|_| |_| |_|\__,_|_|\___/ \__,_|___/ |_____\__,_|\__,_|
Victor Roemer [WTFBBQHAX]
Nov. 03, 2016 10:53:27AM EST
A sample Restful JSON Client API.
This sample demonstrates how to comunicate with an HTTP JSON 3rdparty
API in Lua script.
APIs demonstrated:
* HTTP RestClient
* JSON
--]]
-- GitHub API URL
url='https://api.github.com/repos/GrangerHub/tremulous/releases'
-- HTTP Get request- retrieve the raw JSON response
txt = http.get(url)
assert(txt.code == 200)
-- Decode raw JSON response into a Lua table
releases = rapidjson.decode(txt.body)
-- GitHub returned an array of releases- The "most_recent" is item 1
-- NOTE: Lua array indexing starts at `1` not `0`!!
most_recent = releases[1]
-- FIXME: Remove hardcoded tag_name in this test
assert(most_recent.tag_name == "Oct-22-2016")
for i,asset in ipairs(most_recent.assets) do
print(asset.browser_download_url)
end
|