Last active
July 26, 2016 13:10
-
-
Save noahbass/848963ef1c21fb8d0e00 to your computer and use it in GitHub Desktop.
Meteor external api example: bibles.org api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>meteor external api example</title> | |
</head> | |
<body> | |
<table> | |
<p>{{{verse.verse}}}</p> | |
<p>{{{verse.text}}}</p> | |
</table> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.isClient) { | |
Verse = new Mongo.Collection('verse'); | |
Meteor.subscribe('getVerse'); | |
Template.body.helpers({ | |
verse: function() { | |
return Verse.findOne(); | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
Meteor.publish('getVerse', function() { | |
var self = this; | |
try { | |
var res = HTTP.get('https://bibles.org/v2/chapters/eng-KJVA:1Cor.2/verses.js', { | |
auth: 'bibles.orgapikey:' | |
}); | |
var item = JSON.parse(res.content); | |
var item = item.response; | |
var doc = { | |
text: item.verses[0].text, | |
verse: item.verses[0].verse | |
}; | |
self.added('verse', Random.id(), doc); | |
self.ready(); | |
} catch(error) { | |
console.log(error); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Meteor packages used by this project, one per line. | |
# | |
# 'meteor add' and 'meteor remove' will edit this file for you, | |
# but you can also edit it by hand. | |
meteor-platform | |
insecure | |
http |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment