/// <summary> /// Fires a connection request to the api. /// </summary> /// <param name="email">Email of the User</param> /// <param name="password">Password of the User</param> /// <returns>Return if the connection was succesful</returns> public bool Connect(string email, string password) { //Calculating the Login and Device secret _loginSecret = Utils.GetSecret(email, password, Utils.ServerDomain); _deviceSecret = Utils.GetSecret(email, password, Utils.DeviceDomain); //Creating the queryRequest for the connection request string connectQueryUrl = $"/my/connect?email={HttpUtility.UrlEncode(email)}&appkey={HttpUtility.UrlEncode(Utils.AppKey)}"; //Calling the queryRequest var response = _apiHandler.CallServer <LoginObject>(connectQueryUrl, _loginSecret); //If the response is null the connection was not successfull if (response == null) { return(false); } //Else we are saving the response which contains the SessionToken, RegainToken and the RequestId LoginObject = response; LoginObject.Email = email; LoginObject.Password = password; LoginObject.ServerEncryptionToken = Utils.UpdateEncryptionToken(_loginSecret, LoginObject.SessionToken); LoginObject.DeviceEncryptionToken = Utils.UpdateEncryptionToken(_deviceSecret, LoginObject.SessionToken); IsConnected = true; return(true); }
/// <summary> /// Lists all Devices which are currently connected to your my.jdownloader.org account. /// </summary> /// <returns>Returns a list of your currently connected devices.</returns> public async Task <List <DeviceObject>?> GetDevices() { if (_loginObject is null) { return(new List <DeviceObject>()); } var devices = new List <DeviceObject>(); var query = $"/my/listdevices?sessiontoken={HttpUtility.UrlEncode(_loginObject.SessionToken)}"; var response = await JDownloaderApiHandler.CallServer <DeviceJsonReturnObject>(query, _loginObject.ServerEncryptionToken); if (response == default) { return(devices); } devices = response.Devices; return(devices); }
/// <summary> /// Disconnects the your client from the api /// </summary> /// <returns>True if successfull else false</returns> public async Task <bool> Disconnect() { if (_loginObject is null) { return(false); } var query = $"/my/disconnect?sessiontoken={HttpUtility.UrlEncode(_loginObject.SessionToken)}"; var response = await JDownloaderApiHandler.CallServer <object>(query, _loginObject.ServerEncryptionToken); if (response == null) { return(false); } IsConnected = false; _loginObject = null; return(true); }
/// <summary> /// Tries to reconnect your client to the api. /// </summary> /// <returns>True if successfull else false</returns> public async Task <bool> Reconnect() { if (_loginObject is null) { return(false); } var query = $"/my/reconnect?appkey{HttpUtility.UrlEncode(Utils.AppKey)}&sessiontoken={HttpUtility.UrlEncode(_loginObject.SessionToken)}®aintoken={HttpUtility.UrlEncode(_loginObject.RegainToken)}"; var response = await JDownloaderApiHandler.CallServer <LoginObject>(query, _loginObject.ServerEncryptionToken); if (response == null) { return(false); } _loginObject = response; _loginObject.ServerEncryptionToken = Utils.UpdateEncryptionToken(_loginSecret, _loginObject.SessionToken); _loginObject.DeviceEncryptionToken = Utils.UpdateEncryptionToken(_deviceSecret, _loginObject.SessionToken); IsConnected = true; return(IsConnected); }