Updated to new twitter lib.

This commit is contained in:
Martin Edenhofer 2013-11-19 10:05:40 +01:00
parent 14ae7b73b9
commit b9dc843101
2 changed files with 28 additions and 28 deletions

View file

@ -4,12 +4,12 @@ require 'twitter'
class Channel::Twitter2 class Channel::Twitter2
def connect(channel) def connect(channel)
@client = Twitter::Client.new( @client = Twitter::REST::Client.new do |config|
:consumer_key => channel[:options][:consumer_key], config.consumer_key = channel[:options][:consumer_key]
:consumer_secret => channel[:options][:consumer_secret], config.consumer_secret = channel[:options][:consumer_secret]
:oauth_token => channel[:options][:oauth_token], config.access_token = channel[:options][:oauth_token]
:oauth_token_secret => channel[:options][:oauth_token_secret] config.access_token_secret = channel[:options][:oauth_token_secret]
) end
end end
def fetch (channel) def fetch (channel)
@ -265,15 +265,15 @@ class Channel::Twitter2
# logger.debug('tweeeeettttt!!!!!!') # logger.debug('tweeeeettttt!!!!!!')
channel = Channel.where( :area => 'Twitter::Inbound', :active => true ).first channel = Channel.where( :area => 'Twitter::Inbound', :active => true ).first
client = Twitter::Client.new( client = Twitter::REST::Client.new do |config|
:consumer_key => channel[:options][:consumer_key], config.consumer_key = channel[:options][:consumer_key]
:consumer_secret => channel[:options][:consumer_secret], config.consumer_secret = channel[:options][:consumer_secret]
:oauth_token => channel[:options][:oauth_token], config.access_token = channel[:options][:oauth_token]
:oauth_token_secret => channel[:options][:oauth_token_secret] config.access_token_secret = channel[:options][:oauth_token_secret]
) end
if attr[:type] == 'twitter direct-message' if attr[:type] == 'twitter direct-message'
puts 'to:' + attr[:to].to_s puts 'to:' + attr[:to].to_s
dm = client.direct_message_create( dm = client.create_direct_message(
attr[:to].to_s, attr[:to].to_s,
attr[:body].to_s, attr[:body].to_s,
{} {}

View file

@ -85,12 +85,12 @@ class TwitterTest < ActiveSupport::TestCase
sleep 10 sleep 10
# reply by me_bauer # reply by me_bauer
client = Twitter::Client.new( client = Twitter::REST::Client.new do |config|
:consumer_key => consumer_key, config.consumer_key = consumer_key
:consumer_secret => consumer_secret, config.consumer_secret = consumer_secret
:oauth_token => user2_token, config.access_token = user2_token
:oauth_token_secret => user2_token_secret config.access_token_secret = user2_token_secret
) end
tweets = client.search( hash ) tweets = client.search( hash )
tweets.results.map do |tweet| tweets.results.map do |tweet|
assert_equal( tweet.id, article.message_id ) assert_equal( tweet.id, article.message_id )
@ -119,19 +119,19 @@ class TwitterTest < ActiveSupport::TestCase
test 'new by direct message inbound' do test 'new by direct message inbound' do
# cleanup direct messages of system # cleanup direct messages of system
client = Twitter::Client.new( client = Twitter::REST::Client.new do |config|
:consumer_key => consumer_key, config.consumer_key = consumer_key
:consumer_secret => consumer_secret, config.consumer_secret = consumer_secret
:oauth_token => user1_token, config.access_token = user1_token
:oauth_token_secret => user1_token_secret config.access_token_secret = user1_token_secret
) end
dms = client.direct_messages( :count => 200 ) dms = client.direct_messages( :count => 200 )
dms.each {|dm| dms.each {|dm|
client.direct_message_destroy(dm.id) client.direct_message_destroy(dm.id)
} }
# direct message to @armin_theo # direct message to @armin_theo
client = Twitter::Client.new( client = Twitter::REST::Client.new(
:consumer_key => consumer_key, :consumer_key => consumer_key,
:consumer_secret => consumer_secret, :consumer_secret => consumer_secret,
:oauth_token => user2_token, :oauth_token => user2_token,