Last active
November 15, 2024 01:20
-
-
Save gesslar/a9cb00a83120f0bcdd9c8ba4e025cb93 to your computer and use it in GitHub Desktop.
Glass for GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local GitHubClass = Glu.glass.register({ | |
class_name = "GitHubClass", | |
name = "github", | |
inherit_from = "http", | |
setup = function(___, self, opts, container) | |
local gh_api_base = "https://api.github.com/repos/%s/%s/" | |
function self.get_latest_release(owner, repo, cb) | |
local url = string.format(gh_api_base .. "releases/latest", owner, repo) | |
local response = self.get({ url = url }, function(response) | |
if response.error then | |
return cb(response.error) | |
end | |
local data = yajl.to_value(response.data) | |
return cb(nil, data) | |
end) | |
return response | |
end | |
function self.get_latest_release_assets(owner, repo, cb) | |
local response = self.get_latest_release(owner, repo, function(err, data) | |
if err then return cb(err) end | |
data = data or {} | |
if table.size(data.assets) == 0 then | |
return cb(nil, {}) | |
end | |
return cb(nil, data.assets) | |
end) | |
return response | |
end | |
end | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment