@@ -3,7 +3,7 @@ local json = require("rapidjson")
33local argparse = require (" argparse" )
44
55-- Base url for requests
6- local API_USERS_URL = " https://api.github.com/users/"
6+ local BASE_URL = " https://api.github.com/users/"
77
88--- @class GthUser @Class for a github user basic info
99--- @field url string (private ) Url to make requests , for internal usage
@@ -20,22 +20,22 @@ local GthUser = {}
2020--- Constructor for GthUser class
2121--- @param username string The github username to get info
2222--- @return GthUser
23- function GthUser :new (username )
23+ function GthUser :init (username )
2424 assert (
2525 type (username ) == " string" ,
26- " Bad argument for 'new ', string expected, got " .. type (username )
26+ " Bad argument for 'init ', string expected, got " .. type (username )
2727 )
2828
29- self .url = API_USERS_URL .. username
29+ self .url = BASE_URL .. username
3030 local res = req .get (self .url )
3131 self .json = json .decode (res .text )
3232
3333 self .name = self .json [' name' ]
3434 self .bio = self .json [' bio' ]
3535 self .link = self .json [' html_url' ]
3636
37- self .repos = { count = self .json [' public_repos' ], arr = {} }
38- self .gists = { count = self .json [' public_gists' ], arr = {} }
37+ self .repos = { count = self .json [' public_repos' ], arr = {} }
38+ self .gists = { count = self .json [' public_gists' ], arr = {} }
3939 self .followers = { count = self .json [' followers' ], arr = {} }
4040 self .following = { count = self .json [' following' ], arr = {} }
4141
4848function GthUser :fetch (thing )
4949 assert (
5050 type (thing ) == " string" ,
51- " Bad argument for 'new ', string expected, got " .. type (thing )
51+ " Bad argument for 'fetch ', string expected, got " .. type (thing )
5252 )
5353
5454 local url = self .url .. ' /' .. thing
@@ -77,21 +77,21 @@ function GthUser:fetch(thing)
7777end
7878
7979local opts = argparse ({
80- name = " Github.lua" ,
80+ name = " Github.lua" ,
8181 description = " Simple example of the Github's REST API" ,
82- epilog = " Check out https://github.com/M1que4s/Github-REST-API-Example"
82+ epilog = " Check out https://github.com/M1que4s/Github-REST-API-Example"
8383})
8484
8585opts :argument (" usernames" , " One or more usernames" ):args (" +" )
8686opts :flag (" -f --followers" , " Shows user followers" , false )
8787opts :flag (" -F --following" , " Shows user following" , false )
88- opts :flag (" -r --repos" , " Shows user repos" , false )
89- opts :flag (" -g --gists" , " Shows user gists" , false )
88+ opts :flag (" -r --repos" , " Shows user repos" , false )
89+ opts :flag (" -g --gists" , " Shows user gists" , false )
9090
9191local args = opts :parse (arg )
9292
93- for _ , v in ipairs (args .usernames ) do
94- local user = GthUser :new ( v )
93+ for _ , user in ipairs (args .usernames ) do
94+ local user = GthUser :init ( user )
9595
9696 print (" name: " .. user .name )
9797 print (" bio: " .. user .bio )
@@ -132,4 +132,6 @@ for _, v in ipairs(args.usernames) do
132132 print (" | @" .. v )
133133 end
134134 end
135+
136+ print ()
135137end
0 commit comments