|
| 1 | +// Copyright 2015 The Gogs Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package gogs |
| 6 | + |
| 7 | +import ( |
| 8 | + "bytes" |
| 9 | + "encoding/json" |
| 10 | + "fmt" |
| 11 | + "net/http" |
| 12 | +) |
| 13 | + |
| 14 | +type Organization struct { |
| 15 | + ID int64 `json:"id"` |
| 16 | + UserName string `json:"username"` |
| 17 | + FullName string `json:"full_name"` |
| 18 | + AvatarUrl string `json:"avatar_url"` |
| 19 | + Description string `json:"description"` |
| 20 | + Website string `json:"website"` |
| 21 | + Location string `json:"location"` |
| 22 | +} |
| 23 | + |
| 24 | +func (c *Client) ListMyOrgs() ([]*Organization, error) { |
| 25 | + orgs := make([]*Organization, 0, 5) |
| 26 | + return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs) |
| 27 | +} |
| 28 | + |
| 29 | +func (c *Client) ListUserOrgs(user string) ([]*Organization, error) { |
| 30 | + orgs := make([]*Organization, 0, 5) |
| 31 | + return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs) |
| 32 | +} |
| 33 | + |
| 34 | +func (c *Client) GetOrg(orgname string) (*Organization, error) { |
| 35 | + org := new(Organization) |
| 36 | + return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org) |
| 37 | +} |
| 38 | + |
| 39 | +type EditOrgOption struct { |
| 40 | + FullName string `json:"full_name"` |
| 41 | + Description string `json:"description"` |
| 42 | + Website string `json:"website"` |
| 43 | + Location string `json:"location"` |
| 44 | +} |
| 45 | + |
| 46 | +func (c *Client) EditOrg(orgname string, opt EditOrgOption) error { |
| 47 | + body, err := json.Marshal(&opt) |
| 48 | + if err != nil { |
| 49 | + return err |
| 50 | + } |
| 51 | + _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), |
| 52 | + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) |
| 53 | + return err |
| 54 | +} |
0 commit comments