Class: Twitterland::BackTweets

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/twitterland/back_tweets.rb

Defined Under Namespace

Classes: Unauthenticated

Class Method Summary collapse

Class Method Details

.rubyize_response(response) ⇒ Object

Scrubs the response from Back Tweets to rubyize keys



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twitterland/back_tweets.rb', line 19

def self.rubyize_response(response)
  results = Hashie::Mash.new
  raise BackTweets::Unauthenticated.new if response.has_key?('error')
  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 = Hashie::Mash.new
    tweet.each do |key, value|
      new_tweet[key.to_s.gsub('tweet_', '')] = value
    end
    new_tweet
  end
  results
end

.search(q, api_key, options = {}) ⇒ Object

Return tweet referencing a URL Get your api_key at www.backtype.com/developers

Twitterland::BackTweets.search('http://squeejee.com', 'OU812')


12
13
14
15
# File 'lib/twitterland/back_tweets.rb', line 12

def self.search(q, api_key, options={})
  options['itemsperpage'] = options.delete(:items_per_page) if options[:items_per_page]
  rubyize_response(Hashie::Mash.new(get("/search.json", :query => {:q => q, :key => api_key}.merge(options))))
end