From a284401d3c09510ce744c591bb36132078952170 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 19 Mar 2015 17:04:59 +0700 Subject: [PATCH] Fetch user orgs task --- db/org.go | 4 ++-- task/user.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/db/org.go b/db/org.go index d838545..b73fbf2 100644 --- a/db/org.go +++ b/db/org.go @@ -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"` } diff --git a/task/user.go b/task/user.go index c86ef1e..5cde9b6 100644 --- a/task/user.go +++ b/task/user.go @@ -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 +}