Implement root handler
This commit is contained in:
@@ -360,3 +360,32 @@ func (rd *RealDebrid) GetDownloads(page, offset int) ([]Download, int, error) {
|
||||
rd.log.Debugf("Got %d downloads (page %d), total count is %d", len(allDownloads)+offset, page, totalCount)
|
||||
return allDownloads, totalCount, nil
|
||||
}
|
||||
|
||||
// GetUserInformation gets the current user information.
|
||||
func (rd *RealDebrid) GetUserInformation() (*User, error) {
|
||||
// Construct request URL
|
||||
reqURL := "https://api.real-debrid.com/rest/1.0/user"
|
||||
req, err := http.NewRequest("GET", reqURL, nil)
|
||||
if err != nil {
|
||||
rd.log.Errorf("Error when creating a user information request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send the request
|
||||
resp, err := rd.client.Do(req)
|
||||
if err != nil {
|
||||
rd.log.Errorf("Error when executing the user information request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Decode the JSON response into the User struct
|
||||
var user User
|
||||
err = json.NewDecoder(resp.Body).Decode(&user)
|
||||
if err != nil {
|
||||
rd.log.Errorf("Error when decoding user information JSON: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
@@ -107,3 +107,15 @@ type ActiveTorrentCountResponse struct {
|
||||
DownloadingCount int `json:"nb"`
|
||||
MaxNumberOfTorrents int `json:"limit"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Points int `json:"points"` // Fidelity points
|
||||
Locale string `json:"locale"` // User language
|
||||
Avatar string `json:"avatar"` // URL
|
||||
Type string `json:"type"` // "premium" or "free"
|
||||
Premium int `json:"premium"` // seconds left as a Premium user
|
||||
Expiration string `json:"expiration"` // jsonDate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user