Implement root handler

This commit is contained in:
Ben Sarmiento
2023-11-30 23:08:16 +01:00
parent 0ad879066e
commit 9f81b2b1d0
9 changed files with 105 additions and 127 deletions

View File

@@ -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
}