Ruby: Event Machine Tweetstream and Fibers -


im have trying play around tweetstream gem access twitter's streaming api fetch tweets , save tweets in database.

i have been trying use eventmachine along ruby fibers first time speed tweet insertion

i not sure if way have used ruby fibers along event machine done in right way. need , suggestions telling me if ruby fibers , event machine implementation correct.

just note tweetstream api configuration has been written in initializer , working expected. need @ implementation , tell me if can improved.

require 'rubygems' require 'tweetstream'  require 'eventmachine' require 'fiber'  class tweetlocator     #get tweets     def self.fetch_and_save_tweets         eventmachine.run #using eventmachine on tweet insert              client = tweetstream::client.new                 @tweet_fibers = [fiber.current]              client.locations(-180, -90, 180, 90) |tweet|                 @tweet_fibers << fiber.new                     self.save_tweet_to_db(tweet)                 end                 @tweet_fibers.last.resume             end         end #end of eventmachine run     end      #save tweet     def self.save_tweet_to_db(tweet)         if tweet['geo']             tweet.create!({                 location: tweet['geo']['coordinates'],                 status: tweet['text'],                 profile_pic_url:  tweet['user']['profile_image_url'],                 user_handle: tweet['user']['screen_name']             })         end      end end 


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -