29Apr/090
Fetching Local Tweets in Ruby

Tests take forever because of all the HTTPRequests
Four thumbs up
Next phase I'd like to set up a little web interface showing tweets and tweeters. There's something funny about hitting the internet to find out what's going on around you.
Here's the class, as you can see there are a few overridable defaults
require 'rubygems'
require 'geocoder'
require 'twitter_search'
class Twitter_Interface
attr_accessor :tpp, :distance
attr_reader :address, :geocode
attr :geocoder, :client
def initialize addr = "", dist = "2mi", pp = 15
@client = TwitterSearch::Client.new
@tpp = pp
@distance = dist
@geocoder = initialize_geocoder
set_location addr
end
# Could also use Yahoo API, but it requires API key.
def initialize_geocoder geocoder = Geocoder::GeoCoderUs.new
geocoder
end
def format_geocode geocode = @geocode
if is_geocode? geocode
return "#{geocode.latitude},#{geocode.longitude},#{@distance}"
end
""
end
def tweets
@client.query :geocode => format_geocode, :tpp => @tpp
end
def address_to_geocode addr = @address
if addr == ""
return ""
end
@geocoder.geocode addr
end
def is_geocode? geocode
geocode.respond_to? "success?" and geocode.success?
end
def set_location addr
@address = addr
@geocode = address_to_geocode @address
end
end
And here's how you use it
t = Twitter_Interface.new "1600 pennsylvania ave nw washington dc" #print the twitter query formatted geocode, default distance is 2 miles puts t.format_geocode #=>"38.898748,-77.037684,2mi" #fetch the Twitter_Search::Tweets within 2 miles of the white house! tweets = t.tweets
Download a .zip of the code / tests
Tagged as: geocode, ruby, tdd, twitter
No Comments
THEjoezack: Interesting thoughts on the future of human interaction: http://t.co/yOGf9V99
3:16 AM Nov 09, 2011,
comment
THEjoezack: RT @RWW: Developers: Your Google Maps API Free Riding Days Are Over http://t.co/2ZKHbYkG
9:51 AM Oct 27, 2011,
comment
THEjoezack: RT @bryanfischer: If you play board games, retweet this. I'm experimenting with something. Thanks for your help! #boardgames
3:10 AM Oct 27, 2011,
comment
THEjoezack: RT @jkordyback: Don't buy chocolates for QA people. The selection is never good enough.
1:41 AM Oct 26, 2011,
comment
THEjoezack: Finally started using #instapaper, I didn't think I'd use it but it's changed the way I browse..just like everyone told me :)
1:00 AM Oct 25, 2011,
comment
THEjoezack: The New Toolkit - zachwill: Interesting http://t.co/eEPin8Ca
9:38 PM Oct 22, 2011,
comment
Pages
Recent Comments
- Guesk on Populating Select Boxes with Prototype
- Stefano P on MySQL Capitalize Function
- Hunter Monk on MySQL Capitalize Function
- Fergie Meek on Eclipse RDS Problem: Contacting Server…
- dil bert on Scraping and Saving Flickr Images with Ruby
Categories
- browsers (2)
- code (111)
- gaming (3)
- hobbies (1)
- ide (8)
- internets (1)
- music (2)
- off topic (10)
- photography (15)
- programming (9)
- Projects (17)
- social media (3)
- ubuntu (3)
- wedding (3)
Tags
.net
actionscript
biking
bolt
bookmarklets
c#
cards
cfeclipse
chatter
chrome
clipboard utility
coldbox
coldfusion
css
eclipse
flex
game of life
game programming
gaming
gd2
geohashing
gosu
hpricot
java
javascript
mxunit
mysql
npr api
pics
problems
programming music
project euler
Projects
prototype
PS3
puzzles
regex
resolutions
ruby
scriptaculous
tdd
tools
twitter
ubuntu
vacation



























