forked from 0xch4z/dockerhub-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorganization.go
87 lines (75 loc) · 2.31 KB
/
organization.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
package dockerhub
import (
"context"
"fmt"
"net/http"
"time"
)
// OrganizationService Type Service
type OrganizationService service
// CreateOrganizationRequest struct
type CreateOrganizationRequest struct {
Orgname string `json:"orgname"`
Company string `json:"company"`
}
// Organization struct
type Organization struct {
ID string `json:"id"`
Orgname string `json:"orgname"`
FullName string `json:"full_name"`
Location string `json:"location"`
Company string `json:"company"`
ProfileURL string `json:"profile_url"`
DateJoined time.Time `json:"date_joined"`
GravatarURL string `json:"gravatar_url"`
GravatarEmail string `json:"gravatar_email"`
Type string `json:"type"`
}
// OrganizationList Struct
type OrganizationList struct {
Count int `json:"count"`
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []struct {
ID string `json:"id"`
Orgname string `json:"orgname"`
FullName string `json:"full_name"`
Location string `json:"location"`
Company string `json:"company"`
ProfileURL string `json:"profile_url"`
DateJoined time.Time `json:"date_joined"`
GravatarURL string `json:"gravatar_url"`
GravatarEmail string `json:"gravatar_email"`
Type string `json:"type"`
} `json:"results"`
}
// CreateOrganization Create new Organization
func (s *OrganizationService) CreateOrganization(ctx context.Context, organization, company string) (*Organization, error) {
url := "/orgs/"
org := CreateOrganizationRequest{
Orgname: organization,
Company: company,
}
req, err := s.client.NewRequest(http.MethodPost, url, org)
if err != nil {
return nil, err
}
res := &Organization{}
if _, err := s.client.Do(ctx, req, res); err != nil {
return nil, err
}
return res, nil
}
// GetOrganizations all organizations of user
func (s *OrganizationService) GetOrganizations(ctx context.Context, pageSize int) (*OrganizationList, error) {
slug := fmt.Sprintf("/user/orgs/?page_size=%d", pageSize)
req, err := s.client.NewRequest(http.MethodGet, slug, nil)
if err != nil {
return nil, err
}
res := &OrganizationList{}
if _, err := s.client.Do(ctx, req, res); err != nil {
return nil, err
}
return res, nil
}