forked from cidertool/asc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_invitations.go
193 lines (165 loc) · 7.96 KB
/
users_invitations.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
Copyright (C) 2020 Aaron Sky.
This file is part of asc-go, a package for working with Apple's
App Store Connect API.
asc-go is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
asc-go is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with asc-go. If not, see <http://www.gnu.org/licenses/>.
*/
package asc
import (
"context"
"fmt"
)
// UserInvitation defines model for UserInvitation.
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitation
type UserInvitation struct {
Attributes *UserInvitationAttributes `json:"attributes,omitempty"`
ID string `json:"id"`
Links ResourceLinks `json:"links"`
Relationships *UserInvitationRelationships `json:"relationships,omitempty"`
Type string `json:"type"`
}
// UserInvitationAttributes defines model for UserInvitation.Attributes
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitation/attributes
type UserInvitationAttributes struct {
AllAppsVisible *bool `json:"allAppsVisible,omitempty"`
Email *Email `json:"email,omitempty"`
ExpirationDate *DateTime `json:"expirationDate,omitempty"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
ProvisioningAllowed *bool `json:"provisioningAllowed,omitempty"`
Roles []UserRole `json:"roles,omitempty"`
}
// UserInvitationRelationships defines model for UserInvitation.Relationships
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitation/relationships
type UserInvitationRelationships struct {
VisibleApps *PagedRelationship `json:"visibleApps,omitempty"`
}
// userInvitationCreateRequest defines model for userInvitationCreateRequest.
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitationcreaterequest/data
type userInvitationCreateRequest struct {
Attributes UserInvitationCreateRequestAttributes `json:"attributes"`
Relationships *userInvitationCreateRequestRelationships `json:"relationships,omitempty"`
Type string `json:"type"`
}
// UserInvitationCreateRequestAttributes are attributes for UserInvitationCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitationcreaterequest/data/attributes
type UserInvitationCreateRequestAttributes struct {
AllAppsVisible *bool `json:"allAppsVisible,omitempty"`
Email Email `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
ProvisioningAllowed *bool `json:"provisioningAllowed,omitempty"`
Roles []UserRole `json:"roles"`
}
// userInvitationCreateRequestRelationships are relationships for UserInvitationCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitationcreaterequest/data/relationships
type userInvitationCreateRequestRelationships struct {
VisibleApps *pagedRelationshipDeclaration `json:"visibleApps,omitempty"`
}
// UserInvitationResponse defines model for UserInvitationResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitationresponse
type UserInvitationResponse struct {
Data UserInvitation `json:"data"`
Included []App `json:"included,omitempty"`
Links DocumentLinks `json:"links"`
}
// UserInvitationsResponse defines model for UserInvitationsResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/userinvitationsresponse
type UserInvitationsResponse struct {
Data []UserInvitation `json:"data"`
Included []App `json:"included,omitempty"`
Links PagedDocumentLinks `json:"links"`
Meta *PagingInformation `json:"meta,omitempty"`
}
// ListInvitationsQuery is query options for ListInvitations
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_invited_users
type ListInvitationsQuery struct {
FieldsApps []string `url:"fields[apps],omitempty"`
FieldsUserInvitations []string `url:"fields[userInvitations],omitempty"`
FilterRoles []string `url:"filter[roles],omitempty"`
FilterEmail []string `url:"filter[email],omitempty"`
FilterVisibleApps []string `url:"filter[visibleApps],omitempty"`
Include []string `url:"include,omitempty"`
Limit int `url:"limit,omitempty"`
LimitVisibleApps int `url:"limit[visibleApps],omitempty"`
Sort []string `url:"sort,omitempty"`
Cursor string `url:"cursor,omitempty"`
}
// GetInvitationQuery is query options for GetInvitation
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_user_invitation_information
type GetInvitationQuery struct {
FieldsApps []string `url:"fields[apps],omitempty"`
FieldsUserInvitations []string `url:"fields[userInvitations],omitempty"`
Include []string `url:"include,omitempty"`
LimitVisibleApps int `url:"limit[visibleApps],omitempty"`
}
// ListInvitations gets a list of pending invitations to join your team.
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_invited_users
func (s *UsersService) ListInvitations(ctx context.Context, params *ListInvitationsQuery) (*UserInvitationsResponse, *Response, error) {
res := new(UserInvitationsResponse)
resp, err := s.client.get(ctx, "userInvitations", params, res)
return res, resp, err
}
// GetInvitation gets information about a pending invitation to join your team.
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_user_invitation_information
func (s *UsersService) GetInvitation(ctx context.Context, id string, params *GetInvitationQuery) (*UserInvitationResponse, *Response, error) {
url := fmt.Sprintf("userInvitations/%s", id)
res := new(UserInvitationResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// CreateInvitation invites a user with assigned user roles to join your team.
//
// https://developer.apple.com/documentation/appstoreconnectapi/invite_a_user
func (s *UsersService) CreateInvitation(ctx context.Context, attributes UserInvitationCreateRequestAttributes, visibleAppIDs []string) (*UserInvitationResponse, *Response, error) {
req := userInvitationCreateRequest{
Attributes: attributes,
Type: "userInvitations",
}
if len(visibleAppIDs) > 0 {
relationships := newPagedRelationshipDeclaration(visibleAppIDs, "apps")
req.Relationships = &userInvitationCreateRequestRelationships{
VisibleApps: &relationships,
}
}
res := new(UserInvitationResponse)
resp, err := s.client.post(ctx, "userInvitations", newRequestBody(req), res)
return res, resp, err
}
// CancelInvitation cancels a pending invitation for a user to join your team.
//
// https://developer.apple.com/documentation/appstoreconnectapi/cancel_a_user_invitation
func (s *UsersService) CancelInvitation(ctx context.Context, id string) (*Response, error) {
url := fmt.Sprintf("userInvitations/%s", id)
return s.client.delete(ctx, url, nil)
}
// ListVisibleAppsForInvitation gets a list of apps that will be visible to a user with a pending invitation.
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_all_apps_visible_to_an_invited_user
func (s *UsersService) ListVisibleAppsForInvitation(ctx context.Context, id string, params *ListVisibleAppsQuery) (*AppsResponse, *Response, error) {
url := fmt.Sprintf("userInvitations/%s/visibleApps", id)
res := new(AppsResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}