Permalink
Browse files

add support for leaving the identifier blank and defaulting to the ro…

…ot folder.
  • Loading branch information...
1 parent 390d346 commit bbbcc01975ffa9ee16608f6232fb79de80042d4d @AnalogJ AnalogJ committed Feb 28, 2014
View
@@ -172,6 +172,7 @@ module.exports = function (oauth_data, provider_options) {
})
}
this.GetFolderInformation = function (identifier) {
+ identifier = identifier || '0'
return getClient().then(function (client) {
var deferred = Q.defer();
client.get(
@@ -189,6 +190,7 @@ module.exports = function (oauth_data, provider_options) {
}
this.RetrieveFolderItems = function (identifier, options) {
+ identifier = identifier || '0'
return getClient().then(function (client) {
var deferred = Q.defer();
client.get(
View
@@ -14,7 +14,7 @@ exports.provider = function (provider_options) {
this.oAuthGetAuthorizeUrl = function oAuthGetAuthorizeUrl() {
return oauth2Client.getAuthorizeUrl({
- "redirect_uri": provider_options.redirect_url(provider_options.service_name),
+ "redirect_uri": provider_options.redirect_url,
"response_type": "code"
})
}
@@ -25,7 +25,7 @@ exports.provider = function (provider_options) {
code,
{
"grant_type": "authorization_code",
- "redirect_uri": provider_options.redirect_url(provider_options.service_name)
+ "redirect_uri": provider_options.redirect_url
},
function (err, access_token, refresh_token, results) {
var oauth_data = {'access_token': access_token, 'refresh_token': refresh_token, 'raw': results}
@@ -162,12 +162,17 @@ module.exports = function (oauth_data, provider_options) {
});
}
this.DeleteFolder = this.DeleteFile;
- this.GetFolderInformation = this.GetFileInformation;
+ this.GetFolderInformation = function(identifier, options){
+ identifier = identifier || '';
+ return this.GetFileInformation(identifier, options)
+ }
this.RetrieveFolderItems = function (identifier) {
+ identifier = identifier || '';
+ var path = createPath(identifier)
return getClient().then(function (client) {
var deferred = Q.defer();
- client.readdir(identifier, function (err, content_array, folder_stat, content_stat_array) {
+ client.readdir(path, function (err, content_array, folder_stat, content_stat_array) {
err = errorHandler(err);
if (err) return deferred.reject(err);
return deferred.resolve({content_array: content_array, folder_stat: folder_stat, content_stat_array: content_stat_array});
@@ -18,7 +18,7 @@ exports.provider = function (provider_options) {
this.oAuthGetAuthorizeUrl = function oAuthGetAuthorizeUrl() {
return oauth2Client.getAuthorizeUrl({
- "redirect_uri": provider_options.redirect_url(provider_options.service_name),
+ "redirect_uri": provider_options.redirect_url,
"response_type": "code"
})
}
@@ -29,7 +29,7 @@ exports.provider = function (provider_options) {
code,
{
"grant_type": "authorization_code",
- "redirect_uri": provider_options.redirect_url(provider_options.service_name)
+ "redirect_uri": provider_options.redirect_url
},
function (err, access_token, refresh_token, results) {
var oauth_data = {'access_token': access_token, 'refresh_token': refresh_token, 'raw': results}
@@ -5,7 +5,7 @@ var Q = require('q')
module.exports = function (oauth_data, provider_options) {
var _oauth_data = oauth_data;
- var _oauth2Client = new googleapis.OAuth2Client(provider_options.client_key, provider_options.client_secret, provider_options.redirect_url(provider_options.service_name));
+ var _oauth2Client = new googleapis.OAuth2Client(provider_options.client_key, provider_options.client_secret, provider_options.redirect_url);
_oauth2Client.credentials = _oauth_data;
var _googleClientPromise = null
@@ -101,6 +101,7 @@ module.exports = function (oauth_data, provider_options) {
})
}
this.GetFileInformation = function (identifier) {
+ identifier = identifier ||'root';
return getClient().then(function (client) {
var deferred = Q.defer();
client.drive.files
@@ -136,6 +137,7 @@ module.exports = function (oauth_data, provider_options) {
this.GetFolderInformation = this.GetFileInformation;
this.RetrieveFolderItems = function (identifier) {
+ identifier = identifier ||'root';
return getClient().then(function (client) {
var deferred = Q.defer();
client.drive.children
@@ -7,7 +7,7 @@ exports.provider = function (provider_options) {
//https://developers.google.com/apis-explorer/#p/drive/v2/
//https://github.com/google/google-api-nodejs-client/
var oauth2Client = new googleapis.OAuth2Client(provider_options.client_key,
- provider_options.client_secret, provider_options.redirect_url(provider_options.service_name));
+ provider_options.client_secret, provider_options.redirect_url);
this.oAuthGetAuthorizeUrl = function oAuthGetAuthorizeUrl() {
return oauth2Client.generateAuthUrl({ access_type: 'offline', scope: provider_options.client_scope });
}
View
@@ -33,11 +33,17 @@ exports.setConfig = function (new_config) {
config = extend(true, config, new_config);
};
-function redirect_url(service){
+var redirect_url_generator = function (service){
var service_name = service.toLowerCase();
return 'http://www.example.com:3000/service/callback/' + service_name
}
-exports.redirect_url = redirect_url;
+
+exports.getRedirectUrlGenerator = function(){
+ return redirect_url_generator
+}
+exports.setRedirectUrlGenerator = function(fn){
+ redirect_url_generator = fn;
+}
function generateProviderOptions(service,provider_options){
//provider_options.client_key
@@ -48,7 +54,7 @@ function generateProviderOptions(service,provider_options){
provider_options = provider_options || {};
provider_options = extend(true, config[service], provider_options);
provider_options.service_name = service;
- provider_options.redirect_url = provider_options.redirect_url || redirect_url;
+ provider_options.redirect_url = provider_options.redirect_url || redirect_url_generator(service);
return provider_options;
}
exports.generateProviderOptions = generateProviderOptions;
@@ -133,6 +133,7 @@ module.exports = function (oauth_data, provider_options) {
}
this.CreateFolder = function (folderName, parentIdentifier, options) {
+ parentIdentifier = parentIdentifier || 'me/skydrive/'
return getClient().then(function (client) {
var deferred = Q.defer();
client.post(
@@ -141,7 +142,7 @@ module.exports = function (oauth_data, provider_options) {
'Authorization': 'Bearer ' + _oauth_data.access_token,
'content-type': 'application/json'
},
- url: 'https://apis.live.net/v5.0/' + (parentIdentifier || 'me/skydrive/'),
+ url: 'https://apis.live.net/v5.0/' + parentIdentifier,
body: '{"name":"' + folderName + '", "description": "A test folder"}'
},
function (err, r, body) {
@@ -155,6 +156,7 @@ module.exports = function (oauth_data, provider_options) {
}
this.DeleteFolder = function (identifier) {
+ identifier = identifier || 'me/skydrive'
return getClient().then(function (client) {
var deferred = Q.defer();
client.del(
@@ -171,6 +173,7 @@ module.exports = function (oauth_data, provider_options) {
})
}
this.GetFolderInformation = function (identifier) {
+ identifier = identifier || 'me/skydrive'
return getClient().then(function (client) {
var deferred = Q.defer();
client.get(
@@ -187,6 +190,7 @@ module.exports = function (oauth_data, provider_options) {
})
}
this.RetrieveFolderItems = function (identifier, options) {
+ identifier = identifier || 'me/skydrive'
return getClient().then(function (client) {
var deferred = Q.defer();
client.get(
@@ -15,7 +15,7 @@ exports.provider = function (provider_options) {
this.oAuthGetAuthorizeUrl = function oAuthGetAuthorizeUrl() {
return oauth2Client.getAuthorizeUrl({
- "redirect_uri": provider_options.redirect_url(provider_options.service_name),
+ "redirect_uri": provider_options.redirect_url,
"response_type": "code",
"scope": provider_options.client_scope
@@ -29,7 +29,7 @@ exports.provider = function (provider_options) {
code,
{
"grant_type": "authorization_code",
- "redirect_uri": provider_options.redirect_url(provider_options.service_name)
+ "redirect_uri": provider_options.redirect_url
},
function (err, access_token, refresh_token, results) {
var oauth_data = {'access_token': access_token, 'refresh_token': refresh_token, 'raw': results}
@@ -43,6 +43,7 @@ describe('Box Client', function () {
it('should successfully Create file in root directory', function () {
return Client.CreateFile(testFileName, null, new Buffer(testFileContent)).then(function (response) {
+ console.log("create file:", response.body)
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.entries[0].type, "file");
assert.equal(resp_json.entries[0].name, testFileName);
@@ -52,6 +53,7 @@ describe('Box Client', function () {
it('should successfully Read file metadata', function () {
return Client.GetFileInformation(testFileID).then(function (response) {
+ console.log("file information:", response.body)
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.type, "file");
assert.equal(resp_json.name, testFileName);
@@ -66,6 +68,7 @@ describe('Box Client', function () {
it('should successfully Delete file', function () {
return Client.DeleteFile(testFileID).then(function (response) {
+ console.log("delete file:", response.body)
assert.equal(response.body, '');
//TODO: check the header for 204 response
})
@@ -84,8 +87,29 @@ describe('Box Client', function () {
})
})
+ describe('when no identifiers provided', function(){
+ it('should successfully get root folder information', function () {
+ return Client.GetFolderInformation().then(function (response) {
+ console.log(response.body)
+ var resp_json = JSON.parse(response.body);
+ assert.equal(resp_json.type, "folder");
+ })
+ })
+
+ it('should successfully Read root folder metadata', function () {
+ return Client.RetrieveFolderItems().then(function (response) {
+ console.log("retrieve folder items\n", response.body)
+
+ var resp_json = JSON.parse(response.body);
+ assert.equal(resp_json.total_count, 0);
+ assert.deepEqual(resp_json.entries, []);
+ })
+ })
+ })
+
it('should successfully Create folder in root directory', function () {
return Client.CreateFolder(testFolderName).then(function (response) {
+ console.log("create folder:\n", response.body)
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.type, "folder");
assert.equal(resp_json.name, testFolderName);
@@ -95,6 +119,7 @@ describe('Box Client', function () {
it('should successfully Read folder metadata', function () {
return Client.GetFolderInformation(testFolderID).then(function (response) {
+ console.log("get folder information:\n", response.body)
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.type, "folder");
assert.equal(resp_json.name, testFolderName);
@@ -103,6 +128,8 @@ describe('Box Client', function () {
it('should successfully Read folder contents', function () {
return Client.RetrieveFolderItems(testFolderID).then(function (response) {
+ console.log("retrieve folder items\n", response.body)
+
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.total_count, 0);
assert.deepEqual(resp_json.entries, []);
@@ -127,6 +154,8 @@ describe('Box Client', function () {
it('should access account info', function () {
return Client.AccountInfo().then(function (response) {
+ console.log("account info\n", response.body)
+
var resp_json = JSON.parse(response.body);
assert.equal(resp_json.type, "user");
assert(resp_json.name);
@@ -17,7 +17,7 @@ describe('Box Provider', function () {
it('should generate oauth authorize Url', function () {
var parsed = require('url').parse(Provider.oAuthGetAuthorizeUrl(), true);
assert.equal(parsed.hostname, "www.box.com")
- assert.equal(parsed.query.redirect_uri, FileFog.redirect_url('box'))
+ assert.equal(parsed.query.redirect_uri, FileFog.getRedirectUrlGenerator()('box'))
assert.equal(parsed.query.response_type, "code")
assert.equal(parsed.query.client_id, "")
})
@@ -0,0 +1,17 @@
+{
+ "type": "user",
+ "id": "210924315",
+ "name": "FileFog Test",
+ "login": "filefogtest@gmail.com",
+ "created_at": "2014-02-01T21:35:38-08:00",
+ "modified_at": "2014-02-27T16:12:40-08:00",
+ "language": "en",
+ "space_amount": 10737418240,
+ "space_used": 0,
+ "max_upload_size": 262144000,
+ "status": "active",
+ "job_title": "",
+ "phone": "14153732815",
+ "address": "",
+ "avatar_url": "https://app.box.com/api/avatar/large/210924315"
+}
@@ -0,0 +1,17 @@
+{
+ "type": "user",
+ "id": "210924315",
+ "name": "FileFog Test",
+ "login": "filefogtest@gmail.com",
+ "created_at": "2014-02-01T21:35:38-08:00",
+ "modified_at": "2014-02-27T16:12:40-08:00",
+ "language": "en",
+ "space_amount": 10737418240,
+ "space_used": 0,
+ "max_upload_size": 262144000,
+ "status": "active",
+ "job_title": "",
+ "phone": "14153732815",
+ "address": "",
+ "avatar_url": "https://app.box.com/api/avatar/large/210924315"
+}
@@ -0,0 +1,60 @@
+{
+ "total_count": 1,
+ "entries": [
+ {
+ "type": "file",
+ "id": "14805613466",
+ "sequence_id": "0",
+ "etag": "0",
+ "sha1": "ae5cd92fc059f41e745ee06174bff7504fa68b93",
+ "name": "d74e7107-d8b4-4407-5add-91e434c08f4b_test.txt",
+ "description": "",
+ "size": 20,
+ "path_collection": {
+ "total_count": 1,
+ "entries": [
+ {
+ "type": "folder",
+ "id": "0",
+ "sequence_id": null,
+ "etag": null,
+ "name": "All Files"
+ }
+ ]
+ },
+ "created_at": "2014-02-27T14:33:47-08:00",
+ "modified_at": "2014-02-27T14:33:47-08:00",
+ "trashed_at": null,
+ "purged_at": null,
+ "content_created_at": "2014-02-27T14:33:47-08:00",
+ "content_modified_at": "2014-02-27T14:33:47-08:00",
+ "created_by": {
+ "type": "user",
+ "id": "210924315",
+ "name": "FileFog Test",
+ "login": "filefogtest@gmail.com"
+ },
+ "modified_by": {
+ "type": "user",
+ "id": "210924315",
+ "name": "FileFog Test",
+ "login": "filefogtest@gmail.com"
+ },
+ "owned_by": {
+ "type": "user",
+ "id": "210924315",
+ "name": "FileFog Test",
+ "login": "filefogtest@gmail.com"
+ },
+ "shared_link": null,
+ "parent": {
+ "type": "folder",
+ "id": "0",
+ "sequence_id": null,
+ "etag": null,
+ "name": "All Files"
+ },
+ "item_status": "active"
+ }
+ ]
+}
Oops, something went wrong.

0 comments on commit bbbcc01

Please sign in to comment.