Sample Code

Calling the Cascaad Supertweet API from your code is really simple as the exposed methods are simply accessible over HTTP from any platform/language.

The following are some examples that you can use to build your own SuperTweet-enhanced application. Notice you will need an api_key (in the examples you will see it marked as YOURAPIKEY) to use this APIs, you can register and get one without any questions asked, so just do it and start experimenting :)

Ruby Example

Using the standard library  open-uri is enough for fetching the data

require 'open-uri'
require 'json'

BASE_URL='http://openapi.cascaad.com/1/supertweet'
def show_messages(*ids)
  open("%s/show.json?api_key=YOURAPIKEY&domain=twitter.com&message=%s" % [BASE_URL, ids.join(",")]) do |code|
    JSON.parse(code.read)
  end
end
def related_messages(id)
  open("%s/related.json?api_key=YOURAPIKEY&domain=twitter.com&message=%s" % [BASE_URL, id]) do |code|
    JSON.parse(code.read)
  end
end

Now, suppose for eample that you want to see what entities are talked about in techcrunch's feed, using the Twitter gem:

require 'twitter'
tl = Twitter.timeline 'techcrunch'

ids= tl.map { |e| e['id'] }
  
freq = Hash.new(0)
show_messages(ids).map do |s|
  s['supertweet']['context']['entities'].each do |entity|
    freq[entity['label']] += 1
  end
end

puts freq.sort_by { |k,v| -v }


You should see something like his:

android
3
google
3
iphone
2
zynga
1
gnu/linux
1
dailymotion
1
ipad
1
facebook
1
aol
1
netflix
1
san francisco
1
gmail
1

 

Python Example

Using urllib2 and simplejson the SuperTweet API cab be easily accessed via python as well. The following script allows you to see what is the social rank of the tweets in a user timeline:

import simplejson, urllib2, sys
SUPERTWEET_API='http://openapi.cascaad.com/1/supertweet/show.json?api_key=YOURAPIKEY&domain=twitter.com&message=%s'
TWEET_API = 'http://api.twitter.com/1/statuses/user_timeline.json?id=%s'
USERID = sys.argv[1]

timeline = lambda uid: simplejson.load(urllib2.urlopen(TWEET_API%uid))
rank = lambda mids: simplejson.load(urllib2.urlopen(SUPERTWEET_API % ",".join(mids)))


ranked_messages = [(rm['supertweet']['context']['social_rank'], rm['supertweet']['tweet_text_body']) for rm in rank(str(msg['id']) for msg in timeline(USERID))]

for rm in reversed(sorted(ranked_messages)):
  print rm

The usage is pretty straightforward, just launch it with the given user as argument and it will report the score for the messages known to the system (in this beta phase we do not yet process all the twitter messages thar fall below a set relevance threshold)

$ python cascaad.py rww
(10.36374, u'Google Acquires Online Photo Editor Picnik http://bit.ly/bW8fhK')
(7.86374, u'Chrome Beta Auto-Translates, Offers Privacy Settings http://bit.ly/dcUvHr')
(7.86374, u'"This ban was simply based on an obstinate bureaucratic mindset." - Comment on DoD decision to allow social websites. http://bit.ly/aW53CB')
(7.36374, u'HootSuite Mobile Gets Ads with 140 Proof http://bit.ly/ahwvoy')
(1.0, u'One benefit of pics + audio? Lower bandwidth consumption than video, says Fotobabble CEO in comments here: http://bit.ly/8ZmPO1')
(0.5, u'Watch Out, iPhone Devs: One-Man Android App Nets $13K Monthly http://bit.ly/91q2jf')
(0.0, u'Weekly Poll: What is the Top Threat to Cloud Computing? http://bit.ly/dhH3Pq')