Twitter4R on Rails

July 26th, 2007 by comment mbbx6spp

Last night Twitter4R version 0.2.4 was released with a fix that makes using Twitter4R in Rails much easier.

So let’s quickly kick the tires to see how this all works:

  1. Install the Twitter4R v0.2.4 (or above) Ruby Gem: sudo gem install twitter4r
  2. Create a new rails application: rails twitter4rails
  3. After setting up your config/database.yml to your personal tastes and tweaking the Rails configuration settings in environment.rb, scroll to the bottom of environment.rb and add the following:

    gem(’twitter4r’, ‘>=0.2.4′)
    require(’twitter’) # loads core library
    require(’twitter/console’) # loads a helper method we will use
    require(’twitter/rails’) # added Rails extensions for Twitter4R

    module YourAppNamespace
    ENV["RAILS_ENV"] ||= “test” # assume test environment if no RAILS_ENV set.
    ClientContext = Twitter::Client.from_config(”#{RAILS_ROOT}/config/twitter.yml”, ENV["RAILS_ENV"])
    end

  4. Now in your controllers you can access YourAppNamespace::ClientContext object as you need to or any other part of the Twitter4R API.

If you still want more, feel free to check out the following links:

Comments

7 Responses to “Twitter4R on Rails”

  1. Nola says:


    Cool beans — would like to see the high res video, although this one got the point across for me. :)

  2. Desi says:


    Thanks!

  3. S. Potter says:


    Actually I realized that YouTube automatically downgrades the resolution of videos quite drastically during the upload process. Google Video is also quite low res (though slightly better). Anyone know a better venue for higher res videos?

  4. Carmelyne Thompson says:


    Unfortunately, neither of the free vid hosts serve good quality vids. The options are to host the vid on your server and distribute it via iTunes or as a downloadable vid file.

  5. Desi says:


    Susan, we can find a place to host it either on one of my servers or on one of the devChix servers just ping me on the list and we will find a place to put it.
    Desi

  6. S. Potter says:


    Desi: Thanks, but to be honest I have tons of bandwidth sitting in one of my plans that needs to be used, plus I doubt this screencast will be in overly high demand anyway.

    Carmelyne: Thanks for the information on iTunes, I’ll look into it. I’ll post relevant links here later today with the downloadable file URL and/or iTunes URL for the higher res video.

  7. S. Potter says:


    I kept forgetting to post the download URL:
    http://twitter4r.rubyforge.org/screencasts/twitter4r_on_rails.mp4

    Unfortunately I didn’t have time to find out where to configure an iTunes podcast for it as a web front-end didn’t seem easy to find.

Got something to say?