org.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package gitote
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. )
  7. type Organization struct {
  8. ID int64 `json:"id"`
  9. UserName string `json:"username"`
  10. FullName string `json:"full_name"`
  11. AvatarUrl string `json:"avatar_url"`
  12. Description string `json:"description"`
  13. Website string `json:"website"`
  14. Location string `json:"location"`
  15. }
  16. func (c *Client) ListMyOrgs() ([]*Organization, error) {
  17. orgs := make([]*Organization, 0, 5)
  18. return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
  19. }
  20. func (c *Client) ListUserOrgs(user string) ([]*Organization, error) {
  21. orgs := make([]*Organization, 0, 5)
  22. return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs)
  23. }
  24. func (c *Client) GetOrg(orgname string) (*Organization, error) {
  25. org := new(Organization)
  26. return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
  27. }
  28. type CreateOrgOption struct {
  29. UserName string `json:"username" binding:"Required"`
  30. FullName string `json:"full_name"`
  31. Description string `json:"description"`
  32. Website string `json:"website"`
  33. Location string `json:"location"`
  34. }
  35. type EditOrgOption struct {
  36. FullName string `json:"full_name"`
  37. Description string `json:"description"`
  38. Website string `json:"website"`
  39. Location string `json:"location"`
  40. }
  41. func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
  42. body, err := json.Marshal(&opt)
  43. if err != nil {
  44. return err
  45. }
  46. _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
  47. return err
  48. }