Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Bryan Kaperick
jio
Commits
0c4e62f2
Commit
0c4e62f2
authored
Jun 28, 2017
by
preetwinder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Facebook storage and tests for it
parent
a410f312
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
733 additions
and
1 deletion
+733
-1
Gruntfile.js
Gruntfile.js
+2
-1
src/jio.storage/fbstorage.js
src/jio.storage/fbstorage.js
+114
-0
test/jio.storage/fbstorage.tests.js
test/jio.storage/fbstorage.tests.js
+616
-0
test/tests.html
test/tests.html
+1
-0
No files found.
Gruntfile.js
View file @
0c4e62f2
...
...
@@ -180,7 +180,8 @@ module.exports = function (grunt) {
'
src/jio.storage/localstorage.js
'
,
'
src/jio.storage/indexeddbstorage.js
'
,
'
src/jio.storage/cryptstorage.js
'
,
'
src/jio.storage/websqlstorage.js
'
'
src/jio.storage/websqlstorage.js
'
,
'
src/jio.storage/fbstorage.js
'
],
dest
:
'
dist/<%= pkg.name %>-<%= pkg.version %>.js
'
// dest: 'jio.js'
...
...
src/jio.storage/fbstorage.js
0 → 100644
View file @
0c4e62f2
/*jslint nomen: true */
/*global RSVP, UriTemplate*/
(
function
(
jIO
,
RSVP
,
UriTemplate
)
{
"
use strict
"
;
var
GET_POST_URL
=
"
https://graph.facebook.com/v2.9/{+post_id}
"
+
"
?fields={+fields}&access_token={+access_token}
"
,
get_post_template
=
UriTemplate
.
parse
(
GET_POST_URL
),
GET_FEED_URL
=
"
https://graph.facebook.com/v2.9/{+user_id}/feed
"
+
"
?fields={+fields}&limit={+limit}&since={+since}&access_token=
"
+
"
{+access_token}
"
,
get_feed_template
=
UriTemplate
.
parse
(
GET_FEED_URL
);
function
FBStorage
(
spec
)
{
if
(
typeof
spec
.
access_token
!==
'
string
'
||
!
spec
.
access_token
)
{
throw
new
TypeError
(
"
Access Token must be a string
"
+
"
which contains more than one character.
"
);
}
if
(
typeof
spec
.
user_id
!==
'
string
'
||
!
spec
.
user_id
)
{
throw
new
TypeError
(
"
User ID must be a string
"
+
"
which contains more than one character.
"
);
}
this
.
_access_token
=
spec
.
access_token
;
this
.
_user_id
=
spec
.
user_id
;
this
.
_default_field_list
=
spec
.
default_field_list
||
[];
this
.
_default_limit
=
spec
.
default_limit
||
500
;
}
FBStorage
.
prototype
.
get
=
function
(
id
)
{
var
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
get_post_template
.
expand
({
post_id
:
id
,
fields
:
that
.
_default_field_list
,
access_token
:
that
.
_access_token
})
});
})
.
push
(
function
(
result
)
{
return
JSON
.
parse
(
result
.
target
.
responseText
);
});
};
function
paginateResult
(
url
,
result
,
select_list
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
url
});
})
.
push
(
function
(
response
)
{
return
JSON
.
parse
(
response
.
target
.
responseText
);
},
function
(
err
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Getting feed failed
"
+
err
.
toString
(),
err
.
target
.
status
);
})
.
push
(
function
(
response
)
{
if
(
response
.
data
.
length
===
0
)
{
return
result
;
}
var
i
,
j
,
obj
=
{};
for
(
i
=
0
;
i
<
response
.
data
.
length
;
i
+=
1
)
{
obj
.
id
=
response
.
data
[
i
].
id
;
obj
.
value
=
{};
for
(
j
=
0
;
j
<
select_list
.
length
;
j
+=
1
)
{
obj
.
value
[
select_list
[
j
]]
=
response
.
data
[
i
][
select_list
[
j
]];
}
result
.
push
(
obj
);
obj
=
{};
}
return
paginateResult
(
response
.
paging
.
next
,
result
,
select_list
);
});
}
FBStorage
.
prototype
.
buildQuery
=
function
(
query
)
{
var
that
=
this
,
fields
=
[],
limit
=
this
.
_default_limit
,
template_argument
=
{
user_id
:
this
.
_user_id
,
limit
:
limit
,
access_token
:
this
.
_access_token
};
if
(
query
.
include_docs
)
{
fields
=
fields
.
concat
(
that
.
_default_field_list
);
}
if
(
query
.
select_list
)
{
fields
=
fields
.
concat
(
query
.
select_list
);
}
if
(
query
.
limit
)
{
limit
=
query
.
limit
[
1
];
}
template_argument
.
fields
=
fields
;
template_argument
.
limit
=
limit
;
return
paginateResult
(
get_feed_template
.
expand
(
template_argument
),
[],
fields
)
.
push
(
function
(
result
)
{
if
(
!
query
.
limit
)
{
return
result
;
}
return
result
.
slice
(
query
.
limit
[
0
],
query
.
limit
[
1
]);
});
};
FBStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
this_storage_capacity_list
=
[
"
list
"
,
"
select
"
,
"
include
"
,
"
limit
"
];
if
(
this_storage_capacity_list
.
indexOf
(
name
)
!==
-
1
)
{
return
true
;
}
};
jIO
.
addStorage
(
'
facebook
'
,
FBStorage
);
}(
jIO
,
RSVP
,
UriTemplate
));
\ No newline at end of file
test/jio.storage/fbstorage.tests.js
0 → 100644
View file @
0c4e62f2
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
0c4e62f2
...
...
@@ -53,6 +53,7 @@
<script
src=
"jio.storage/zipstorage.tests.js"
></script>
<script
src=
"jio.storage/gdrivestorage.tests.js"
></script>
<script
src=
"jio.storage/websqlstorage.tests.js"
></script>
<script
src=
"jio.storage/fbstorage.tests.js"
></script>
<!--script src="../lib/jquery/jquery.min.js"></script>
<script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script-->
...
...
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