From ae203f542a61c0bc2ea3080489d2a53e3845e656 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 27 May 2014 14:01:25 +0200 Subject: [PATCH] Moved to method api. --- app/models/channel/twitter2.rb | 28 +++++++++++++--------------- test/unit/twitter_test.rb | 10 +++++----- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/models/channel/twitter2.rb b/app/models/channel/twitter2.rb index 3c5da40f1..2c0b08ef6 100644 --- a/app/models/channel/twitter2.rb +++ b/app/models/channel/twitter2.rb @@ -93,19 +93,16 @@ class Channel::Twitter2 sender = nil # status (full user data is included) - if tweet.user + if tweet.respond_to?('user') sender = tweet.user - # direct message (full user data is included) - elsif tweet['sender'] - sender = tweet['sender'] + # direct message (full user data is included) + elsif tweet.respond_to?('sender') + sender = tweet.sender - # search (no user data is included, do extra lookup) - elsif tweet['from_user_id'] + # search (no user data is included, do extra lookup) + elsif tweet.respond_to?('from_user_id') begin - - # reconnect for # workaround - # @client = connect(channel) sender = @client.user(tweet.from_user_id) rescue Exception => e puts "Exception: twitter: " + e.inspect @@ -115,9 +112,9 @@ class Channel::Twitter2 # check if parent exists user = nil, ticket = nil, article = nil - if tweet.in_reply_to_status_id + if tweet.respond_to?('in_reply_to_status_id') && tweet.in_reply_to_status_id puts 'import in_reply_tweet ' + tweet.in_reply_to_status_id.to_s - tweet_sub = @client.status(tweet.in_reply_to_status_id) + tweet_sub = @client.status( tweet.in_reply_to_status_id ) # puts tweet_sub.inspect (user, ticket, article) = fetch_import(tweet_sub, channel, group) end @@ -179,11 +176,11 @@ class Channel::Twitter2 # puts '+++++++++++++++++++++++++++' + tweet.inspect # check if ticket exists - if tweet.in_reply_to_status_id - puts 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id + if tweet.respond_to?('in_reply_to_status_id') && tweet.in_reply_to_status_id + puts 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s article = Ticket::Article.where( :message_id => tweet.in_reply_to_status_id.to_s ).first if article - puts 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id + puts 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s return article.ticket end end @@ -246,9 +243,10 @@ class Channel::Twitter2 # import tweet to = nil - if tweet.recipient + if tweet.respond_to?('recipient') to = tweet.recipient.name end + article = Ticket::Article.create( :ticket_id => ticket.id, :ticket_article_type_id => Ticket::Article::Type.where( :name => @article_type ).first.id, diff --git a/test/unit/twitter_test.rb b/test/unit/twitter_test.rb index 05ab01b9a..0eadc4f4b 100644 --- a/test/unit/twitter_test.rb +++ b/test/unit/twitter_test.rb @@ -10,7 +10,7 @@ class TwitterTest < ActiveSupport::TestCase # user1: armin_theo (is system and is following marion_bauer) user1_token = '1405469528-WQ6XHizgrbYasUwjp0I0TUONhftNkrfrpgFLrdc' user1_token_secret = '0LHChGFlQx9jSxM8tkBsuDOMhbJMSXTL2zKJJO5Xk' - + # user2: me_bauer (is following armin_theo) user2_token = '1406098795-XQTjg1Zj5uVW0C11NNpNA4xopyclRJJoriWis0I' user2_token_secret = 'T8ph5afeSDjGDA9X1ZBlzEvoSiXfN266ZZUMj5UaY' @@ -131,10 +131,10 @@ class TwitterTest < ActiveSupport::TestCase # direct message to @armin_theo client = Twitter::REST::Client.new( - :consumer_key => consumer_key, - :consumer_secret => consumer_secret, - :oauth_token => user2_token, - :oauth_token_secret => user2_token_secret + :consumer_key => consumer_key, + :consumer_secret => consumer_secret, + :access_token => user2_token, + :access_token_secret => user2_token_secret ) dms = client.direct_messages( :count => 200 ) dms.each {|dm|