-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (47 loc) · 1.54 KB
/
server.js
File metadata and controls
49 lines (47 loc) · 1.54 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
Meteor.methods ({'callWordpress' :
// takes site WITH slash and directive .. just appends the two together
function(site,directive){
if(typeof site != "undefined" && typeof site == "string" && site != '' && typeof directive != "undefined" && typeof directive == "string" && directive != '')
var q = HTTP.get(site + directive,{headers: {"Accept":"application/json"} });
if(q.statusCode==200){
var respJson = JSON.parse(q.content);
return respJson;
}else{
return {error: q.statusCode};
}
return false;
}
});
Meteor.publish("wordpress",function(site,directive){
if(typeof site != "undefined" && typeof site == "string" && site != ''){
if(typeof directive == "undefined" || typeof directive != "string" || directive == ''){
directive = "json=get_recent_posts";
}
var q = HTTP.get(site + '?' + directive,{headers: {"Accept":"application/json"} });
if(q.statusCode==200){
var respJson = JSON.parse(q.content);
if(respJson && typeof respJson.posts != "undefined")
{
respJson.posts.filter(function(arr){
// avoid entering same id?
arr._id = arr.id + '';
if(Wordpress.findOne({_id : arr.id + ""})){
Wordpress.upsert(arr._id,arr)
}else{
Wordpress.insert(arr);
}
});
return Wordpress.find();
}else{
this.ready();
}
}else{
this.ready();
return {error: q.statusCode};
}
}
this.ready();
});
Meteor.publish("wpPost",function(id){
return Wordpress.find({_id : id + ""});
});