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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
jio
Commits
72f69b24
Commit
72f69b24
authored
Sep 29, 2017
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip youtube storage
parent
18cf665b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
src/jio.storage/youtubestorage.js
src/jio.storage/youtubestorage.js
+87
-0
No files found.
src/jio.storage/youtubestorage.js
0 → 100644
View file @
72f69b24
/**
* Youtube (Data) Storage. Type = "youtube".
*/
/*global jIO, RSVP, UriTemplate, JSON*/
/*jslint nomen: true*/
(
function
(
jIO
,
RSVP
,
UriTemplate
,
JSON
)
{
"
use strict
"
;
var
GET_URL
=
"
https://www.googleapis.com/youtube/v3/videos?
"
+
"
part=snippet,statistics,contentDetails{&id}{&key}
"
;
var
GET_TEMPLATE
=
UriTemplate
.
parse
(
GET_URL
);
var
ALLDOCS_URL
=
"
https://www.googleapis.com/youtube/v3/search?
"
+
"
part=snippet{&pageToken}&q={search}&type=video&maxResults=10{&key}
"
;
var
ALLDOCS_TEMPLATE
=
UriTemplate
.
parse
(
ALLDOCS_URL
);
function
handleError
(
error
,
id
)
{
if
(
error
.
target
&&
error
.
target
.
status
===
404
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document:
"
+
id
,
404
);
}
throw
error
;
}
/**
* The JIO Youtube Storage extension
*
* @class YoutubeStorage
* @constructor
*/
function
YoutubeStorage
(
spec
)
{
if
(
spec
===
undefined
||
spec
.
api_key
===
undefined
||
typeof
spec
.
api_key
!==
'
string
'
)
{
throw
new
TypeError
(
"
API Key must be a string
"
+
"
which contains more than one character.
"
);
}
this
.
_api_key
=
spec
.
api_key
;
return
;
}
YoutubeStorage
.
prototype
.
get
=
function
(
id
)
{
var
key
=
this
.
_api_key
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
GET_TEMPLATE
.
expand
({
"
id
"
:
id
,
"
key
"
:
key
})
});
})
.
push
(
function
(
evt
)
{
return
JSON
.
parse
(
evt
.
target
.
response
||
evt
.
target
.
responseText
);
},
handleError
);
};
YoutubeStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
key
=
this
.
_api_key
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
url
"
:
ALLDOCS_TEMPLATE
.
expand
({
"
search
"
:
options
.
query
,
"
key
"
:
key
,
"
pageToken
"
:
options
.
token
||
""
})
});
})
.
push
(
function
(
data
)
{
var
obj
=
JSON
.
parse
(
data
.
target
.
response
||
data
.
target
.
responseText
),
i
;
for
(
i
=
0
;
i
<
obj
.
items
.
length
;
i
+=
1
)
{
obj
.
items
[
i
].
value
=
{};
}
obj
.
items
.
nextPageToken
=
obj
.
nextPageToken
;
return
obj
.
items
;
},
handleError
);
};
YoutubeStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
((
name
===
"
list
"
)
||
(
name
===
"
include
"
)
||
(
name
===
"
query
"
));
};
jIO
.
addStorage
(
'
youtube
'
,
YoutubeStorage
);
}
(
jIO
,
RSVP
,
UriTemplate
,
JSON
));
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