lib/rabbit/twitter.rb in rabbit-0.9.3 vs lib/rabbit/twitter.rb in rabbit-1.0.0
- old
+ new
@@ -20,11 +20,17 @@
end
def setup
return unless @oauth_parameters.nil?
require 'yaml'
- require 'twitter_oauth'
+ begin
+ require 'twitter_oauth'
+ rescue LoadError
+ @logger.warn(_("twitter_oauth gem is missing. " \
+ "Install it by 'gem install twitter_oauth'."))
+ return
+ end
setup_access_token unless @config_file_path.exist?
oauth_access_parameters = YAML.load(@config_file_path.read)
@oauth_parameters = {
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
@@ -40,12 +46,20 @@
end
def start(*filters, &block)
register_listener(&block) if block_given?
setup if @oauth_parameters.nil?
+ return if @oauth_parameters.nil?
require 'socket'
- require 'twitter/json_stream'
+ begin
+ require 'twitter/json_stream'
+ rescue LoadError
+ @logger.warn(_("twitter-stream gem is missing. " \
+ "Install it by 'gem install twitter-stream'."))
+ return
+ end
+
stream_options = {
:oauth => @oauth_parameters,
:user_agent => "Rabitter #{Rabbit::VERSION}",
:host => "stream.twitter.com",
:path => "/1/statuses/filter.json",
@@ -113,11 +127,21 @@
end
def connect
close
@socket = TCPSocket.new(@options[:host], "http")
- @channel = GLib::IOChannel.new(@socket.fileno)
- @channel.flags = GLib::IOChannel::FLAG_NONBLOCK
+ if GLib.const_defined?(:IOChannelWin32Socket)
+ @channel = GLib::IOChannelWin32Socket.new(@socket.fileno)
+ else
+ @channel = GLib::IOChannel.new(@socket.fileno)
+ end
+ begin
+ @channel.flags = GLib::IOChannel::FLAG_NONBLOCK
+ rescue GLib::IOChannelError
+ @logger.warn("[twitter][read][error] " +
+ "failed to set non-blocking mode: " +
+ "#{$!.message}(#{$!.class})")
+ end
reader_id = @channel.add_watch(GLib::IOChannel::IN) do |io, condition|
@logger.debug("[twitter][read][start]")
data = io.read(4096)
@logger.debug("[twitter][read][done] #{data.bytesize}")
if data.empty?