Moved to method api.

This commit is contained in:
Martin Edenhofer 2014-05-27 14:01:25 +02:00
parent 449ddf5b07
commit ae203f542a
2 changed files with 18 additions and 20 deletions

View file

@ -93,19 +93,16 @@ class Channel::Twitter2
sender = nil sender = nil
# status (full user data is included) # status (full user data is included)
if tweet.user if tweet.respond_to?('user')
sender = tweet.user sender = tweet.user
# direct message (full user data is included) # direct message (full user data is included)
elsif tweet['sender'] elsif tweet.respond_to?('sender')
sender = tweet['sender'] sender = tweet.sender
# search (no user data is included, do extra lookup) # search (no user data is included, do extra lookup)
elsif tweet['from_user_id'] elsif tweet.respond_to?('from_user_id')
begin begin
# reconnect for #<Twitter::Error::NotFound: Sorry, that page does not exist> workaround
# @client = connect(channel)
sender = @client.user(tweet.from_user_id) sender = @client.user(tweet.from_user_id)
rescue Exception => e rescue Exception => e
puts "Exception: twitter: " + e.inspect puts "Exception: twitter: " + e.inspect
@ -115,9 +112,9 @@ class Channel::Twitter2
# check if parent exists # check if parent exists
user = nil, ticket = nil, article = nil 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 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 # puts tweet_sub.inspect
(user, ticket, article) = fetch_import(tweet_sub, channel, group) (user, ticket, article) = fetch_import(tweet_sub, channel, group)
end end
@ -179,11 +176,11 @@ class Channel::Twitter2
# puts '+++++++++++++++++++++++++++' + tweet.inspect # puts '+++++++++++++++++++++++++++' + tweet.inspect
# check if ticket exists # check if ticket exists
if 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 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 article = Ticket::Article.where( :message_id => tweet.in_reply_to_status_id.to_s ).first
if article 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 return article.ticket
end end
end end
@ -246,9 +243,10 @@ class Channel::Twitter2
# import tweet # import tweet
to = nil to = nil
if tweet.recipient if tweet.respond_to?('recipient')
to = tweet.recipient.name to = tweet.recipient.name
end end
article = Ticket::Article.create( article = Ticket::Article.create(
:ticket_id => ticket.id, :ticket_id => ticket.id,
:ticket_article_type_id => Ticket::Article::Type.where( :name => @article_type ).first.id, :ticket_article_type_id => Ticket::Article::Type.where( :name => @article_type ).first.id,

View file

@ -10,7 +10,7 @@ class TwitterTest < ActiveSupport::TestCase
# user1: armin_theo (is system and is following marion_bauer) # user1: armin_theo (is system and is following marion_bauer)
user1_token = '1405469528-WQ6XHizgrbYasUwjp0I0TUONhftNkrfrpgFLrdc' user1_token = '1405469528-WQ6XHizgrbYasUwjp0I0TUONhftNkrfrpgFLrdc'
user1_token_secret = '0LHChGFlQx9jSxM8tkBsuDOMhbJMSXTL2zKJJO5Xk' user1_token_secret = '0LHChGFlQx9jSxM8tkBsuDOMhbJMSXTL2zKJJO5Xk'
# user2: me_bauer (is following armin_theo) # user2: me_bauer (is following armin_theo)
user2_token = '1406098795-XQTjg1Zj5uVW0C11NNpNA4xopyclRJJoriWis0I' user2_token = '1406098795-XQTjg1Zj5uVW0C11NNpNA4xopyclRJJoriWis0I'
user2_token_secret = 'T8ph5afeSDjGDA9X1ZBlzEvoSiXfN266ZZUMj5UaY' user2_token_secret = 'T8ph5afeSDjGDA9X1ZBlzEvoSiXfN266ZZUMj5UaY'
@ -131,10 +131,10 @@ class TwitterTest < ActiveSupport::TestCase
# direct message to @armin_theo # direct message to @armin_theo
client = Twitter::REST::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, :access_token => user2_token,
:oauth_token_secret => user2_token_secret :access_token_secret => user2_token_secret
) )
dms = client.direct_messages( :count => 200 ) dms = client.direct_messages( :count => 200 )
dms.each {|dm| dms.each {|dm|