summaryrefslogtreecommitdiff
path: root/scripts/sample-httpjson-client.lua
diff options
context:
space:
mode:
authorIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
committerIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
commit425decdf7e9284d15aa726e3ae96b9942fb0e3ea (patch)
tree6c0dd7edfefff1be7b9e75fe0b3a0a85fe1595f3 /scripts/sample-httpjson-client.lua
parentccb0b2e4d6674a7a00c9bf491f08fc73b6898c54 (diff)
create tremded branch
Diffstat (limited to 'scripts/sample-httpjson-client.lua')
-rw-r--r--scripts/sample-httpjson-client.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/sample-httpjson-client.lua b/scripts/sample-httpjson-client.lua
new file mode 100644
index 0000000..a733f95
--- /dev/null
+++ b/scripts/sample-httpjson-client.lua
@@ -0,0 +1,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