forked from chinchan54/ps3-cloud-drive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b567725
commit 9d7e975
Showing
15 changed files
with
366 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <sys/systime.h> //sysUsleep | ||
#include "ApiInterface.h" | ||
#include "log.h" | ||
|
||
bool APIInterface::ShouldRetryCheck( long response ) | ||
{ | ||
// HTTP 500 and 503 should be temperory. just wait a bit and retry | ||
if ( response == 500 || response == 503 ) | ||
{ | ||
debugPrintf("Request failed due to temporary error: %d, retrying in 5 seconds\n",response); | ||
|
||
sysUsleep(5); | ||
return true ; | ||
} | ||
|
||
// HTTP 401 Unauthorized. the auth token has been expired. refresh it | ||
else if ( response == 401 ) | ||
{ | ||
debugPrintf("Request failed due to Auth token expired: %d. refreshing token\n",response); | ||
|
||
m_auth_token->Refresh() ; | ||
return true ; | ||
} | ||
else | ||
{ | ||
debugPrintf("OAuth2 session ok, continue... %d\n",response); | ||
return false ; | ||
} | ||
} | ||
|
||
//TODO access m_prog_func_last_progress from *clientp | ||
/*int APIInterface::transferProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) | ||
{ | ||
if(dltotal > 0.0) | ||
{ | ||
double curProg = (dlnow / dltotal) * 100; | ||
if(curProg - m_prog_func_last_progress > 1) | ||
{ | ||
msgDialogProgressBarInc(MSG_PROGRESSBAR_INDEX1, curProg - m_prog_func_last_progress); | ||
debugPrintf("DOWN: %f of %f P: %f C: %f\r\n", dlnow, dltotal, m_prog_func_last_progress, curProg); | ||
m_prog_func_last_progress = curProg; | ||
} | ||
} | ||
if(ultotal > 0.0) | ||
{ | ||
double curProg = (ulnow / ultotal) * 100; | ||
if(curProg - m_prog_func_last_progress > 1) | ||
{ | ||
msgDialogProgressBarInc(MSG_PROGRESSBAR_INDEX1, curProg - m_prog_func_last_progress); | ||
debugPrintf("UP: %f of %f P: %f C: %f\r\n", ulnow, ultotal, m_prog_func_last_progress,curProg); | ||
m_prog_func_last_progress = curProg; | ||
} | ||
} | ||
return 0; | ||
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <sysutil/msg.h> //msgDialogProgress... | ||
|
||
#include "Json.h" | ||
#include "Download.h" | ||
#include "Header.h" | ||
|
||
#include "CurlAgent.h" | ||
#include "OAuth2.h" | ||
|
||
class APIInterface { | ||
public: | ||
double m_prog_func_last_progress; | ||
|
||
const std::string *m_api_key_map; | ||
const std::string m_client_id; | ||
const std::string m_client_secret; | ||
const std::string m_token_url; | ||
const std::string m_device_url; | ||
OAuth2* m_auth_token; | ||
CurlAgent http; | ||
|
||
Json m_remote_resource_root; | ||
|
||
APIInterface( | ||
std::string _client_id, | ||
std::string _client_secret, | ||
std::string _token_url, | ||
std::string _device_url | ||
): | ||
|
||
m_client_id(_client_id), | ||
m_client_secret(_client_secret), | ||
m_token_url(_token_url), | ||
m_device_url(_device_url) | ||
{} | ||
|
||
void init(){ | ||
m_auth_token = new OAuth2(m_token_url, m_device_url, m_client_id, m_client_secret, m_api_key_map); | ||
} | ||
|
||
bool ShouldRetryCheck( long response ); | ||
//TODO *clientp - possible to pass api or just pointer to double status; @see https://github.com/curl/curl/issues/806 | ||
//int transferProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); | ||
|
||
//api specific methods | ||
virtual Json checkIfRemoteResourceExists(std::string resourceTitle,std::string mimeType,std::string parentId) = 0; | ||
virtual Json::Array getResourcesUnderFolder(std::string parentId) = 0; | ||
virtual bool downloadFile(std::string localPath, std::string fileId) = 0; | ||
virtual void downloadChanges(int *dialog_action) = 0; | ||
virtual Json uploadFile(std::string path, std::string filename, std::string mimeType, std::string parentId, std::string fileId = "") = 0; | ||
virtual Json uploadDirectory(std::string dirName, std::string parentId) = 0; | ||
}; |
Oops, something went wrong.