-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathokscript.js
More file actions
65 lines (61 loc) · 2.79 KB
/
okscript.js
File metadata and controls
65 lines (61 loc) · 2.79 KB
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
OKAPIWrapper = {
unityObject : null,
processAPIIniterror : function(errorObject) {
console.log("OK API Init error");
},
init : function (unityobject){
OKAPIWrapper.unityObject = unityobject;
var rParams = FAPI.Util.getRequestParameters();
FAPI.init(rParams["api_server"], rParams["apiconnection"],
function() {},
function(error){
OKAPIWrapper.processAPIIniterror(error);
});
},
unity_api_call : function(parameters){
if (!(OKAPIWrapper.unityObject && OKAPIWrapper.unityObject.getUnity !== undefined && OKAPIWrapper.unityObject.getUnity().SendMessage !== undefined)){
console.log("OKAPIWrapper is not initsialized or no unityObject passed to OKAPIWrapper. If you are using internet explorer, is'possible, that script works correct, please, check it in debugger.");
}
FAPI.Client.call(JSON.parse(parameters), OKAPIWrapper.unity_api_callback);
},
unity_api_callback: function(method,result,data){
OKAPIWrapper.unityObject.getUnity().SendMessage("OKAPI", "APIMethodCallback", JSON.stringify(result));
}
}
var feedPostingObject;
function API_callback(method, result, data) {
if (method == "showConfirmation" && result == "ok") {
FAPI.Client.call(feedPostingObject, function(status, data, error) {
var rez = {"status":status, "data":data, "error":error};
OKAPIWrapper.unityObject.getUnity().SendMessage("OKAPI", "PublishCallback", JSON.stringify(rez));
}, data);
return;
}
if (method == "showConfirmation" && result != "ok") {
var rez = {"status":status, "data":data, "error":error};
OKAPIWrapper.unityObject.getUnity().SendMessage("OKAPI", "PublishCallback", JSON.stringify(rez));
return;
}
var rez = {"method":method, "result":result, "data":data};
OKAPIWrapper.unityObject.getUnity().SendMessage("OKAPI", "JSMethodCallback", JSON.stringify(rez));
}
function getUrlVars()
{
var vars = new Object(), hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars[hash[0]] = hash[1];
}
OKAPIWrapper.unityObject.getUnity().SendMessage("OKAPI", "GetUrlVarsCallback", JSON.stringify(vars));
}
function publish(description, streamMessage, JSONAttachments, JSONActionLinks){
feedPostingObject = { method: 'stream.publish',
message: streamMessage,
attachment: JSONAttachments,
action_links: JSONActionLinks
};
sig = FAPI.Client.calcSignature(feedPostingObject);
FAPI.UI.showConfirmation('stream.publish', description, sig);
}