forked from BrightcoveOS/Brightcove-Wordpress-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbc-mapi.js
162 lines (146 loc) · 5.97 KB
/
bc-mapi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Brightcove JavaScript MAPI Wrapper 1.2 (16 FEBRUARY 2011)
* (Formerly known as Kudos)
*
* REFERENCES:
* Website: http://opensource.brightcove.com
* Source: http://github.com/brightcoveos
*
* AUTHORS:
* Brian Franklin <[email protected]>
* Matthew Congrove <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, alter, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, subject to the following conditions:
*
* 1. The permission granted herein does not extend to commercial use of
* the Software by entities primarily engaged in providing online video and
* related services.
*
* 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, SUITABILITY, TITLE,
* NONINFRINGEMENT, OR THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE, INABILITY TO USE, OR OTHER DEALINGS IN THE SOFTWARE.
*
* 3. NONE OF THE AUTHORS, CONTRIBUTORS, NOR BRIGHTCOVE SHALL BE RESPONSIBLE
* IN ANY MANNER FOR USE OF THE SOFTWARE. THE SOFTWARE IS PROVIDED FOR YOUR
* CONVENIENCE AND ANY USE IS SOLELY AT YOUR OWN RISK. NO MAINTENANCE AND/OR
* SUPPORT OF ANY KIND IS PROVIDED FOR THE SOFTWARE.
*/
var BCMAPI = new function () {
this.token = "";
this.callback = "BCMAPI.flush";
this.url = "http://api.brightcove.com/services/library";
this.calls = [
{ "command" : "find_all_videos", "def" : false },
{ "command" : "find_video_by_id", "def" : "video_id" },
{ "command" : "find_video_by_id_unfiltered", "def" : "video_id" },
{ "command" : "find_videos_by_ids", "def" : "video_ids" },
{ "command" : "find_videos_by_ids_unfiltered", "def" : "video_ids" },
{ "command" : "find_video_by_reference_id", "def" : "reference_id" },
{ "command" : "find_video_by_reference_id_unfiltered", "def" : "reference_id" },
{ "command" : "find_videos_by_reference_ids", "def" : "reference_ids" },
{ "command" : "find_videos_by_reference_ids_unfiltered", "def" : "reference_ids" },
{ "command" : "find_videos_by_campaign_id", "def" : "campaign_id" },
{ "command" : "find_videos_by_tags", "def" : "or_tags" },
{ "command" : "find_videos_by_text", "def" : "text" },
{ "command" : "find_videos_by_user_id", "def" : "user_id" },
{ "command" : "find_modified_videos", "def" : "from_date" },
{ "command" : "find_related_videos", "def" : "video_id" },
{ "command" : "find_all_playlists", "def" : false },
{ "command" : "find_playlist_by_id", "def" : "playlist_id" },
{ "command" : "find_playlists_by_ids", "def" : "playlist_ids" },
{ "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" }
];
/**
* Injects API calls into the head of a document
* @since 0.1
* @param string [pQuery] The query string for the API call to inject
* @return true
*/
this.inject = function (pQuery) {
var pElement = document.createElement("script");
pElement.setAttribute("src", this.url + "?" + pQuery);
pElement.setAttribute("type", "text/javascript");
document.getElementsByTagName("head")[0].appendChild(pElement);
return true;
};
/**
* Performs an API query.
* @since 1.0
* @param string [pCommand] A Brightcove API method
* @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.find = function (pCommand, pParams) {
pCommand = pCommand.toLowerCase().replace(/(find_)|(_)|(get_)/g, "");
pParams = pParams || null;
var pDefault = null;
var pQuery = "";
for (var pCall in this.calls) {
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;
}
}
pQuery = "command=" + pCommand;
if ((typeof pParams == "object") && pParams) {
for (var pParam in pParams) {
if (pParam == "selector") {
pQuery += "&" + pDefault + "=" + encodeURIComponent(pParams[pParam]);
} else {
pQuery += "&" + pParam + "=" + encodeURIComponent(pParams[pParam]);
}
}
if (typeof pParams.callback != "string") {
pQuery += "&callback=" + this.callback;
}
if (typeof pParams.token != "string") {
pQuery += "&token=" + this.token;
}
} else if (pParams) {
pQuery += "&" + pDefault + "=" + encodeURIComponent(pParams) + "&callback=" + this.callback;
pQuery += "&token=" + this.token;
} else {
pQuery += "&token=" + this.token;
pQuery += "&callback=" + this.callback;
}
this.inject(pQuery);
return true;
};
/**
* Performs an API search 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 = function (pParams) {
return this.find("search_videos", pParams);
};
/**
* Default callback which does nothing
* @since 0.1
* @param mixed [pData] The data returned from the API
* @return true
*/
this.flush = function (pData) {
return true;
};
}();