-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathusers.go
99 lines (86 loc) · 2.33 KB
/
users.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
package dropbox
import (
"encoding/json"
)
// Users client for user accounts.
type Users struct {
*Client
}
// NewUsers client.
func NewUsers(config *Config) *Users {
return &Users{
Client: &Client{
Config: config,
},
}
}
// GetAccountInput request input.
type GetAccountInput struct {
AccountID string `json:"account_id"`
}
// GetAccountOutput request output.
type GetAccountOutput struct {
AccountID string `json:"account_id"`
Name struct {
GivenName string `json:"given_name"`
Surname string `json:"surname"`
FamiliarName string `json:"familiar_name"`
DisplayName string `json:"display_name"`
} `json:"name"`
}
// GetAccount returns information about a user's account.
func (c *Users) GetAccount(in *GetAccountInput) (out *GetAccountOutput, err error) {
body, err := c.call("/users/get_account", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetCurrentAccountOutput request output.
type GetCurrentAccountOutput struct {
AccountID string `json:"account_id"`
Name struct {
GivenName string `json:"given_name"`
Surname string `json:"surname"`
FamiliarName string `json:"familiar_name"`
DisplayName string `json:"display_name"`
} `json:"name"`
Email string `json:"email"`
Locale string `json:"locale"`
ReferralLink string `json:"referral_link"`
IsPaired bool `json:"is_paired"`
AccountType struct {
Tag string `json:".tag"`
} `json:"account_type"`
Country string `json:"country"`
}
// GetCurrentAccount returns information about the current user's account.
func (c *Users) GetCurrentAccount() (out *GetCurrentAccountOutput, err error) {
body, err := c.call("/users/get_current_account", nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetSpaceUsageOutput request output.
type GetSpaceUsageOutput struct {
Used uint64 `json:"used"`
Allocation struct {
Used uint64 `json:"used"`
Allocated uint64 `json:"allocated"`
} `json:"allocation"`
}
// GetSpaceUsage returns space usage information for the current user's account.
func (c *Users) GetSpaceUsage() (out *GetSpaceUsageOutput, err error) {
body, err := c.call("/users/get_space_usage", nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}