forked from cidertool/asc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps_metadata_previews.go
244 lines (214 loc) · 9.63 KB
/
apps_metadata_previews.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
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"
)
// PreviewType defines model for PreviewType.
//
// https://developer.apple.com/documentation/appstoreconnectapi/previewtype
type PreviewType string
const (
// PreviewTypeAppleTV is a preview type for Apple TV.
PreviewTypeAppleTV PreviewType = "APPLE_TV"
// PreviewTypeDesktop is a preview type for Desktop.
PreviewTypeDesktop PreviewType = "DESKTOP"
// PreviewTypeiPad105 is a preview type for iPad 10.5".
PreviewTypeiPad105 PreviewType = "IPAD_105"
// PreviewTypeiPad97 is a preview type for iPad 9.7".
PreviewTypeiPad97 PreviewType = "IPAD_97"
// PreviewTypeiPadPro129 is a preview type for iPad Pro 12.9".
PreviewTypeiPadPro129 PreviewType = "IPAD_PRO_129"
// PreviewTypeiPadPro3Gen11 is a preview type for iPad Pro 3rd Gen 11".
PreviewTypeiPadPro3Gen11 PreviewType = "IPAD_PRO_3GEN_11"
// PreviewTypeiPadPro3Gen129 is a preview type for iPad Pro 3rd Gen 12.9".
PreviewTypeiPadPro3Gen129 PreviewType = "IPAD_PRO_3GEN_129"
// PreviewTypeiPhone35 is a preview type for iPhone 3.5".
PreviewTypeiPhone35 PreviewType = "IPHONE_35"
// PreviewTypeiPhone40 is a preview type for iPhone 4".
PreviewTypeiPhone40 PreviewType = "IPHONE_40"
// PreviewTypeiPhone47 is a preview type for iPhone 4.7".
PreviewTypeiPhone47 PreviewType = "IPHONE_47"
// PreviewTypeiPhone55 is a preview type for iPhone 5.5".
PreviewTypeiPhone55 PreviewType = "IPHONE_55"
// PreviewTypeiPhone58 is a preview type for iPhone 5.8".
PreviewTypeiPhone58 PreviewType = "IPHONE_58"
// PreviewTypeiPhone65 is a preview type for iPhone 6.5".
PreviewTypeiPhone65 PreviewType = "IPHONE_65"
// PreviewTypeWatchSeries3 is a preview type for Apple Watch Series 3.
PreviewTypeWatchSeries3 PreviewType = "WATCH_SERIES_3"
// PreviewTypeWatchSeries4 is a preview type for Apple Watch Series 4.
PreviewTypeWatchSeries4 PreviewType = "WATCH_SERIES_4"
)
// AppPreview defines model for AppPreview.
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreview
type AppPreview struct {
Attributes *AppPreviewAttributes `json:"attributes,omitempty"`
ID string `json:"id"`
Links ResourceLinks `json:"links"`
Relationships *AppPreviewRelationships `json:"relationships,omitempty"`
Type string `json:"type"`
}
// AppPreviewAttributes defines model for AppPreview.Attributes
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreview/attributes
type AppPreviewAttributes struct {
AssetDeliveryState *AppMediaAssetState `json:"assetDeliveryState,omitempty"`
FileName *string `json:"fileName,omitempty"`
FileSize *int64 `json:"fileSize,omitempty"`
MimeType *string `json:"mimeType,omitempty"`
PreviewFrameTimeCode *string `json:"previewFrameTimeCode,omitempty"`
PreviewImage *ImageAsset `json:"previewImage,omitempty"`
SourceFileChecksum *string `json:"sourceFileChecksum,omitempty"`
UploadOperations []UploadOperation `json:"uploadOperations,omitempty"`
VideoURL *string `json:"videoUrl,omitempty"`
}
// AppPreviewRelationships defines model for AppPreview.Relationships
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreview/relationships
type AppPreviewRelationships struct {
AppPreviewSet *Relationship `json:"appPreviewSet,omitempty"`
}
// AppPreviewCreateRequest defines model for AppPreviewCreateRequest.
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewcreaterequest/data
type appPreviewCreateRequest struct {
Attributes appPreviewCreateRequestAttributes `json:"attributes"`
Relationships appPreviewCreateRequestRelationships `json:"relationships"`
Type string `json:"type"`
}
// AppPreviewCreateRequestAttributes are attributes for AppPreviewCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewcreaterequest/data/attributes
type appPreviewCreateRequestAttributes struct {
FileName string `json:"fileName"`
FileSize int64 `json:"fileSize"`
MimeType *string `json:"mimeType,omitempty"`
PreviewFrameTimeCode *string `json:"previewFrameTimeCode,omitempty"`
}
// AppPreviewCreateRequestRelationships are relationships for AppPreviewCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewcreaterequest/data/relationships
type appPreviewCreateRequestRelationships struct {
AppPreviewSet relationshipDeclaration `json:"appPreviewSet"`
}
// AppPreviewUpdateRequest defines model for AppPreviewUpdateRequest.
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewupdaterequest/data
type appPreviewUpdateRequest struct {
Attributes *appPreviewUpdateRequestAttributes `json:"attributes,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
}
// AppPreviewUpdateRequestAttributes are attributes for AppPreviewUpdateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewupdaterequest/data/attributes
type appPreviewUpdateRequestAttributes struct {
PreviewFrameTimeCode *string `json:"previewFrameTimeCode,omitempty"`
SourceFileChecksum *string `json:"sourceFileChecksum,omitempty"`
Uploaded *bool `json:"uploaded,omitempty"`
}
// AppPreviewResponse defines model for AppPreviewResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewresponse
type AppPreviewResponse struct {
Data AppPreview `json:"data"`
Links DocumentLinks `json:"links"`
}
// AppPreviewsResponse defines model for AppPreviewsResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/apppreviewsresponse
type AppPreviewsResponse struct {
Data []AppPreview `json:"data"`
Links PagedDocumentLinks `json:"links"`
Meta *PagingInformation `json:"meta,omitempty"`
}
// ImageAsset defines model for ImageAsset.
//
// https://developer.apple.com/documentation/appstoreconnectapi/imageasset
type ImageAsset struct {
Height *int `json:"height,omitempty"`
TemplateURL *string `json:"templateUrl,omitempty"`
Width *int `json:"width,omitempty"`
}
// GetAppPreviewQuery are query options for GetAppPreview
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_app_preview_information
type GetAppPreviewQuery struct {
FieldsAppPreviews []string `url:"fields[appPreviews],omitempty"`
Include []string `url:"include,omitempty"`
}
// GetAppPreview gets information about an app preview and its upload and processing status.
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_app_preview_information
func (s *AppsService) GetAppPreview(ctx context.Context, id string, params *GetAppPreviewQuery) (*AppPreviewResponse, *Response, error) {
url := fmt.Sprintf("appPreviews/%s", id)
res := new(AppPreviewResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// CreateAppPreview adds a new preview to a preview set.
//
// https://developer.apple.com/documentation/appstoreconnectapi/create_an_app_preview
func (s *AppsService) CreateAppPreview(ctx context.Context, fileName string, fileSize int64, appPreviewSetID string) (*AppPreviewResponse, *Response, error) {
req := appPreviewCreateRequest{
Attributes: appPreviewCreateRequestAttributes{
FileName: fileName,
FileSize: fileSize,
},
Relationships: appPreviewCreateRequestRelationships{
AppPreviewSet: relationshipDeclaration{
Data: RelationshipData{
ID: appPreviewSetID,
Type: "appPreviewSets",
},
},
},
Type: "appPreviews",
}
res := new(AppPreviewResponse)
resp, err := s.client.post(ctx, "appPreviews", newRequestBody(req), res)
return res, resp, err
}
// CommitAppPreview commits an app preview after uploading it.
//
// https://developer.apple.com/documentation/appstoreconnectapi/modify_an_app_preview
func (s *AppsService) CommitAppPreview(ctx context.Context, id string, uploaded *bool, sourceFileChecksum *string, previewFrameTimeCode *string) (*AppPreviewResponse, *Response, error) {
req := appPreviewUpdateRequest{
ID: id,
Type: "appPreviews",
}
if uploaded != nil || sourceFileChecksum != nil || previewFrameTimeCode != nil {
req.Attributes = &appPreviewUpdateRequestAttributes{
Uploaded: uploaded,
SourceFileChecksum: sourceFileChecksum,
PreviewFrameTimeCode: previewFrameTimeCode,
}
}
url := fmt.Sprintf("appPreviews/%s", id)
res := new(AppPreviewResponse)
resp, err := s.client.patch(ctx, url, newRequestBody(req), res)
return res, resp, err
}
// DeleteAppPreview deletes an app preview that is associated with a preview set.
//
// https://developer.apple.com/documentation/appstoreconnectapi/delete_an_app_preview
func (s *AppsService) DeleteAppPreview(ctx context.Context, id string) (*Response, error) {
url := fmt.Sprintf("appPreviews/%s", id)
return s.client.delete(ctx, url, nil)
}