Moved to method api.
This commit is contained in:
parent
449ddf5b07
commit
ae203f542a
2 changed files with 18 additions and 20 deletions
|
@ -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,
|
||||||
|
|
|
@ -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|
|
||||||
|
|
Loading…
Reference in a new issue