Skip to content

Commit

Permalink
impr: allow more params (close #8 & close #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyTheTank committed Feb 3, 2016
1 parent 09fced8 commit 5822dad
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 45 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Author: Jonathan Hornung ([JohnnyTheTank](https://github.com/JohnnyTheTank))
//docs: https://developers.google.com/youtube/v3/docs/videos/list
youtubeFactory.getVideoById({
videoId: "<VIDEO_ID>",
part: "<YOUR_PART>", // (optional) default: 'id,snippet,contentDetails,statistics'
key: "<YOUR_API_KEY>",
}).then(function (_data) {
//on success
Expand All @@ -48,8 +49,18 @@ youtubeFactory.getVideosFromChannelById({
channelId: "<CHANNEL_ID>",
q: "<SEARCH_STRING>", // (optional) filters the channel result with your search string
order: "<ORDER_TYPE>", // (optional) valid values: 'date', 'rating', 'relevance', 'title', 'videoCount', 'viewCount' | default: 'date'
publishedAfter: "<PUBLISHED_AFTER>", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
publishedBefore: "<PUBLISHED_AFTER>", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
regionCode: "<REGION_CODE>", // (optional) ISO 3166-1 alpha-2 country code
relevanceLanguage: "<RELEVANCE_LANGUAGE>", // (optional) ISO 639-1 two-letter language code
safeSearch: "<SAFE_SEARCH>", // (optional) valid values: 'moderate','none','strict' | defaut: 'moderate'
maxResults: "<MAX_RESULTS>", // (optional) valid values: 0-50 | default: 5
videoEmbeddable: "<VIDEO_EMBEDDABLE>", // (optional) valid values: 'true', 'any' | default: 'true'
videoLicense: "<VIDEO_LICENSE>", // (optional) valid values: 'any','creativeCommon','youtube'
videoSyndicated: "<VIDEO_SYNDICATED>", // (optional) restrict a search to only videos that can be played outside youtube.com. valid values: 'any','true' | default: 'any'
fields: "<FIELDS>", // (optional) Selector specifying which fields to include in a partial response
pageToken: "<PAGE_TOKEN>", // (optional)
part: "<PART>", // (optional) default: 'id,snippet'
key: "<YOUR_API_KEY>",
}).then(function (_data) {
//on success
Expand All @@ -66,7 +77,18 @@ youtubeFactory.getVideosFromSearchByParams({
locationRadius: "<LOCATION_RADIUS>", // (optional) valid values e.g. '1500m', '5km', '10000ft', and '0.75mi' | default: '5000m'
order: "<ORDER_TYPE>", // (optional) valid values: 'date', 'rating', 'relevance', 'title', 'videoCount', 'viewCount' | default: 'date'
maxResults: "<MAX_RESULTS>", // (optional) valid values: 0-50 | default: 5
publishedAfter: "<PUBLISHED_AFTER>", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
publishedBefore: "<PUBLISHED_AFTER>", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
regionCode: "<REGION_CODE>", // (optional) ISO 3166-1 alpha-2 country code
relevanceLanguage: "<RELEVANCE_LANGUAGE>", // (optional) ISO 639-1 two-letter language code
safeSearch: "<SAFE_SEARCH>", // (optional) valid values: 'moderate','none','strict' | defaut: 'moderate'
maxResults: "<MAX_RESULTS>", // (optional) valid values: 0-50 | default: 5
videoEmbeddable: "<VIDEO_EMBEDDABLE>", // (optional) valid values: 'true', 'any' | default: 'true'
videoLicense: "<VIDEO_LICENSE>", // (optional) valid values: 'any','creativeCommon','youtube'
videoSyndicated: "<VIDEO_SYNDICATED>", // (optional) restrict a search to only videos that can be played outside youtube.com. valid values: 'any','true' | default: 'any'
fields: "<FIELDS>", // (optional) Selector specifying which fields to include in a partial response
pageToken: "<PAGE_TOKEN>", // (optional)
part: "<PART>", // (optional) default: 'id,snippet'
key: "<YOUR_API_KEY>",
}).then(function (_data) {
//on success
Expand All @@ -81,6 +103,7 @@ youtubeFactory.getVideosFromPlaylistById({
playlistId: "<PLAYLIST_ID>",
maxResults: "<MAX_RESULTS>", // (optional) valid values: 0-50 // default: 5
pageToken: "<PAGE_TOKEN>", // (optional)
part: "<PART>", // (optional) default: 'id,snippet'
key: "<YOUR_API_KEY>",
}).then(function (_data) {
//on success
Expand All @@ -96,6 +119,7 @@ youtubeFactory.getVideosFromPlaylistById({
youtubeFactory.getChannelById({
channelId: "<CHANNEL_ID>",
pageToken: "<PAGE_TOKEN>", // (optional)
part: "<PART>", // (optional) default: 'id,snippet'
key: "<YOUR_API_KEY>",
}).then(function (_data) {
//on success
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Jonathan Hornung <[email protected]>"
],
"version": "0.5.0",
"version": "0.6.0",
"description": "angular factory for youtube rest api connection",
"main": "dist/angular-youtube-api-factory.min.js",
"moduleType": [],
Expand Down
118 changes: 97 additions & 21 deletions dist/angular-youtube-api-factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
@name: angular-youtube-api-factory
@version: 0.5.0 (06-01-2016)
@version: 0.6.0 (03-02-2016)
@author: Jonathan Hornung
@url: https://github.com/JohnnyTheTank/angular-youtube-api-factory#readme
@license: MIT
Expand Down Expand Up @@ -78,94 +78,170 @@ angular.module("jtt_youtube", [])

var youtubeSearchData = {
object: {
part: "id,snippet",
key: _params.key,
},
url: "",
};

if (angular.isDefined(_params.part)) {
youtubeSearchData.object.part = _params.part;
}

switch (_type) {
case "videosFromChannelById":
if (angular.isUndefined(_params.part)) {
youtubeSearchData.object.part = "id,snippet";
}
youtubeSearchData.object.type = "video";
youtubeSearchData.object.channelId = _params.channelId;

if (typeof _params.order !== "undefined") {
if (angular.isDefined(_params.order)) {
youtubeSearchData.object.order = _params.order;
} else {
youtubeSearchData.object.order = "date";
}
if (typeof _params.q !== "undefined") {
if (angular.isDefined(_params.q)) {
youtubeSearchData.object.q = _params.q;
}
if (typeof _params.maxResults !== "undefined") {
if (angular.isDefined(_params.maxResults)) {
youtubeSearchData.object.maxResults = _params.maxResults;
}
if (angular.isDefined(_params.publishedAfter)) {
youtubeSearchData.object.publishedAfter = _params.publishedAfter;
}
if (angular.isDefined(_params.publishedBefore)) {
youtubeSearchData.object.publishedBefore = _params.publishedBefore;
}
if (angular.isDefined(_params.regionCode)) {
youtubeSearchData.object.regionCode = _params.regionCode;
}
if (angular.isDefined(_params.relevanceLanguage)) {
youtubeSearchData.object.relevanceLanguage = _params.relevanceLanguage;
}
if (angular.isDefined(_params.safeSearch)) {
youtubeSearchData.object.safeSearch = _params.safeSearch;
}
if (angular.isDefined(_params.videoEmbeddable)) {
youtubeSearchData.object.videoEmbeddable = _params.videoEmbeddable;
} else {
youtubeSearchData.object.videoEmbeddable = true;
}
if (angular.isDefined(_params.videoLicense)) {
youtubeSearchData.object.videoLicense = _params.videoLicense;
}
if (angular.isDefined(_params.videoSyndicated)) {
youtubeSearchData.object.videoSyndicated = _params.videoSyndicated;
}
if (angular.isDefined(_params.fields)) {
youtubeSearchData.object.fields = _params.fields;
}

youtubeSearchData.url = this.getApiBaseUrl() + "search?";

if (typeof _params.nextPageToken !== "undefined") {
if (angular.isDefined(_params.nextPageToken)) {
youtubeSearchData.url += "pageToken=" + _params.nextPageToken + "&";
}
break;

case "videosFromSearchByParams":
if (angular.isUndefined(_params.part)) {
youtubeSearchData.object.part = "id,snippet";
}
youtubeSearchData.object.type = "video";
if (typeof _params.order !== "undefined") {
if (angular.isDefined(_params.order)) {
youtubeSearchData.object.order = _params.order;
} else {
youtubeSearchData.object.order = "date";
}
if (typeof _params.q !== "undefined") {
if (angular.isDefined(_params.q)) {
youtubeSearchData.object.q = _params.q;
}
if (typeof _params.location !== "undefined") {
if (angular.isDefined(_params.location)) {
youtubeSearchData.object.location = _params.location;
}
if (typeof _params.locationRadius !== "undefined") {
if (angular.isDefined(_params.locationRadius)) {
youtubeSearchData.object.locationRadius = _params.locationRadius;
} else {
if (typeof _params.location !== "undefined") {
if (angular.isDefined(_params.location)) {
youtubeSearchData.object.locationRadius = "5000m"
}
}
if (typeof _params.maxResults !== "undefined") {
if (angular.isDefined(_params.maxResults)) {
youtubeSearchData.object.maxResults = _params.maxResults;
}
if (angular.isDefined(_params.publishedAfter)) {
youtubeSearchData.object.publishedAfter = _params.publishedAfter;
}
if (angular.isDefined(_params.publishedBefore)) {
youtubeSearchData.object.publishedBefore = _params.publishedBefore;
}
if (angular.isDefined(_params.regionCode)) {
youtubeSearchData.object.regionCode = _params.regionCode;
}
if (angular.isDefined(_params.relevanceLanguage)) {
youtubeSearchData.object.relevanceLanguage = _params.relevanceLanguage;
}
if (angular.isDefined(_params.safeSearch)) {
youtubeSearchData.object.safeSearch = _params.safeSearch;
}
if (angular.isDefined(_params.videoEmbeddable)) {
youtubeSearchData.object.videoEmbeddable = _params.videoEmbeddable;
} else {
youtubeSearchData.object.videoEmbeddable = true;
}
if (angular.isDefined(_params.videoLicense)) {
youtubeSearchData.object.videoLicense = _params.videoLicense;
}
if (angular.isDefined(_params.videoSyndicated)) {
youtubeSearchData.object.videoSyndicated = _params.videoSyndicated;
}
if (angular.isDefined(_params.fields)) {
youtubeSearchData.object.fields = _params.fields;
}

youtubeSearchData.url = this.getApiBaseUrl()+"search?";
if (typeof _params.nextPageToken !== "undefined") {
youtubeSearchData.url = this.getApiBaseUrl() + "search?";
if (angular.isDefined(_params.nextPageToken)) {
youtubeSearchData.url += "pageToken=" + _params.nextPageToken + "&";
}
break;

case "videosFromPlaylistById":
if (angular.isUndefined(_params.part)) {
youtubeSearchData.object.part = "id,snippet";
}
youtubeSearchData.object.playlistId = _params.playlistId;
youtubeSearchData.object.type = "video";

if (typeof _params.maxResults !== "undefined") {
if (angular.isDefined(_params.maxResults)) {
youtubeSearchData.object.maxResults = _params.maxResults;
}

youtubeSearchData.url = this.getApiBaseUrl()+"playlistItems?";
if (typeof _params.nextPageToken !== "undefined") {
youtubeSearchData.url = this.getApiBaseUrl() + "playlistItems?";
if (angular.isDefined(_params.nextPageToken)) {
youtubeSearchData.url += "pageToken=" + _params.nextPageToken + "&";
}
break;

case "videoById":
if (angular.isUndefined(_params.part)) {
youtubeSearchData.object.part = "id,snippet,contentDetails,statistics";
}
youtubeSearchData.object.id = _params.videoId;

youtubeSearchData.url = this.getApiBaseUrl()+"videos?";
if (typeof _params.nextPageToken !== "undefined") {
youtubeSearchData.url = this.getApiBaseUrl() + "videos?";
if (angular.isDefined(_params.nextPageToken)) {
youtubeSearchData.url += "pageToken=" + _params.nextPageToken + "&";
}
break;

case "channelById":
if (angular.isUndefined(_params.part)) {
youtubeSearchData.object.part = "id,snippet";
}
youtubeSearchData.object.type = "channel";

youtubeSearchData.url = this.getApiBaseUrl()+"search?";
if (typeof _params.nextPageToken !== "undefined") {
youtubeSearchData.url = this.getApiBaseUrl() + "search?";
if (angular.isDefined(_params.nextPageToken)) {
youtubeSearchData.url += "pageToken=" + _params.nextPageToken + "&";
}
break;
Expand Down
Loading

0 comments on commit 5822dad

Please sign in to comment.