Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Bechu
jio
Commits
9d15334f
Commit
9d15334f
authored
Sep 23, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dropbox: use URITemplate to build URL
parent
77a8fbc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
37 deletions
+92
-37
src/jio.storage/dropboxstorage.js
src/jio.storage/dropboxstorage.js
+18
-9
test/jio.storage/dropboxstorage.tests.js
test/jio.storage/dropboxstorage.tests.js
+74
-28
No files found.
src/jio.storage/dropboxstorage.js
View file @
9d15334f
...
...
@@ -23,8 +23,11 @@
remote_template
=
UriTemplate
.
parse
(
REMOVE_URL
),
GET_URL
=
"
https://content.dropboxapi.com/1/files
"
+
"
{/root,id}{+name}{?access_token}
"
,
get_template
=
UriTemplate
.
parse
(
GET_URL
)
;
get_template
=
UriTemplate
.
parse
(
GET_URL
)
,
//LIST_URL = 'https://api.dropboxapi.com/1/metadata/sandbox/';
METADATA_URL
=
"
https://api.dropboxapi.com/1/metadata
"
+
"
{/root}{+id}{?access_token}
"
,
metadata_template
=
UriTemplate
.
parse
(
METADATA_URL
);
function
restrictDocumentId
(
id
)
{
if
(
id
.
indexOf
(
"
/
"
)
!==
0
)
{
...
...
@@ -86,6 +89,7 @@
.
push
(
undefined
,
function
(
err
)
{
if
((
err
.
target
!==
undefined
)
&&
(
err
.
target
.
status
===
405
))
{
// Directory already exists, no need to fail
return
;
}
throw
err
;
...
...
@@ -115,10 +119,12 @@
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
url
"
:
"
https://api.dropboxapi.com/1/metadata/
"
+
that
.
_root
+
"
/
"
+
id
+
'
?access_token=
'
+
that
.
_access_token
type
:
"
GET
"
,
url
:
metadata_template
.
expand
({
access_token
:
that
.
_access_token
,
root
:
that
.
_root
,
id
:
id
})
});
})
.
push
(
function
(
evt
)
{
...
...
@@ -144,10 +150,12 @@
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
url
"
:
"
https://api.dropboxapi.com/1/metadata/
"
+
that
.
_root
+
"
/
"
+
id
+
'
?access_token=
'
+
that
.
_access_token
type
:
"
GET
"
,
url
:
metadata_template
.
expand
({
access_token
:
that
.
_access_token
,
root
:
that
.
_root
,
id
:
id
})
});
})
.
push
(
function
(
evt
)
{
...
...
@@ -250,6 +258,7 @@
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find attachment:
"
+
id
+
"
,
"
+
name
,
404
);
}
throw
error
;
});
};
...
...
test/jio.storage/dropboxstorage.tests.js
View file @
9d15334f
...
...
@@ -10,6 +10,7 @@
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
,
throws
=
QUnit
.
throws
,
token
=
"
sample_token
"
;
/////////////////////////////////////////////////////////////////
...
...
@@ -21,10 +22,30 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
dropbox
"
,
access_token
:
token
,
root
:
"
drop
box
"
root
:
"
sand
box
"
});
equal
(
jio
.
__type
,
"
dropbox
"
);
deepEqual
(
jio
.
__storage
.
_access_token
,
token
);
deepEqual
(
jio
.
__storage
.
_root
,
"
sandbox
"
);
});
test
(
"
reject invalid root
"
,
function
()
{
throws
(
function
()
{
jIO
.
createJIO
({
type
:
"
dropbox
"
,
access_token
:
token
,
root
:
"
foobar
"
});
},
function
(
error
)
{
ok
(
error
instanceof
TypeError
);
equal
(
error
.
message
,
"
root must be 'dropbox' or 'sandbox'
"
);
return
true
;
}
);
});
/////////////////////////////////////////////////////////////////
...
...
@@ -301,11 +322,6 @@
});
test
(
"
get inexistent document
"
,
function
()
{
var
url_get
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
//inexistent/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url_get
,
[
404
,
{
"
Content-Type
"
:
"
text/xml
"
},
''
]);
stop
();
expect
(
3
);
...
...
@@ -323,9 +339,9 @@
});
});
test
(
"
get d
ocument
"
,
function
()
{
test
(
"
get d
irectory
"
,
function
()
{
var
url
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
/
/
id1/?access_token=
"
+
token
;
"
/id1/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
{"is_dir": true, "contents": []}
'
...
...
@@ -345,6 +361,30 @@
});
});
test
(
"
get file
"
,
function
()
{
var
url
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
/id1/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
{"is_dir": false, "contents": []}
'
]);
stop
();
expect
(
3
);
this
.
jio
.
get
(
"
/id1/
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Not a directory: /id1/
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// DropboxStorage.allAttachments
/////////////////////////////////////////////////////////////////
...
...
@@ -403,12 +443,31 @@
});
});
test
(
"
get inexistent document
"
,
function
()
{
var
url
=
"
/inexistent/
"
;
this
.
server
.
respondWith
(
"
PROPFIND
"
,
url
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
"
foo
"
]);
test
(
"
get file
"
,
function
()
{
var
url
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
/id1/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
{"is_dir": false, "contents": []}
'
]);
stop
();
expect
(
3
);
this
.
jio
.
allAttachments
(
"
/id1/
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Not a directory: /id1/
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get inexistent document
"
,
function
()
{
stop
();
expect
(
3
);
...
...
@@ -428,7 +487,7 @@
test
(
"
get document without attachment
"
,
function
()
{
var
url
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
/
/
id1/?access_token=
"
+
token
;
"
/id1/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
{"is_dir": true, "contents": []}
'
...
...
@@ -450,7 +509,7 @@
test
(
"
get document with attachment
"
,
function
()
{
var
url
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
/
/
id1/?access_token=
"
+
token
;
"
/id1/?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
{"is_dir": true, "path": "/id1",
'
+
...
...
@@ -737,13 +796,6 @@
});
test
(
"
remove inexistent attachment
"
,
function
()
{
var
url_get_id
=
"
https://api.dropboxapi.com/1/metadata/dropbox
"
+
"
//removeAttachment1/attachment1?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url_get_id
,
[
404
,
{
"
Content-Type
"
:
"
text/xml
"
},
''
]);
stop
();
expect
(
3
);
...
...
@@ -890,12 +942,6 @@
});
test
(
"
get inexistent attachment
"
,
function
()
{
var
url
=
"
https://content.dropboxapi.com/1/files/dropbox//
"
+
"
getAttachment1/attachment1?access_token=
"
+
token
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
404
,
{
"
Content-Type
"
:
"
text/xml
"
},
""
]);
stop
();
expect
(
3
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment