Skip to content

Commit 3113f6c

Browse files
committed
Add initial box.com
1 parent 602b2bb commit 3113f6c

File tree

7 files changed

+150
-5
lines changed

7 files changed

+150
-5
lines changed

demos/box.html

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!DOCTYPE html>
2+
<link rel="stylesheet" href="/adorn/adorn.css"/>
3+
<script src="/adorn/adorn.js" async></script>
4+
<script src="client_ids.js"></script>
5+
<style>
6+
.alert {
7+
display: block;
8+
padding: 15px;
9+
margin-bottom: 20px;
10+
border: 1px solid rgba(0, 0, 0, 0);
11+
border-radius: 4px;
12+
}
13+
.alert-warning{
14+
color: #8A6D3B;
15+
background-color: #FCF8E3;
16+
border-color: #FAEBCC;
17+
}
18+
.alert.alert-warning:before {
19+
content: "Warning: ";
20+
font-weight: bold;
21+
}
22+
</style>
23+
24+
25+
<title>hello( box )</title>
26+
<h1>hello( box )</h1>
27+
28+
29+
<blockquote>
30+
Box.com only provides authentication from apps which are using HTTPS. <a href="https://developers.box.com/docs/#api-basics">See Box.com API documentation</a>
31+
</blockquote>
32+
33+
<script>
34+
if(document.location.href.indexOf('https://')!==0){
35+
document.body.appendChild((function(){
36+
var div = document.createElement('div');
37+
div.className = "alert alert-warning";
38+
div.appendChild((function(){
39+
var a = document.createElement('a');
40+
a.href = document.location.href.replace('http://', 'https://');
41+
a.innerHTML = "Launch page with secure protocol - https://";
42+
return a;
43+
})());
44+
return div;
45+
})());
46+
}
47+
</script>
48+
49+
<button onclick="login();" id="profile">Login Box</button>
50+
51+
<script src="../src/hello.js" class="pre"></script>
52+
<script src="../src/modules/box.js" class="pre"></script>
53+
54+
<script class="pre">
55+
56+
var profile = document.getElementById( 'profile' );
57+
58+
function login(){
59+
60+
var box = hello('box');
61+
62+
box
63+
.login()
64+
.then(function(){
65+
return box.api('me')
66+
})
67+
.then(function(r){
68+
69+
profile.innerHTML = "<img src='"+ r.thumbnail + "' width=24/>Connected to Box.com as " + r.name;
70+
71+
}, console.error.bind(console) );
72+
73+
}
74+
</script>
75+
76+
<p>Initiate box client</p>
77+
78+
<script>
79+
var BOX_CLIENT_ID = {
80+
'local.knarly.com' : 'rdyb5se2fcuioryle3qdw2wcrps959x4',
81+
'adodson.com' : '264d13a33ba845f396a152cc326e6f5d'
82+
}[window.location.hostname];
83+
</script>
84+
85+
<script class="pre">
86+
hello.init({
87+
box : BOX_CLIENT_ID
88+
},{
89+
redirect_uri:'../redirect.html',
90+
response_type:'code'
91+
});
92+
</script>

demos/client_ids.js

-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ var INSTAGRAM_CLIENT_ID = {
7272
'adodson.com' : location_https ? 'e47d210f864c4b1ca94225ddab97205a' : '264d13a33ba845f396a152cc326e6f5d'
7373
}[window.location.hostname];
7474

75-
var BOX_CLIENT_ID = {
76-
'local.knarly.com' : 'rdyb5se2fcuioryle3qdw2wcrps959x4',
77-
'adodson.com' : '264d13a33ba845f396a152cc326e6f5d'
78-
}[window.location.hostname];
7975

8076
var FLICKR_CLIENT_ID = {
8177
'local.knarly.com' : '46dfea40b0f9d3765bc598966b5955d3',

src/hello.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ hello.utils.extend( hello.utils, {
24072407
path = utils.qs( p.oauth_proxy, {
24082408
path : path,
24092409
access_token : sign||'', // This will prompt the request to be signed as though it is OAuth1
2410-
then : (p.method.toLowerCase() === 'get' ? 'redirect' : 'proxy'),
2410+
then : p.proxy_response_type || (p.method.toLowerCase() === 'get' ? 'redirect' : 'proxy'),
24112411
method : p.method.toLowerCase(),
24122412
suppress_response_codes : true
24132413
});

src/modules/box.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// GitHub
3+
//
4+
hello.init({
5+
box : {
6+
name : 'Box',
7+
oauth : {
8+
version : 2,
9+
auth : 'https://app.box.com/api/oauth2/authorize',
10+
grant : 'https://api.box.com/oauth2/token',
11+
response_type : 'code'
12+
},
13+
base : 'https://api.box.com/2.0/',
14+
get : {
15+
'me' : 'users/me',
16+
'me/files' : 'files'
17+
},
18+
scope : {
19+
basic : ''
20+
},
21+
wrap : {
22+
me : function(o){
23+
if(o.id){
24+
o.picture = o.thumbnail = o.avatar_url;
25+
if(o.login.match('@')){
26+
o.email = o.login;
27+
}
28+
}
29+
return o;
30+
},
31+
"me/files" : function(o){
32+
if(Object.prototype.toString.call(o) === '[object Array]'){
33+
return {data:o};
34+
}
35+
return o;
36+
}
37+
},
38+
xhr : function(p){
39+
40+
p.proxy = true;
41+
p.proxy_response_type = 'proxy';
42+
return true;
43+
},
44+
jsonp : false
45+
}
46+
});

tests/specs/e2e/modules.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define([
22
'../libs/error_response',
3+
'../../../src/modules/box',
34
'../../../src/modules/facebook',
45
'../../../src/modules/flickr',
56
'../../../src/modules/google',

tests/specs/stubs/box/get/me.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type":"user","id":"197571718","name":"Jane McGee","login":"[email protected]","created_at":"2013-05-30T05:39:30-07:00","modified_at":"2015-01-14T16:40:48-08:00","language":"en","timezone":"America\/Los_Angeles","space_amount":5368709120,"space_used":16446,"max_upload_size":2147483648,"status":"active","job_title":"","phone":"","address":"","avatar_url":"https:\/\/app.box.com\/api\/avatar\/large\/197571718"}

tests/specs/unit/modules/apiMe.js

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ define(['./helper'], function (helper) {
1616
message: "OAuth error: unauthorized"
1717
}
1818
},
19+
{
20+
network: "box",
21+
expect: {
22+
id: '197571718',
23+
name: "Jane McGee",
24+
thumbnail: "https://app.box.com/api/avatar/large/197571718"
25+
},
26+
errorExpect: false
27+
},
1928
{
2029
network: "dropbox",
2130
expect: {

0 commit comments

Comments
 (0)