-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
104 lines (98 loc) · 2.61 KB
/
code.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
const urlTwitterServer = "http://twitterhello.scripting.com/";
function servercall (verb, params, flAuthenticated, callback, method, postbody) {
function buildParamList (paramtable) {
var s = "";
for (var x in paramtable) {
if (s.length > 0) {
s += "&";
}
s += x + "=" + encodeURIComponent (paramtable [x]);
}
return (s);
}
if (flAuthenticated === undefined) {
flAuthenticated = true;
}
if (params === undefined) {
params = new Object ();
}
if (method === undefined) {
method = "GET";
}
if (flAuthenticated) {
params.oauth_token = localStorage.twOauthToken;
params.oauth_token_secret = localStorage.twOauthTokenSecret;
}
var apiUrl = urlTwitterServer + verb;
var paramString = buildParamList (params);
if (paramString.length > 0) {
apiUrl += "?" + paramString;
}
console.log ("serverCall: verb == " + verb + ", apiUrl == " + apiUrl);
$.ajax ({
type: method,
url: apiUrl,
data: postbody,
success: function (data) {
if (callback !== undefined) {
callback (undefined, data);
}
},
error: function (status, something, otherthing) {
console.log ("serverCall: error == " + JSON.stringify (status, undefined, 4));
if (callback !== undefined) {
var err = {
code: status.status,
message: JSON.parse (status.responseText).message
};
if (callback !== undefined) {
callback (err);
}
}
},
dataType: "json"
});
}
function signOnTwitter () {
$(".btn").blur ();
twConnectToTwitter ();
}
function signOffTwitter () {
twDisconnectFromTwitter ();
location.reload ();
}
function sendHelloWorldTweet () {
$(".btn").blur ();
var lastMessage = "Hello world.";
if (localStorage.lastMessage !== undefined) {
lastMessage = localStorage.lastMessage;
}
askDialog ("Enter your Hello World message:", lastMessage, "Hello world.", function (helloWorldMessage, flcancel) {
if (!flcancel) {
servercall ("sendtweet", {message: helloWorldMessage}, true, function (err, result) {
if (err) {
alertDialog ("Can't send the tweet because: " + err.message);
}
else {
alertDialog ("It worked!");
console.log (jsonStringify (result));
}
});
localStorage.lastMessage = helloWorldMessage;
}
});
}
function startup () {
console.log ("startup");
twStorageData.urlTwitterServer = urlTwitterServer;
twGetOauthParams ();
if (twIsTwitterConnected ()) {
$("#idTwitterScreenname").text (twGetScreenName ());
$("#idSignedOn").css ("display", "block");
$("#idNotSignedOn").css ("display", "none");
}
else {
$("#idNotSignedOn").css ("display", "block");
$("#idSignedOn").css ("display", "none");
}
}