All checks were successful
Golang test / go-test (push) Successful in 26s
77 lines
3.2 KiB
Go
77 lines
3.2 KiB
Go
package github
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
"time"
|
|
|
|
"sirherobrine23.com.br/go-bds/request/v2"
|
|
)
|
|
|
|
// User info
|
|
type User struct {
|
|
Login string `json:"login"`
|
|
ID int `json:"id"`
|
|
NodeID string `json:"node_id"`
|
|
AvatarURL string `json:"avatar_url"`
|
|
GravatarID string `json:"gravatar_id"`
|
|
URL string `json:"url"`
|
|
HTMLURL string `json:"html_url"`
|
|
FollowersURL string `json:"followers_url"`
|
|
FollowingURL string `json:"following_url"`
|
|
GistsURL string `json:"gists_url"`
|
|
StarredURL string `json:"starred_url"`
|
|
SubscriptionsURL string `json:"subscriptions_url"`
|
|
OrganizationsURL string `json:"organizations_url"`
|
|
ReposURL string `json:"repos_url"`
|
|
EventsURL string `json:"events_url"`
|
|
ReceivedEventsURL string `json:"received_events_url"`
|
|
Type string `json:"type"`
|
|
SiteAdmin bool `json:"site_admin"`
|
|
Name string `json:"name"`
|
|
Company string `json:"company"`
|
|
Blog string `json:"blog"`
|
|
Location string `json:"location"`
|
|
Email string `json:"email"`
|
|
Hireable bool `json:"hireable"`
|
|
Bio string `json:"bio"`
|
|
TwitterUsername string `json:"twitter_username"`
|
|
PublicRepos int `json:"public_repos"`
|
|
PublicGists int `json:"public_gists"`
|
|
Followers int `json:"followers"`
|
|
Following int `json:"following"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
PrivateGists int `json:"private_gists"`
|
|
TotalPrivateRepos int `json:"total_private_repos"`
|
|
OwnedPrivateRepos int `json:"owned_private_repos"`
|
|
DiskUsage int `json:"disk_usage"`
|
|
Collaborators int `json:"collaborators"`
|
|
TwoFactorAuthentication bool `json:"two_factor_authentication"`
|
|
Plan struct {
|
|
Name string `json:"name"`
|
|
Space int `json:"space"`
|
|
PrivateRepos int `json:"private_repos"`
|
|
Collaborators int `json:"collaborators"`
|
|
} `json:"plan"`
|
|
}
|
|
|
|
// Finder user by username
|
|
func (client Github) User(username string) (*User, error) {
|
|
reqOptions := &request.Options{Method: "GET", Header: request.Header{}, CodeProcess: processCodes}
|
|
client.authHeader(&reqOptions.Header)
|
|
res, _, err := request.JSON[*User](client.Host.ResolveReference(&url.URL{Path: path.Join(client.Host.Path, "users", url.PathEscape(username))}).String(), reqOptions)
|
|
return res, err
|
|
}
|
|
|
|
// Return current token User
|
|
func (client Github) Whoami() (*User, error) {
|
|
if client.Token == "" {
|
|
return nil, ErrToken
|
|
}
|
|
reqOptions := &request.Options{Method: "GET", Header: request.Header{}, CodeProcess: processCodes}
|
|
client.authHeader(&reqOptions.Header)
|
|
res, _, err := request.JSON[*User](client.Host.ResolveReference(&url.URL{Path: path.Join(client.Host.Path, "user")}).String(), reqOptions)
|
|
return res, err
|
|
}
|