forked from scratchfoundation/scratchx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_extension.js
39 lines (32 loc) · 1.21 KB
/
weather_extension.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
/* Extension demonstrating a blocking reporter block */
/* Sayamindu Dasgupta <[email protected]>, May 2014 */
new (function() {
var ext = this;
// Cleanup function when the extension is unloaded
ext._shutdown = function() {};
// Status reporting code
// Use this to report missing hardware, plugin or unsupported browser
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
ext.get_temp = function(location, callback) {
// Make an AJAX call to the Open Weather Maps API
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?q='+location+'&units=imperial',
dataType: 'jsonp',
success: function( weather_data ) {
// Got the data - parse it and return the temperature
temperature = weather_data['main']['temp'];
callback(temperature);
}
});
};
// Block and block menu descriptions
var descriptor = {
blocks: [
['R', 'current temperature in city %s', 'get_temp', 'Boston, MA'],
]
};
// Register the extension
ScratchExtensions.register('Weather extension', descriptor, ext);
})();