CanTweet – A rails, twitter and html5 canvas experiment

Welcome to 1 of the coolest post I’ve done =)

Me and my friend @pirelenito(+blog) we’re coding yesterday, he wanted to learn Rails, and I get something new, the result was this marvelous creation: the CanTweet

The highlights inner work of the code is basically how we get the info from Twitter ruby API and convert the twits length into the new Canvas tag element from HTML5,

Here is a small snip from our lib PV created:

require "twitter"

class TwitRetriever
  COUNT = 50
# ...
def sizes
    twits = []
   Twitter::Search.new.containing(@keyword).per_page(COUNT).fetch.results.each do |r|
      twits.push r.text.size
    end
    twits
  end
end

And finally we draw in the canvas using the functions:


var graph = document.getElementById("graph")
var context = graph.getContext("2d")
context.strokeRect()
context.strokeStyle = "rgb(r,g,b)"
context.beginPath()
context.lineTo(x, y)
context.stroke()

Resources:
CANVAS
https://developer.mozilla.org/en/HTML/Canvas
https://developer.mozilla.org/en/Canvas_tutorial
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#2dcontext

TWITTER API
http://twitter.rubyforge.org/
http://github.com/jnunemaker/twitter
http://rdoc.info/projects/jnunemaker/twitter

Advertisements

One thought on “CanTweet – A rails, twitter and html5 canvas experiment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s