Sha256: 2ea0fc24783aa130093db83bf39d8ee3c655366f749121588b90107fcaf085e8

Contents?: true

Size: 1010 Bytes

Versions: 8

Compression:

Stored size: 1010 Bytes

Contents

module Twitterland
  class BackTweets
    include HTTParty
    base_uri 'backtweets.com'
    format :json
  
    # Return tweet referencing a URL
    # Get your api_key at http://www.backtype.com/developers
    # 
    #   Twitterland::BackTweets.search('http://squeejee.com', 'OU812')
    def self.search(q, api_key)
      rubyize_response(Mash.new(get("/search.json", :query => {:q => q, :key => api_key})))
    end
    
    
    # Scrubs the response from Back Tweets to rubyize keys
    def self.rubyize_response(response)
      results = Mash.new
      results.total_results = response['totalresults'].to_i
      results.start_index = response['startindex']
      results.items_per_page = response['itemsperpage']
      results.tweets = response['tweets'].map do |tweet|
        new_tweet = Mash.new
        tweet.each do |key, value|
          new_tweet[key.to_s.gsub('tweet_', '')] = value
        end
        new_tweet
      end
      results
    end
    private_class_method :rubyize_response
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
squeejee-twitterland-0.2.0 lib/twitterland/back_tweets.rb
squeejee-twitterland-0.2.1 lib/twitterland/back_tweets.rb
twitterland-0.4.2 lib/twitterland/back_tweets.rb
twitterland-0.4.1 lib/twitterland/back_tweets.rb
twitterland-0.4.0 lib/twitterland/back_tweets.rb
twitterland-0.3.0 lib/twitterland/back_tweets.rb
twitterland-0.2.0 lib/twitterland/back_tweets.rb
twitterland-0.2.1 lib/twitterland/back_tweets.rb