user.go 990 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gitote
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. // User represents a API user.
  7. type User struct {
  8. ID int64 `json:"id"`
  9. UserName string `json:"login"`
  10. FullName string `json:"full_name"`
  11. Website string `json:"website"`
  12. Email string `json:"email"`
  13. Company string `json:"company"`
  14. Location string `json:"location"`
  15. Description string `json:"bio"`
  16. IsAdmin bool `json:"is_admin"`
  17. AvatarUrl string `json:"avatar_url"`
  18. }
  19. // MarshalJSON implements the json.Marshaler interface for User
  20. func (u User) MarshalJSON() ([]byte, error) {
  21. // Re-declaring User to avoid recursion
  22. type shadow User
  23. return json.Marshal(struct {
  24. shadow
  25. // LEGACY [Gitote 1.0]: remove field(s) for backward compatibility
  26. CompatUserName string `json:"username"`
  27. }{shadow(u), u.UserName})
  28. }
  29. func (c *Client) GetUserInfo(user string) (*User, error) {
  30. u := new(User)
  31. err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
  32. return u, err
  33. }