1
0
Fork 0

Fetch user orgs task

This commit is contained in:
Gregory Eremin 2015-03-19 17:04:59 +07:00
parent 6d1e181db4
commit a284401d3c
2 changed files with 24 additions and 2 deletions

View File

@ -5,9 +5,9 @@ import (
)
type Org struct {
GithubID uint64 `json:"github_id"`
Login string `json:"login"`
Descr string `json:"descr"`
ID uint64 `json:"id"`
Company string `json:"company"`
AvatarURL string `json:"avatar_url"`
}

View File

@ -37,3 +37,25 @@ func FetchUserInfo(token, login string) (u *db.User, err error) {
return
}
func FetchUserOrgs(token string) (orgs []*db.Org, err error) {
client := newGithubClient(token)
var ghorgs []github.Organization
var resp *github.Response
if ghorgs, resp, err = client.Organizations.List("", nil); err != nil {
return
}
saveResponseMeta(token, resp)
for _, ghorg := range ghorgs {
org := &db.Org{
GithubID: uint64(*ghorg.ID),
Login: *ghorg.Login,
Company: *ghorg.Company,
AvatarURL: *ghorg.AvatarURL,
}
orgs = append(orgs, org)
}
return
}