diff options
Diffstat (limited to 'backends/cloud')
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 20 | ||||
-rw-r--r-- | backends/cloud/storageinfo.h | 16 |
2 files changed, 26 insertions, 10 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index d32d86567a..5a881211e3 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -101,10 +101,17 @@ void DropboxStorage::infoInnerCallback(StorageInfoCallback outerCallback, void * return; } - if (outerCallback) { - //TODO: check that JSON doesn't contain some error message instead of an actual response - //TODO: use JSON fields to construct StorageInfo - (*outerCallback)(StorageInfo(json->stringify())); + if (outerCallback) { + //Dropbox documentation states there is no errors for this API method + Common::JSONObject info = json->asObject(); + Common::String uid = Common::String::format("%d", info.getVal("uid")->asNumber()); + Common::String name = info.getVal("display_name")->asString(); + Common::String email = info.getVal("email")->asString(); + Common::JSONObject quota = info.getVal("quota_info")->asObject(); + uint32 quotaNormal = quota.getVal("normal")->asNumber(); + uint32 quotaShared = quota.getVal("shared")->asNumber(); + uint32 quotaAllocated = quota.getVal("quota")->asNumber(); + (*outerCallback)(StorageInfo(uid, name, email, quotaNormal+quotaShared, quotaAllocated)); delete outerCallback; } @@ -112,7 +119,10 @@ void DropboxStorage::infoInnerCallback(StorageInfoCallback outerCallback, void * } void DropboxStorage::infoMethodCallback(StorageInfo storageInfo) { - debug("info: %s", storageInfo.info().c_str()); + debug("\nStorage info:"); + debug("User name: %s", storageInfo.name().c_str()); + debug("Email: %s", storageInfo.email().c_str()); + debug("Disk usage: %u/%u", storageInfo.used(), storageInfo.available()); } DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) { diff --git a/backends/cloud/storageinfo.h b/backends/cloud/storageinfo.h index 510acb3778..f09563570f 100644 --- a/backends/cloud/storageinfo.h +++ b/backends/cloud/storageinfo.h @@ -32,14 +32,20 @@ namespace Cloud { * It's disk quota usage, owner name, and such. */ -class StorageInfo { - /** Temporary StorageInfo just contains raw JSON, received from cloud storage. */ - Common::String _info; +class StorageInfo { + Common::String _uid, _name, _email; + uint32 _usedBytes, _allocatedBytes; public: - StorageInfo(Common::String info): _info(info) {} + StorageInfo(Common::String uid, Common::String name, Common::String email, uint32 used, uint32 allocated): + _uid(uid), _name(name), _email(email), _usedBytes(used), _allocatedBytes(allocated) {} + + Common::String uid() const { return _uid; } + Common::String name() const { return _name; } + Common::String email() const { return _email; } + uint32 used() const { return _usedBytes; } + uint32 available() const { return _allocatedBytes; } - Common::String info() const { return _info; } }; } //end of namespace Cloud |