Reputation: 749
I'm learning mongodb with ruby, I write update.rb as follows:
require 'rubygems'
require 'mongo'
require 'twitter'
require File.join(File.dirname(__FILE__), 'config')
class TweetArchiver
def initialize(tag)
connection = Mongo::Connection.new
db = connection[DATABASE_NAME]
@tweets = db[COLLECTION_NAME]
@tweets.create_index([['id', 1]], :unique => true)
@tweets.create_index([['tags', 1], ['id', -1]])
@tag = tag
@tweets_found = 0
end
def update
puts "Starting Twitter search for '#{@tag}'..."
save_tweets_for(@tag)
print "#{@tweets_found} tweets saved.\n\n"
end
private
def save_tweets_for(term)
Twitter.search(term).each do |tweet|
@tweets_found += 1
tweet_with_tag = tweet.to_hash.merge!({"tags" => [term]})
@tweets.save(tweet_with_tag)
end
end
end
I run ruby update.rb, then get error:
undefined method `search' for Twitter:Module (NoMethodError)
Upvotes: 0
Views: 892
Reputation: 176412
The error is quite self-explanatory. The Twitter
module has no search
method defined.
Twitter.search(term).each do |tweet|
You should check the documentation of the library to make sure you are using it in the right way.
Upvotes: 1