-
Notifications
You must be signed in to change notification settings - Fork 0
/
achievements_create.go
86 lines (75 loc) · 2.35 KB
/
achievements_create.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
package appstore
import (
"context"
"fmt"
)
// https://developer.apple.com/documentation/appstoreconnectapi/create_an_achievement
func (c *Client) CreateAchievement(ctx context.Context, gameCenter *Resource[GameCenter], ach *Achievement) (*Resource[Achievement], error) {
url := "https://api.appstoreconnect.apple.com/v1/" + resourceTypeAchievements
req := createResource{
Type: resourceTypeAchievements,
Attr: ach,
Relations: relations{
GameCenter: &relationd{
Data: relation{
ID: gameCenter.ID,
Type: gameCenter.Type,
},
},
},
}
resp, err := doCreate[Achievement](c, ctx, url, req)
if err != nil {
return nil, fmt.Errorf("failed to create achievement: %w", err)
}
return resp, nil
}
// https://developer.apple.com/documentation/appstoreconnectapi/create_an_achievement_localization
func (c *Client) CreateAchievementLocalization(ctx context.Context, ach *Resource[Achievement], loc *AchievementLocalization) (*Resource[AchievementLocalization], error) {
url := "https://api.appstoreconnect.apple.com/v1/" + resourceTypeAchievementLocalizations
req := createResource{
Type: resourceTypeAchievementLocalizations,
Attr: loc,
Relations: relations{
Achievement: &relationd{
Data: relation{
ID: ach.ID,
Type: ach.Type,
},
},
},
}
resp, err := doCreate[AchievementLocalization](c, ctx, url, req)
if err != nil {
return nil, fmt.Errorf("failed to create achievement localization: %w", err)
}
return resp, nil
}
// https://developer.apple.com/documentation/appstoreconnectapi/create_an_achievement_image
func (c *Client) CreateAchievementImage(ctx context.Context, loc *Resource[AchievementLocalization], name string, data []byte) (*Resource[Asset], error) {
url := "https://api.appstoreconnect.apple.com/v1/" + resourceTypeAchievementImages
req := createResource{
Type: resourceTypeAchievementImages,
Attr: createAsset{
Name: name,
Size: len(data),
},
Relations: relations{
AchievementLocalization: &relationd{
Data: relation{
ID: loc.ID,
Type: loc.Type,
},
},
},
}
asset, err := doCreate[Asset](c, ctx, url, req)
if err != nil {
return nil, fmt.Errorf("failed to create achievement image: %w", err)
}
asset, err = c.uploadAsset(ctx, asset, data)
if err != nil {
return nil, fmt.Errorf("failed to upload achievement image: %w", err)
}
return asset, nil
}