-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
102 lines (79 loc) · 2.17 KB
/
user.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
package iaphub
import (
"encoding/json"
"errors"
"fmt"
"strconv"
)
type GetUserRequest struct {
UserId string
Platform Platform
Upsert bool
}
func (c *Client) GetUser(request GetUserRequest) (User, error) {
var user User
if request.UserId == "" || request.Platform == "" {
return user, fmt.Errorf("required parameter \"userId\" or \"platform\" is missing")
}
path := fmt.Sprintf(pathGetUser, c.appId, request.UserId)
params := map[string]string{
"platform": string(request.Platform),
}
if request.Upsert {
params["upsert"] = strconv.FormatBool(true)
}
response, err := c.requestGet(path, params)
if err != nil {
return user, err
}
err = json.Unmarshal(response, &user)
return user, err
}
type GetUserMigrateRequest struct {
UserId string
}
func (c *Client) GetUserMigrate(request GetUserMigrateRequest) (LatestUser, error) {
var latestUser LatestUser
if request.UserId == "" {
return latestUser, errors.New("required parameter")
}
var params map[string]string
path := fmt.Sprintf(pathMigrateUser, c.appId, request.UserId)
response, err := c.requestGet(path, params)
if err != nil {
return latestUser, err
}
err = json.Unmarshal(response, &latestUser)
return latestUser, err
}
type UpdateUserRequest struct {
UserId string `json:"userId"`
Country string `json:"country"`
Upsert bool `json:"upsert"`
Env Env `json:"environment,omitempty"`
Tags map[string]string `json:"tags"`
}
func (c *Client) UpdateUser(request UpdateUserRequest) error {
if request.UserId == "" || request.Country == "" {
return fmt.Errorf("required parameter \"userId\" or \"country\" is missing")
}
if request.Env == "" {
request.Env = c.env
}
path := fmt.Sprintf(pathUpdateUser, c.appId, request.UserId)
_, err := c.requestPost(path, map[string]string{}, request)
return err
}
type User struct {
ProductForSale []Product `json:"productsForSale"`
ActiveProducts []Product `json:"activeProducts"`
}
type Product struct {
Id string `json:"id"`
Type string `json:"type"`
Sku string `json:"sku"`
Purchase string `json:"purchase"`
}
type LatestUser struct {
UserId string `json:"userId"`
}