forked from soraghallaigh/FH-Training-App-Sencha
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
executable file
·107 lines (95 loc) · 1.96 KB
/
main.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
/*
* Stocks
*/
function getStockInfo(param) {
return stock.getStockInfo(param.name);
}
/*
* Twitter
*/
function getTweets() {
var username = 'feedhenry';
var num_tweets = 10;
var url = 'http://search.twitter.com/search.json?q=' + username;
var response = $fh.web({
url: url,
method: 'GET',
allowSelfSignedCert: true
});
return {'data': $fh.parse(response.body).results};
}
/*
* Payment
*/
function payment() {
var cardType = $params.cardType;
var cardNumber = $params.cardNumber;
var url = "http://www.webservicex.net/CreditCard.asmx/ValidateCardNumber?cardType=" + cardType + "&cardNumber=" + cardNumber;
return $fh.web({
url: url,
method: 'GET'
});
}
/*
* Maps
*/
// Cache points for 10 seconds
var CACHE_TIME = 30;
var MARKERS = {
locations: [
{
lat: '52.245671',
lon: '-7.080002'
},
{
lat: '52.257861',
lon: '-7.136993'
}
]
};
function getCachedPoints() {
var ret = $fh.cache({
"act": "load",
"key": "points"
});
return ret.val;
}
function cachePoints(hash, data) {
var obj = {
"hash": hash,
"data": data,
"cached": true
};
$fh.cache({
"act": "save",
"key": "points",
"val": obj,
"expire": CACHE_TIME
});
}
function getPoints() {
var response = {};
var cache = getCachedPoints();
if (cache.length === 0) {
var data = MARKERS;
var hash = $fh.hash({
algorithm: 'MD5',
text: $fh.stringify(data)
});
// Cache the data
cachePoints(hash, data);
// Build the response
response = {'data': data, 'hash':hash, 'cached':false};
} else {
// Parse the cached data
cache = $fh.parse(cache);
if( $params.hash && $params.hash === cache.hash ) {
// Client data is up to date
response = {'hash':$params.hash, 'cached':true};
} else {
// Hash value from client missing or incorrect, return cached cloud data
response = cache;
}
}
return response;
}