-
Notifications
You must be signed in to change notification settings - Fork 2
/
requests.go
91 lines (78 loc) · 2.31 KB
/
requests.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
package customercredit
import (
"encoding/json"
"github.com/Huawei/gophercloud"
)
type QueryCreditOpts struct {
//Customer ID
CustomerId string `q:"customer_id" required:"true"`
}
type SetCreditOpts struct {
//客户ID。
CustomerId string `json:"customerId" required:"true"`
//调整的目标金额。
AdjustmentAmount float64 `json:"adjustmentAmount" required:"true"`
//金额单位。
MeasureId *int `json:"measureId" required:"true"`
}
type QueryCreditOptsBuilder interface {
ToQueryCreditMap() (string, error)
}
func (opts QueryCreditOpts) ToQueryCreditMap() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
type SetCreditOptsBuilder interface {
ToSetCreditMap() (map[string]interface{}, error)
}
func (opts SetCreditOpts) ToSetCreditMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
/**
* You can use REST APIs to configure customers' credit limits on your sales platform.
* This API can be invoked only by the partner account AK/SK or token.
*/
func SetCredit(client *gophercloud.ServiceClient, opts SetCreditOptsBuilder) (r SetCreditResult) {
domainID := client.ProviderClient.DomainID
if opts != nil {
body, err := opts.ToSetCreditMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(getSetCreditURL(client, domainID), body, nil, &gophercloud.RequestOpts{
OkCodes: []int{204},
HandleError: func(httpStatus int, responseContent string) error {
var setCrediterr SetCreditError
message := responseContent
err := json.Unmarshal([]byte(responseContent), &setCrediterr)
if err == nil {
return &setCrediterr
}
return &gophercloud.UnifiedError{
ErrCode: gophercloud.MatchErrorCode(httpStatus, message),
ErrMessage: message,
}
},
})
}
return
}
/**
* You can use REST APIs to query customers' credit limits on your sales platform.
* This API can be invoked only by the partner account AK/SK or token.
*/
func QueryCredit(client *gophercloud.ServiceClient, opts QueryCreditOptsBuilder)(r QueryCreditResult) {
domainID := client.ProviderClient.DomainID
url := getQueryCreditURL(client,domainID)
if opts != nil {
query, err := opts.ToQueryCreditMap()
if err != nil {
r.Err = err
return
}
url += query
_, r.Err = client.Get(url, &r.Body, nil)
}
return
}