Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making sure the service URL is protocol neutral so as not to break locks #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ Performs an API search query.
Default:
Type: Mixed

### Return Value

true

search_unfiltered
-----------------
Performs an unfiltered API search query, which will return all videos including deleted, inactive, and scheduled videos.

**Note:** `_unfiltered` methods are not enabled by default — they must be enabled by Brightcove Support

- **pParams** *Either an object containing the API parameters to apply to the given command, or a single value which is applied to the command's default selector; for "any", "all" or "none" arguments, use a string value for a single search term, or an array value for multiple search terms*

Default:
Type: Mixed

### Return Value

true
42 changes: 29 additions & 13 deletions bc-mapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
var BCMAPI = new function () {
this.token = "";
this.callback = "BCMAPI.flush";
this.url = "http://api.brightcove.com/services/library";
this.url = "//api.brightcove.com/services/library";
this.request = this.url;
this.calls = [
{ "command" : "find_all_videos", "def" : false },
Expand All @@ -41,7 +41,8 @@ var BCMAPI = new function () {
{ "command" : "find_playlist_by_reference_id", "def" : "reference_id" },
{ "command" : "find_playlists_by_reference_ids", "def" : "reference_ids" },
{ "command" : "find_playlists_for_player_id", "def" : "player_id" },
{ "command" : "search_videos", "def" : "all" }
{ "command" : "search_videos", "def" : "all" },
{ "command" : "search_videos_unfiltered", "def" : "all"}
];

/**
Expand All @@ -52,11 +53,15 @@ var BCMAPI = new function () {
*/
this.inject = function (pQuery) {
var pElement = document.createElement("script");
// if url has been modified, make sure it is protocol-neutral
if (this.url.indexOf("//") !== 0) {
this.url = this.url.substring(this.url.indexOf("//"));
}
this.request = this.url + "?" + pQuery;
pElement.setAttribute("src", this.request);
pElement.setAttribute("type", "text/javascript");
document.getElementsByTagName("head")[0].appendChild(pElement);

return true;
};

Expand All @@ -68,6 +73,7 @@ var BCMAPI = new function () {
* @return true
*/
this.find = function (pCommand, pParams) {
var tempArray;
pCommand = pCommand.toLowerCase().replace(/(find_)|(_)|(get_)/g, "");
pParams = pParams || null;
var pDefault = null;
Expand All @@ -77,14 +83,14 @@ var BCMAPI = new function () {
if (typeof this.calls[pCall].command == "undefined") {
continue;
}

if (pCommand == this.calls[pCall].command.toLowerCase().replace(/(find_)|(_)|(get_)/g, "")) {
pCommand = this.calls[pCall].command;

if (typeof this.calls[pCall].def != "undefined") {
pDefault = this.calls[pCall].def;
}

break;
}
}
Expand All @@ -95,14 +101,14 @@ var BCMAPI = new function () {
for (var pParam in pParams) {
if (pParam == "any" || pParam == "all" || pParam == "none") {
if (this.isArray(pParams[pParam])) {
for (var idx in pParams[pParam]) {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam][idx]);
}
} else {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam]);
for (var idx in pParams[pParam]) {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam][idx]);
}
} else {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam]);
}
}
if (pParam == "selector" && pParam !== "all") {
if (pParam == "selector" && pParam !== "all") {
pQuery += "&" + pDefault + "=" + encodeURIComponent(pParams[pParam]);
} else {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam]);
Expand Down Expand Up @@ -138,7 +144,17 @@ var BCMAPI = new function () {
this.search = function (pParams) {
return this.find("search_videos", pParams);
};


/**
* Performs an API search_videos_unfiltered query
* @since 1.0
* @param mixed [pParams] Either an object containing the API parameters to apply to the given command, or a single value which is applied to the command's default selector
* @return true
*/
this.search_unfiltered = function (pParams) {
return this.find("search_videos_unfiltered", pParams);
};

/**
* Determines if param member is an array
* @since 1.1
Expand Down