Permalink
Browse files

added tranform for each service.

  • Loading branch information...
1 parent 2dfe441 commit 306b57398fef130ac6d4489b9dfd1992428b40fb @AnalogJ AnalogJ committed Mar 1, 2014
@@ -49,24 +49,6 @@ function parseDeletion(deletion_response){
exports.parseDeletion = parseDeletion;
function parseFolderItems(items_response){
-
- /*
- "total_count": 0,
- "entries": [],
- "offset": 0,
- "limit": 100,
- "order": [
- {
- "by": "type",
- "direction": "ASC"
- },
- {
- "by": "name",
- "direction": "ASC"
- }
- ]
- * */
-
var transform = {};
transform.total_items = null;
transform.content = items_response.content_stat_array.map(function(current_item){
@@ -28,7 +28,7 @@ module.exports = function (oauth_data, provider_options) {
return deferred.promise;
}
- this.CheckQuota = function (options) {
+ this.AccountInfo = function (options) {
options = options || {}
options.includeSubscribed = options.includeSubscribed || true;
return getClient().then(function (client) {
@@ -43,16 +43,20 @@ module.exports = function (oauth_data, provider_options) {
})
}
-// this.CheckQuota = function (options) {
-// return getClient().then(function (client) {
-// var deferred = Q.defer();
-// client.getAccountInfo(options || {}, function (err, stat) {
-// if (err) return deferred.reject(err);
-// return deferred.resolve(stat);
-// });
-// return deferred.promise;
-// })
-// }
+ this.CheckQuota = function (options) {
+ options = options || {}
+ options.includeSubscribed = options.includeSubscribed || true;
+ return getClient().then(function (client) {
+ var deferred = Q.defer();
+ client.drive.about
+ .get(options)
+ .withAuthClient(_oauth2Client).execute(function (err, result) {
+ if (err) return deferred.reject(err);
+ return deferred.resolve(result);
+ });
+ return deferred.promise;
+ })
+ }
this.CreateFile = function (fileName, parentIdentifier, content_buffer, options) {
@@ -0,0 +1,87 @@
+function parseFileInformation(file_response){
+ var transform = {};
+ transform.is_file = (file_response.mimeType != "application/vnd.google-apps.folder");
+ transform.is_folder = (file_response.mimeType == "application/vnd.google-apps.folder");
+ transform.etag = file_response.etag;
+ transform.identifier = file_response.id;
+ transform.parent_identifier = file_response.parents[0].id;
+ transform.mimetype = file_response.mimeType
+ transform.created_date = new Date(file_response.createdDate);
+ transform.modified_date = new Date(file_response.modifiedDate);
+ transform.name = file_response.title;
+ transform.description = '';
+ //transform.extension = file_response.name.split('.')
+ transform.checksum = file_response.md5Checksum;
+ transform.file_size = file_response.fileSize;
+ transform._raw = file_response;
+ return transform;
+}
+exports.parseFileInformation = parseFileInformation;
+
+function parseFolderInformation(folder_response){
+ var transform = {};
+ transform.is_file = (folder_response.mimeType != "application/vnd.google-apps.folder");
+ transform.is_folder = (folder_response.mimeType == "application/vnd.google-apps.folder");
+ transform.etag = folder_response.etag;
+ transform.identifier = folder_response.id;
+ transform.parent_identifier = folder_response.parents[0].id;
+ transform.created_date = new Date(folder_response.createdDate);
+ transform.modified_date = new Date(folder_response.modifiedDate);
+ transform.name = folder_response.title;
+ transform.description = '';
+ transform._raw = folder_response;
+ return transform;
+}
+exports.parseFolderInformation = parseFolderInformation;
+
+function parseDeletion(deletion_response){
+ var transform = {}
+ transform.success = true;
+ transform._raw = '';
+ return transform;
+}
+exports.parseDeletion = parseDeletion;
+
+function parseFolderItems(items_response){
+ var transform = {};
+ transform.total_items = null;
+ transform.content = items_response.items.map(function(current_item){
+ if(current_item.mimeType != "application/vnd.google-apps.folder"){
+ return parseFileInformation(current_item);
+ }
+ else{
+ return parseFolderInformation(current_item);
+ }
+ });
+ return transform;
+}
+
+exports.parseFolderItems = parseFolderItems;
+
+
+function parseAccountInfo(account_response){
+
+ var transform = {};
+ transform.name = account_response.user.displayName;
+ transform.email = '';
+ transform.avatar_url = '';
+ transform.created_date = null;
+ transform.modified_date = null;
+ transform.id = account_response.permissionId;
+ transform._raw = account_response;
+ return transform;
+}
+exports.parseAccountInfo = parseAccountInfo;
+
+function parseQuota(quota_response){
+ var transform = {};
+ transform.total_bytes = quota_response.quotaBytesTotal; //total space allocated in bytes
+ transform.used_bytes = quota_response.quotaBytesUsed; //bytes used.
+ transform.limits= {
+ upload_size : '10737418240'
+ }
+ transform._raw = quota_response;
+ return transform;
+}
+exports.parseQuota = parseQuota;
+
@@ -59,6 +59,22 @@ module.exports = function (oauth_data, provider_options) {
})
}
+ this.CheckQuota = function (options) {
+ options = options || {}
+ return getClient().then(function (client) {
+ var deferred = Q.defer();
+ client.get({
+ url: 'https://apis.live.net/v5.0/me/skydrive/quota'
+ },
+ function (err, r, body) {
+ if (err) return deferred.reject(err);
+ return deferred.resolve({ "response": r, "body": body});
+ });
+
+ return deferred.promise;
+ })
+ }
+
this.CreateFile = function (fileName, parentIdentifier, content_buffer, options) {
options = options || {}
@@ -67,7 +83,7 @@ module.exports = function (oauth_data, provider_options) {
}
parentIdentifier = parentIdentifier || 'me/skydrive'
return getClient().then(function (client) {
- console.log("successfully got client", fileName, parentIdentifier, content_buffer);
+// console.log("successfully got client", fileName, parentIdentifier, content_buffer);
var deferred = Q.defer();
client.put({
url: 'https://apis.live.net/v5.0/' + parentIdentifier + '/files/'+ fileName,
@@ -81,12 +97,10 @@ module.exports = function (oauth_data, provider_options) {
// ]
},
function (err, r, body) {
- console.log(err, r.statusCode, body);
err = errorHandler(r, body, err);
if (err) return deferred.reject(err);
return deferred.resolve({ "response": r, "body": body});
});
- console.log("GENEREATED POST")
return deferred.promise;
})
}
@@ -228,7 +242,6 @@ module.exports = function (oauth_data, provider_options) {
url: 'https://apis.live.net/v5.0/' + identifier + '/files'
},
function (err, r, body) {
- console.log(err, r.statusCode, body);
err = errorHandler(r, body, err);
if (err) return deferred.reject(err);
return deferred.resolve({ "response": r, "body": body});
@@ -0,0 +1,86 @@
+function parseFileInformation(file_response){
+ var transform = {};
+ transform.is_file = (file_response.type != "folder");
+ transform.is_folder = (file_response.type == "folder");
+ transform.etag = '';
+ transform.identifier = file_response.id;
+ transform.parent_identifier = file_response.parent_id;
+ transform.mimetype = ''
+ transform.created_date = new Date(file_response.created_time);
+ transform.modified_date = new Date(file_response.updated_time);
+ transform.name = file_response.name;
+ transform.description = file_response.description;
+ //transform.extension = file_response.name.split('.')
+ transform.checksum = null;
+ transform.file_size = file_response.size;
+ transform._raw = file_response;
+ return transform;
+}
+exports.parseFileInformation = parseFileInformation;
+
+function parseFolderInformation(folder_response){
+ var transform = {};
+ transform.is_file = (folder_response.type != "folder");
+ transform.is_folder = (folder_response.type == "folder");
+ transform.etag = '';
+ transform.identifier = folder_response.id;
+ transform.parent_identifier = folder_response.parent_id;
+ transform.created_date = new Date(folder_response.created_time);
+ transform.modified_date = new Date(folder_response.updated_time);
+ transform.name = folder_response.name;
+ transform.description = folder_response.description;
+ transform._raw = folder_response;
+ return transform;
+}
+exports.parseFolderInformation = parseFolderInformation;
+
+function parseDeletion(deletion_response){
+ var transform = {}
+ transform.success = true;
+ transform._raw = '';
+ return transform;
+}
+exports.parseDeletion = parseDeletion;
+
+function parseFolderItems(items_response){
+ var transform = {};
+ transform.total_items = null;
+ transform.content = items_response.data.map(function(current_item){
+ if(current_item.type != "folder"){
+ return parseFileInformation(current_item);
+ }
+ else{
+ return parseFolderInformation(current_item);
+ }
+ });
+ return transform;
+}
+
+exports.parseFolderItems = parseFolderItems;
+
+
+function parseAccountInfo(account_response){
+
+ var transform = {};
+ transform.name = account_response.name;
+ transform.email = account_response.emails.preferred;
+ transform.avatar_url = '';
+ transform.created_date = new Date(account_response.updated_time);
+ transform.modified_date = new Date(account_response.updated_time);
+ transform.id = account_response.id;
+ transform._raw = account_response;
+ return transform;
+}
+exports.parseAccountInfo = parseAccountInfo;
+
+function parseQuota(quota_response){
+ var transform = {};
+ transform.total_bytes = quota_response.quota; //total space allocated in bytes
+ transform.used_bytes = quota_response.quota - quota_response.available; //bytes used.
+ transform.limits= {
+ }
+ transform._raw = quota_response;
+ return transform;
+}
+exports.parseQuota = parseQuota;
+
Oops, something went wrong.

0 comments on commit 306b573

Please sign in to comment.