Fixes to work with new channel options.

This commit is contained in:
Martin Edenhofer 2012-04-18 14:55:48 +02:00
parent 8f2e1516a7
commit 20f2cdfecf
2 changed files with 28 additions and 25 deletions

View file

@ -4,42 +4,45 @@ class Channel::Twitter2
include UserInfo include UserInfo
# def fetch(:oauth_token, :oauth_token_secret) # def fetch(:oauth_token, :oauth_token_secret)
def fetch (account) def fetch (channel)
puts 'fetching tweets' puts "fetching tweets (oauth_token#{channel[:options][:oauth_token]})"
@client = Twitter::Client.new( @client = Twitter::Client.new(
:consumer_key => account[:consumer_key], :consumer_key => channel[:options][:consumer_key],
:consumer_secret => account[:consumer_secret], :consumer_secret => channel[:options][:consumer_secret],
:oauth_token => account[:oauth_token], :oauth_token => channel[:options][:oauth_token],
:oauth_token_secret => account[:oauth_token_secret] :oauth_token_secret => channel[:options][:oauth_token_secret]
) )
# search results # search results
if account[:search] if channel[:options][:search]
account[:search].each { |search| channel[:options][:search].each { |search|
puts " - searching for #{search[:item]}"
tweets = @client.search( search[:item] ) tweets = @client.search( search[:item] )
@article_type = 'twitter status' @article_type = 'twitter status'
fetch_loop(tweets, account, search[:group]) fetch_loop(tweets, channel, search[:group])
} }
end end
# mentions # mentions
if account[:mentions] if channel[:options][:mentions]
puts " - searching for mentions"
tweets = @client.mentions tweets = @client.mentions
@article_type = 'twitter status' @article_type = 'twitter status'
fetch_loop(tweets, account, account[:mentions][:group]) fetch_loop(tweets, channel, channel[:options][:mentions][:group])
end end
# direct messages # direct messages
if account[:direct_messages] if channel[:options][:direct_messages]
puts " - searching for direct_messages"
tweets = @client.direct_messages tweets = @client.direct_messages
@article_type = 'twitter direct-message' @article_type = 'twitter direct-message'
fetch_loop(tweets, account, account[:direct_messages][:group]) fetch_loop(tweets, channel, channel[:options][:direct_messages][:group])
end end
puts 'done' puts 'done'
end end
def fetch_loop(tweets, account, group) def fetch_loop(tweets, channel, group)
# find tweets # find tweets
tweets.each do |tweet| tweets.each do |tweet|
@ -54,7 +57,7 @@ class Channel::Twitter2
# use transaction # use transaction
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
puts 'import tweet' puts 'import tweet'
fetch_import(tweet, account, group) fetch_import(tweet, channel, group)
end end
# execute ticket events # execute ticket events
@ -62,7 +65,7 @@ class Channel::Twitter2
end end
end end
def fetch_import(tweet, account, group) def fetch_import(tweet, channel, group)
# do sender lockup if needed # do sender lockup if needed
sender = nil sender = nil
@ -86,13 +89,13 @@ class Channel::Twitter2
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, account, group) (user, ticket, article) = fetch_import(tweet_sub, channel, group)
end end
# create stuff # create stuff
user = fetch_user_create(tweet, sender) user = fetch_user_create(tweet, sender)
if !ticket if !ticket
ticket = fetch_ticket_create(user, tweet, sender, account, group) ticket = fetch_ticket_create(user, tweet, sender, channel, group)
end end
article = fetch_article_create(user, ticket, tweet, sender) article = fetch_article_create(user, ticket, tweet, sender)
return user, ticket, article return user, ticket, article
@ -139,7 +142,7 @@ class Channel::Twitter2
return user return user
end end
def fetch_ticket_create(user, tweet, sender, account, group) def fetch_ticket_create(user, tweet, sender, channel, group)
puts '+++++++++++++++++++++++++++' + tweet.inspect puts '+++++++++++++++++++++++++++' + tweet.inspect
# check if ticket exists # check if ticket exists
@ -210,13 +213,13 @@ class Channel::Twitter2
end end
def send(atts, account) def send(atts, channel)
# logger.debug('tweeeeettttt!!!!!!') # logger.debug('tweeeeettttt!!!!!!')
@client = Twitter::Client.new( @client = Twitter::Client.new(
:consumer_key => account[:consumer_key], :consumer_key => channel[:options][:consumer_key],
:consumer_secret => account[:consumer_secret], :consumer_secret => channel[:options][:consumer_secret],
:oauth_token => account[:oauth_token], :oauth_token => channel[:options][:oauth_token],
:oauth_token_secret => account[:oauth_token_secret] :oauth_token_secret => channel[:options][:oauth_token_secret]
) )
puts 'to:' + atts[:to].to_s puts 'to:' + atts[:to].to_s
if atts[:type] == 'twitter direct-message' then if atts[:type] == 'twitter direct-message' then

View file

@ -1379,7 +1379,7 @@ Channel.create(
Channel.create( Channel.create(
:adapter => 'Twitter2', :adapter => 'Twitter2',
:area => 'Twitter', :area => 'Twitter::Inbound',
:options => { :options => {
:consumer_key => 'PJ4c3dYYRtSZZZdOKo8ow', :consumer_key => 'PJ4c3dYYRtSZZZdOKo8ow',
:consumer_secret => 'ggAdnJE2Al1Vv0cwwvX5bdvKOieFs0vjCIh5M8Dxk', :consumer_secret => 'ggAdnJE2Al1Vv0cwwvX5bdvKOieFs0vjCIh5M8Dxk',