-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
73 lines (61 loc) · 1.8 KB
/
user.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
package alldebrid
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
//User is the user info struct
type User struct {
Status string `json:"status"`
Data userData `json:"data,omitempty"`
Error alldebridError `json:"error,omitempty"`
}
type userData struct {
User userDataUser `json:"user"`
}
type userDataUser struct {
Username string `json:"username"`
Email string `json:"email"`
IsPremium bool `json:"isPremium"`
IsTrial bool `json:"isTrial"`
PremiumUntil int `json:"premiumUntil"`
Lang string `json:"lang"`
PreferedDomain string `json:"preferedDomain"`
FidelityPoints int `json:"fidelityPoints"`
LimitedHostersQuotas userQuotas `json:"limitedHostersQuotas"`
}
type userQuotas struct {
Filefactory int `json:"filefactory"`
Gigapeta int `json:"gigapeta"`
Videobin int `json:"videobin"`
Isra int `json:"isra"`
Rapidgator int `json:"rapidgator"`
Rapidu int `json:"rapidu"`
Brupload int `json:"brupload"`
Uploadcloud int `json:"uploadcloud"`
Userscloud int `json:"userscloud"`
Wipfiles int `json:"wipfiles"`
Ddl int `json:"ddl"`
Flashbit int `json:"flashbit"`
Anzfile int `json:"anzfile"`
Keep2Share int `json:"keep2share"`
}
//GetUserInfo retrieves user infos from alldebrid
func (c *Client) GetUserInfo() (User, error) {
resp, err := http.Get(fmt.Sprintf(userinfo, getUserEndpoint(), c.ic.appName, c.ic.apikey))
if err != nil {
return User{}, err
}
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)
var usInfo User
err = decoder.Decode(&usInfo)
if err != nil {
return User{}, err
}
if usInfo.Status != "success" {
return User{}, errors.New(usInfo.Error.Message)
}
return usInfo, nil
}