forked from shuheiktgw/go-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizations.go
111 lines (96 loc) · 3.34 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
)
// OrganizationsService handles communication with the
// organization related methods of the Travis CI API.
type OrganizationsService struct {
client *Client
}
// Organization is a standard representation of an individual organization
//
// Travis CI API docs: https://developer.travis-ci.com/resource/organization#standard-representation
type Organization struct {
// Value uniquely identifying the organization
Id *uint `json:"id,omitempty"`
// Login set on GitHub
Login *string `json:"login,omitempty"`
// Name set on GitHub
Name *string `json:"name,omitempty"`
// Id set on GitHub
GithubId *uint `json:"github_id,omitempty"`
// Avatar_url set on GitHub
AvatarUrl *string `json:"avatar_url,omitempty"`
// Whether or not the organization has an education account
Education *bool `json:"education,omitempty"`
// Repositories belonging to this organization.
Repositories []*Repository `json:"repositories,omitempty"`
// Installation belonging to the organization
Installation *Installation `json:"installation,omitempty"`
*Metadata
}
// OrganizationOption specifies the optional parameters for organization endpoint
type OrganizationOption struct {
// List of attributes to eager load
Include []string `url:"include,omitempty,comma"`
}
// OrganizationsOption specifies the optional parameters for organizations endpoint
type OrganizationsOption struct {
// How many organizations to include in the response
Limit int `url:"limit,omitempty"`
// How many organizations to skip before the first entry in the response
Offset int `url:"offset,omitempty"`
// Attributes to sort organizations by
SortBy string `url:"sort_by,omitempty"`
// List of attributes to eager load
Include []string `url:"include,omitempty,comma"`
}
// organizationsResponse represents a response
// from organizations endpoints
type organizationsResponse struct {
Organizations []*Organization `json:"organizations,omitempty"`
}
// Find fetches an organization with the given id
//
// Travis CI API docs: https://developer.travis-ci.com/resource/organization#find
func (os *OrganizationsService) Find(ctx context.Context, id uint, opt *OrganizationOption) (*Organization, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("/org/%d", id), opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest(http.MethodGet, u, nil, nil)
if err != nil {
return nil, nil, err
}
var org Organization
resp, err := os.client.Do(ctx, req, &org)
if err != nil {
return nil, resp, err
}
return &org, resp, err
}
// List fetches a list of organizations the current user is a member of
//
// Travis CI API docs: https://developer.travis-ci.com/resource/organizations#for_current_user
func (os *OrganizationsService) List(ctx context.Context, opt *OrganizationsOption) ([]*Organization, *http.Response, error) {
u, err := urlWithOptions("/orgs", opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest(http.MethodGet, u, nil, nil)
if err != nil {
return nil, nil, err
}
var or organizationsResponse
resp, err := os.client.Do(ctx, req, &or)
if err != nil {
return nil, resp, err
}
return or.Organizations, resp, err
}