forked from huaweicloud/huaweicloud-sdk-go
/
request.go
162 lines (131 loc) · 4.86 KB
/
request.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
package customermanagement
import (
"encoding/json"
"github.com/gophercloud/gophercloud"
)
type CheckCustomerRegisterInfoOpts struct {
//The options are email, mobile, or name
SearchType string `json:"searchType" required:"true"`
//Mobile number, email address, or account name.
SearchKey string `json:"searchKey" required:"true"`
}
type CheckCustomerRegisterInfoBuilder interface {
ToCheckCustomerRegisterInfoMap() (map[string]interface{}, error)
}
func (opts CheckCustomerRegisterInfoOpts) ToCheckCustomerRegisterInfoMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
type CreateCustomerOpts struct {
//HUAWEI CLOUD username of the customer.
DomainName string `json:"domainName,omitempty"`
//Mobile number.
MobilePhone string `json:"mobilePhone,omitempty"`
//Mobile number country code
CountryCode string `json:"countryCode,omitempty"`
//Verification code
VerificationCode string `json:"verificationCode,omitempty"`
//Unique ID of the user on the third-party system, which is assigned by the partner.
XAccountId string `json:"xAccountId" required:"true"`
//Platform ID assigned by Huawei to a partner.
XAccountType string `json:"xAccountType" required:"true"`
//password
Password string `json:"password,omitempty"`
//Indicates whether to disable the marketing message sending function.
IsCloseMarketMs string `json:"isCloseMarketMs,omitempty"`
}
type CreateCustomerOptsBuilder interface {
ToCreateCustomerMap() (map[string]interface{}, error)
}
func (opts CreateCustomerOpts) ToCreateCustomerMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
type QueryCustomerOpts struct {
//Account name
DomainName string `json:"domainName,omitempty"`
//Real-name authentication name
Name string `json:"name,omitempty"`
//Page to be queried
Offset int `json:"offset,omitempty"`
//Number of records on each page
Limit int `json:"limit,omitempty"`
//Tag
Label string `json:"label,omitempty"`
//Association type
CooperationType string `json:"cooperationType,omitempty"`
//Start time of the association time range (UTC time)
CooperationTimeStart string `json:"cooperationTimeStart,omitempty"`
//End time of the association time range (UTC time)
CooperationTimeEnd string `json:"cooperationTimeEnd,omitempty"`
}
type QueryCustomerOptsBuilder interface {
ToQueryCustomerMap() (map[string]interface{}, error)
}
func (opts QueryCustomerOpts) ToQueryCustomerMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
/**
* This API is used to check whether the account name, and mobile number or email address entered by the customer can be used for registration.
* This API can be invoked only by the partner AK/SK or token.
*/
func CheckCustomerRegisterInfo(client *gophercloud.ServiceClient, opts CheckCustomerRegisterInfoBuilder) (r CheckCustomerRegisterInfoResult) {
domainID := client.ProviderClient.DomainID
if opts != nil {
body, err := opts.ToCheckCustomerRegisterInfoMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(getCheckCustomerRegisterInfoURL(client, domainID), body, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
}
return
}
/**
* This API is used to create a HUAWEI CLOUD account for a customer when the customer creates an account on your sales platform, and bind the customer account on the partner sales platform to the HUAWEI CLOUD account. In addition, the HUAWEI CLOUD account is bound to the partner account.
* This API can be invoked only by the partner AK/SK or token..
*/
func CreateCustomer(client *gophercloud.ServiceClient, opts CreateCustomerOptsBuilder) (r CreateCustomerResult) {
domainID := client.ProviderClient.DomainID
if opts != nil {
body, err := opts.ToCreateCustomerMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(getCreateCustomerURL(client, domainID), body, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
HandleError: func(httpStatus int, responseContent string) error {
var createCustomerResp CreateCustomerResp
message := responseContent
err := json.Unmarshal([]byte(responseContent), &createCustomerResp)
if err == nil {
return &createCustomerResp
}
return &gophercloud.UnifiedError{
ErrCode: gophercloud.MatchErrorCode(httpStatus, message),
ErrMessage: message,
}
},
})
}
return
}
/**
* This API is used to query your customers.
* This API can be invoked only by the partner account AK/SK or token.
*/
func QueryCustomer(client *gophercloud.ServiceClient, opts QueryCustomerOptsBuilder) (r QueryCustomerResult) {
domainID := client.ProviderClient.DomainID
if opts != nil {
body, err := opts.ToQueryCustomerMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(getQueryCustomerURL(client, domainID), body, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
}
return
}