/
organizations.go
83 lines (67 loc) · 2.19 KB
/
organizations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 Mark Wolfe. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buildkite
import "fmt"
// OrganizationsService handles communication with the organization related
// methods of the buildkite API.
//
// buildkite API docs: https://buildkite.com/docs/api/organizations
type OrganizationsService struct {
client *Client
}
// Organization represents a buildkite organization.
type Organization struct {
ID *string `json:"id,omitempty"`
URL *string `json:"url,omitempty"`
WebURL *string `json:"web_url,omitempty"`
Name *string `json:"name,omitempty"`
Slug *string `json:"slug,omitempty"`
Repository *string `json:"repository,omitempty"`
PipelinesURL *string `json:"pipelines_url,omitempty"`
AgentsURL *string `json:"agents_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}
// OrganizationListOptions specifies the optional parameters to the
// OrganizationsService.List method.
type OrganizationListOptions struct {
ListOptions
}
// List the organizations for the current user.
//
// buildkite API docs: https://buildkite.com/docs/api/organizations#list-organizations
func (os *OrganizationsService) List(opt *OrganizationListOptions) ([]Organization, *Response, error) {
var u string
u = fmt.Sprintf("v2/organizations")
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
orgs := new([]Organization)
resp, err := os.client.Do(req, orgs)
if err != nil {
return nil, resp, err
}
return *orgs, resp, err
}
// Get fetches an organization
//
// buildkite API docs: https://buildkite.com/docs/api/organizations#get-an-organization
func (os *OrganizationsService) Get(slug string) (*Organization, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s", slug)
req, err := os.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
organization := new(Organization)
resp, err := os.client.Do(req, organization)
if err != nil {
return nil, resp, err
}
return organization, resp, err
}