-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspaceApi.js
43 lines (40 loc) · 1.05 KB
/
spaceApi.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
if (Meteor.isClient) {
Template.contentRegion.helpers({
viewData: function () {
return Session.get('apiData');
},
dataType: function () {
var mediaType = Session.get('apiData').media_type;
var templateName = mediaType+'Template';
return templateName
}
});
Template.contentRegion.events({
'click button': function (e,t) {
e.preventDefault();
var id = Meteor.settings.public.nasaApiKey;
Meteor.call('getData', id, function(e, r){
if(e){
Session.set('apiData',{error: e});
} else {
Session.set('apiData',r);
return r;
}
});
$('button').attr('disabled','disabled');
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
Meteor.methods({
'getData':function(id){
console.log('Getting data for ', id);
var apiUrl = "https://api.nasa.gov/planetary/apod?api_key="+id;
var response = HTTP.get(apiUrl).data;
return response
}
});
});
}