在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:lusis/lua-github开源软件地址:https://github.com/lusis/lua-github开源编程语言:Lua 96.9%开源软件介绍:lua-github
InstallEasiest option is probably to install from luarocks:
Alternately, you can install via the included RequirementsThe following versions were tested
UsageBelow are a few examples of usage both with nginx and luasocket/luasec. Results of most api calls return either
Some api calls return straight lualocal inspect = require 'inspect'
local gh = require('github').new()
gh:set_access_token('XXXXXXXX')
-- alternately: local gh = require('github').new({access_token = 'XXXXXXXXX'})
local r, err = gh:get_authenticated_user()
print(err)
-- no access token
gh:set_access_token('XXXXXXXX')
-- alternately: local gh = require('github').new({access_token = 'XXXXXXXXX'})
local r, err = gh:get_authenticated_user()
if err then
print(err)
else
inspect(r)
end
-- {
-- avatar_url = "https://avatars.githubusercontent.com/u/228958?v=3",
-- bio = <userdata 1>,
-- blog = "http://about.me/lusis",
-- company = "The Lusis Group",
-- created_at = "2010-03-23T20:28:44Z",
-- email = "[email protected]",
-- events_url = "https://api.github.com/users/lusis/events{/privacy}",
-- followers = 231,
-- followers_url = "https://api.github.com/users/lusis/followers",
-- following = 97,
-- following_url = "https://api.github.com/users/lusis/following{/other_user}",
-- gists_url = "https://api.github.com/users/lusis/gists{/gist_id}",
-- gravatar_id = "",
-- hireable = false,
-- html_url = "https://github.com/lusis",
-- id = 228958,
-- location = "Roswell, GA.",
-- login = "lusis",
-- name = "John E. Vincent",
-- organizations_url = "https://api.github.com/users/lusis/orgs",
-- public_gists = 231,
-- public_repos = 137,
-- received_events_url = "https://api.github.com/users/lusis/received_events",
-- repos_url = "https://api.github.com/users/lusis/repos",
-- site_admin = false,
-- starred_url = "https://api.github.com/users/lusis/starred{/owner}{/repo}",
-- subscriptions_url = "https://api.github.com/users/lusis/subscriptions",
-- type = "User",
-- updated_at = "2014-12-03T20:56:53Z",
-- url = "https://api.github.com/users/lusis"
-- }
print(r.login)
-- lusis
local r, err = gh:get_authed_user_org_membership('github', 'lusis')
print(r)
-- false
local r, err = gh:get_authed_user_org_membership('logstash', 'lusis')
print(r)
-- true nginx usageThe nginx usage is largely similar but you'll need to follow the httpclient instructions to set up the internal redirect in nginx. Then you'll use this library specifying the alternate driver: ngx.var.access_token = 'XXXXXXX'
local gh = require('github').new({access_token = ngx.var.access_token, httpclient_driver = 'httpclient.ngx_driver'})
local r, err = gh:get_authenticated_user()
if err or r.login ~= 'lusis' then
ngx.exit(ngx.HTTP_UNAUTHORIZED)
else
ngx.say("welcome "..r.login)
end oauth usageAlternately you can make all calls with oauth credentials but it's up to you to store those somewhere inside nginx each authenticated user. The library provides a few helpers you can use:
In the second example, args is a lua table like so: args = {
client_id = 'XXXXXXX',
client_secret = 'YYYYYYY',
redirect_uri = 'http://hostname/my_oauth_callback'
} Authenticated vs Unauthenticated callsNote that the library can be used out of the box without having a github access token. Most calls provide authenticated vs unauthenticated versions. For example:
The first option makes a call to Debugging the underlying httpclientA feature of With every action in local inspect = require 'inspect'
ngx.log(ngx.ERR, inspect(gh.hc:get_last_request().get_headers())) Which is where I realized that my TODO
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论