Created
February 28, 2011 06:52
This file contains 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
### Getting entries from my blog (Posterous) | |
getBlogPosts = -> | |
req = $.ajax 'http://query.yahooapis.com/v1/public/yql', | |
jsonp:'callback' | |
dataType:'jsonp' | |
data: | |
q: "select channel.item.title, channel.item.pubDate, | |
channel.item.link from xml where | |
url = 'http://blog.jrmoran.com/rss' limit 6" | |
format: 'json' | |
req.success (res) -> | |
if res.query.count > 0 | |
# comprehension will iterate over each entry, parse them to html | |
# and add them to the array `htmlstr` | |
htmlstr = for post in res.query.results.rss | |
item = post.channel.item | |
date = item.pubDate.substring 0,16 | |
"<li> | |
<a href = ' #{ item.link } '> #{ item.title} </a><br> | |
<span class = 'date' > #{ date } </span> | |
</li>" | |
$('#recent-posts').append htmlstr.join('') |
This file contains 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
### Getting entries from my blog (Octopress) | |
# `targetNode` is a jQuery object | |
loadBlogPosts: (targetNode)-> | |
# return an html string representation of an entry | |
renderEntry= (entry)-> | |
"<li> | |
<a href = ' #{ entry.url } '> #{ entry.title} </a><br> | |
<span class = 'date' > #{ entry.date } </span> | |
</li>" | |
# Retrieving posts from My blog using YQL | |
# | |
# * `callback` used by YQL to reference the callback function | |
# * `JSONP` for cross-domain request | |
# * `q` YQL query | |
# | |
req = $.ajax 'http://query.yahooapis.com/v1/public/yql', | |
jsonp:'callback' | |
dataType:'jsonp' | |
data: | |
q: "select entry.title.content, entry.link, entry.updated from xml where | |
url = 'http://blog.jrmoran.com/atom.xml' limit 6" | |
format: 'json' | |
# Processing response | |
req.success (data) -> | |
if data.query.count > 0 | |
# comprehension will iterate over each entry, parse them to html | |
# and add them to the array `htmlstr` | |
htmlstr = for result in data.query.results.feed | |
renderEntry | |
url : result.entry.link.href | |
title: result.entry.title | |
date : result.entry.updated.substring 0, 10 | |
targetNode.append htmlstr.join '' |
This file contains 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
// Retrieving posts from My blog using YQL | |
// @requires jQuery 1.5.1 | |
var req = $.ajax('http://query.yahooapis.com/v1/public/yql', { | |
// YQL uses this parameter to reference the callback function | |
jsonp:'callback', | |
// This is a cross-domain request so JSONP must be used | |
dataType:'jsonp', | |
data: { | |
// this is the actual YQL query and the format of the response | |
q: "select channel.item.title, channel.item.pubDate, " + | |
"channel.item.link from xml where " + | |
"url = 'http://blog.jrmoran.com/rss' limit 5", | |
format: 'json' | |
} | |
}); | |
// Working with the response | |
req.success(function(res){ | |
//work with the response here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment