Skip to content

Commit a8598b0

Browse files
committed
Add UpdatePreference
1 parent 8e67f6f commit a8598b0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

user.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,33 @@ func UserMe(ctx context.Context, accessToken string) (*User, error) {
8989
}
9090
return resp.Data, nil
9191
}
92+
93+
func UpdatePreference(ctx context.Context, uid, sid, privateKey string, messageSource, conversationSource, currency string, threshold float64) (*User, error) {
94+
data, err := json.Marshal(map[string]interface{}{
95+
"receive_message_source": messageSource,
96+
"accept_conversation_source": conversationSource,
97+
"fiat_currency": currency,
98+
"transfer_notification_threshold": threshold,
99+
})
100+
if err != nil {
101+
return nil, err
102+
}
103+
path := "/me/preferences"
104+
token, err := SignAuthenticationToken(uid, sid, privateKey, "POST", path, string(data))
105+
body, err := Request(ctx, "POST", path, data, token)
106+
if err != nil {
107+
return nil, ServerError(ctx, err)
108+
}
109+
var resp struct {
110+
Data *User `json:"data"`
111+
Error Error `json:"error"`
112+
}
113+
err = json.Unmarshal(body, &resp)
114+
if err != nil {
115+
return nil, BadDataError(ctx)
116+
}
117+
if resp.Error.Code > 0 {
118+
return nil, resp.Error
119+
}
120+
return resp.Data, nil
121+
}

0 commit comments

Comments
 (0)