-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.go
More file actions
51 lines (43 loc) · 1.13 KB
/
user.go
File metadata and controls
51 lines (43 loc) · 1.13 KB
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
package ulule
import (
"errors"
"strconv"
)
// GetUser returns a User for for given ID
func (c *Client) GetUser(userID int) (*User, error) {
userIDStr := strconv.Itoa(userID)
resp := &User{}
err := c.apiget("/users/"+userIDStr, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Me returns connected user
func (c *Client) Me() (*User, error) {
resp := &User{}
err := c.apiget("/me", resp)
if err != nil {
return nil, err
}
return resp, nil
}
// GetUserOrders lists orders for a user
// limit and offset stand for pagination
// the boolean returns indicates if it was the last
// page or not.
// This function only works for connected user.
func (c *Client) GetUserOrders(u *User, limit, offset int) ([]*Order, error, bool) {
if u == nil {
return nil, errors.New("user can't be nil"), false
}
userIDStr := strconv.Itoa(u.ID)
limitStr := strconv.Itoa(limit)
offsetStr := strconv.Itoa(offset)
orders := &ListOrderResponse{}
err := c.apiget("/users/"+userIDStr+"/orders?limit="+limitStr+"&offset="+offsetStr, orders)
if err != nil {
return nil, err, false
}
return orders.Orders, nil, orders.Meta.Next == ""
}