Sha256: fb89026e3a74d265476b07373403d1f90fb4d11c68f608b2737b21f65449116b
Contents?: true
Size: 711 Bytes
Versions: 5
Compression:
Stored size: 711 Bytes
Contents
local http = require("socket.http") local ltn12 = require("ltn12") local M = {} require "json" local parseJson = function( filename ) local file = io.open( filename, "r" ) if file then local contents = file:read( "*a" ) result = json.decode( contents ) io.close( file ) return result else return {} end end M.parseJson = parseJson local parseRemoteJson = function( remoteUrl ) local tempFilename = system.pathForFile( "temp.json", system.TemporaryDirectory ) local tempFile = io.open( tempFilename, "w+b" ) http.request { url = remoteUrl, sink = ltn12.sink.file( tempFile ) } return parseJson( tempFilename ) end M.parseRemoteJson = parseRemoteJson return M
Version data entries
5 entries across 5 versions & 1 rubygems