lib/chatterbot/client.rb in chatterbot-0.7.1 vs lib/chatterbot/client.rb in chatterbot-0.9.0
- old
+ new
@@ -4,43 +4,38 @@
#
# routines for connecting to Twitter and validating the bot
#
module Client
- attr_accessor :screen_name, :client, :search_client
+ attr_accessor :screen_name, :client, :streaming_client, :search_client
#
# the main interface to the Twitter API
#
def client
- @client ||= Twitter::Client.new(
- :endpoint => base_url,
- :consumer_key => client_params[:consumer_key],
- :consumer_secret => client_params[:consumer_secret],
- :oauth_token => client_params[:token],
- :oauth_token_secret => client_params[:secret]
- )
+ @client ||= Twitter::REST::Client.new(
+ :consumer_key => client_params[:consumer_key],
+ :consumer_secret => client_params[:consumer_secret],
+ :access_token => client_params[:token],
+ :access_token_secret => client_params[:secret]
+ )
end
- #
- # client for running searches -- for some reason Twitter::Client was overwriting
- # the endpoint for searches in a destructive fashion, so I had two
- # clients. That appears to be fixed, but if not, this takes care of that problem
- #
- def search_client
- client
- # return client
-
- # @search_client ||= Twitter::Client.new(
- # :endpoint => base_url,
- # :consumer_key => client_params[:consumer_key],
- # :consumer_secret => client_params[:consumer_secret],
- # :oauth_token => client_params[:token],
- # :oauth_token_secret => client_params[:secret]
- # )
+ def streaming_client
+ @streaming_client ||= Twitter::Streaming::Client.new(
+ :consumer_key => client_params[:consumer_key],
+ :consumer_secret => client_params[:consumer_secret],
+ :access_token => client_params[:token],
+ :access_token_secret => client_params[:secret]
+ )
end
+ def reset!
+ config[:since_id] = 0
+ config[:since_id_reply] = 0
+ end
+
#
# reset the since_id for this bot to the highest since_id we can
# get, by running a really open search and updating config with
# the max_id
#
@@ -53,11 +48,11 @@
#
# resets the since_id_reply for this bot to the last mention received
#
def reset_since_id_reply
config[:tmp_since_id_reply] = 0
- result = client.mentions.max_by(&:id)
+ result = client.mentions_timeline.max_by(&:id)
update_since_id_reply(result)
end
#
@@ -177,10 +172,10 @@
update_config unless ! do_update_config
reset_client
rescue OAuth::Unauthorized => e
display_oauth_error
- puts e.inspect
+ warn e.inspect
return false
end
end
return true