user.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package gitote
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "time"
  6. )
  7. // User represents a API user.
  8. type User struct {
  9. ID int64 `json:"id"`
  10. UserName string `json:"login"`
  11. FullName string `json:"full_name"`
  12. Website string `json:"website"`
  13. Email string `json:"email"`
  14. Company string `json:"company"`
  15. Location string `json:"location"`
  16. Description string `json:"bio"`
  17. IsAdmin bool `json:"site_admin"`
  18. NumRepos int `json:"repos"`
  19. Created time.Time `json:"created_at"`
  20. Updated time.Time `json:"updated_at"`
  21. NumFollowing int `json:"following"`
  22. NumFollowers int `json:"followers"`
  23. AvatarUrl string `json:"avatar_url"`
  24. FollowersURL string `json:"followers_url"`
  25. FollowingURL string `json:"following_url"`
  26. OrganizationsURL string `json:"organizations_url"`
  27. ReposURL string `json:"repos_url"`
  28. }
  29. // MarshalJSON implements the json.Marshaler interface for User
  30. func (u User) MarshalJSON() ([]byte, error) {
  31. // Re-declaring User to avoid recursion
  32. type shadow User
  33. return json.Marshal(struct {
  34. shadow
  35. // LEGACY [Gitote 1.0]: remove field(s) for backward compatibility
  36. CompatUserName string `json:"username"`
  37. }{shadow(u), u.UserName})
  38. }
  39. func (c *Client) GetUserInfo(user string) (*User, error) {
  40. u := new(User)
  41. err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
  42. return u, err
  43. }