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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user