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
# 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 #<Twitter::Error::NotFound: Sorry, that page does not exist> 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,

View file

@ -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|