Skip to content

Instantly share code, notes, and snippets.

@gdeest
Created March 17, 2012 21:02
Show Gist options
  • Save gdeest/2065254 to your computer and use it in GitHub Desktop.
Save gdeest/2065254 to your computer and use it in GitHub Desktop.
Fun with Twitter
import stdlib.apis.twitter
twitter_config = Twitter({ consumer_key: "XXX",
consumer_secret: "XXX" });
function user_tweets(user) {
twitter_config.get_user_timeline(
user,
twitter_config.default_timeline, {none})
}
function render_tweet(tweet) {
<div class=tweet>
<h2>{tweet.created_at}</h2>
<div class=msg>{tweet.text}</div>
</div>
}
function render_tweets(tweets) {
Xhtml.createFragment(
List.map(render_tweet, tweets))
}
function load_tweets(screen_name, selector) {
function (_) {
*selector = render_tweets(user_tweets({~screen_name}))
}
}
function latest_tweets(screen_name) {
<div id=msgs onready={load_tweets(screen_name, #msgs)}>
Tweets not yet loaded...
</>
}
function dispatch(url) {
match(url) {
case { path: ["user", screen_name] ...}:
Resource.page("Latest tweets for: {screen_name}", latest_tweets(screen_name))
case { ~path ... }:
Resource.page("Hello", <h1>Hello !</h1>)
}
}
Server.start(Server.http, {~dispatch} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment