Replaced group attribute with group_id since names can change.
This commit is contained in:
parent
5a28d2a47a
commit
f259dd3459
4 changed files with 20 additions and 20 deletions
|
@ -44,24 +44,24 @@ Example:
|
||||||
{
|
{
|
||||||
"item":"#otrs",
|
"item":"#otrs",
|
||||||
"type": "mixed", # optional, possible 'mixed' (default), 'recent', 'popular'
|
"type": "mixed", # optional, possible 'mixed' (default), 'recent', 'popular'
|
||||||
"group": "OTRS",
|
"group_id:": 1,
|
||||||
"limit": 1, # optional
|
"limit": 1, # optional
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"item":"#zombie23",
|
"item":"#zombie23",
|
||||||
"group": "Zombie Apocalypse Early Warning System",
|
"group_id:": 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"item":"#otterhub",
|
"item":"#otterhub",
|
||||||
"group": "Community",
|
"group_id:": 3,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"mentions" {
|
"mentions" {
|
||||||
"group": "Twitter",
|
"group_id:": 4,
|
||||||
"limit": 100, # optional
|
"limit": 100, # optional
|
||||||
},
|
},
|
||||||
"direct_messages": {
|
"direct_messages": {
|
||||||
"group": "Twitter",
|
"group_id:": 4,
|
||||||
"limit": 1, # optional
|
"limit": 1, # optional
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Channel::Twitter
|
||||||
@tweet = Tweet.new( @channel[:options][:auth] )
|
@tweet = Tweet.new( @channel[:options][:auth] )
|
||||||
@sync = @channel[:options][:sync]
|
@sync = @channel[:options][:sync]
|
||||||
|
|
||||||
Rails.logger.debug "twitter fetch started"
|
Rails.logger.debug 'twitter fetch started'
|
||||||
|
|
||||||
fetch_search
|
fetch_search
|
||||||
fetch_mentions
|
fetch_mentions
|
||||||
|
@ -55,7 +55,7 @@ class Channel::Twitter
|
||||||
break if search[:limit] && search[:limit] <= counter
|
break if search[:limit] && search[:limit] <= counter
|
||||||
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||||
|
|
||||||
@tweet.to_group( tweet, search[:group] )
|
@tweet.to_group( tweet, search[:group_id] )
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class Channel::Twitter
|
||||||
break if @sync[:mentions][:limit] && @sync[:mentions][:limit] <= counter
|
break if @sync[:mentions][:limit] && @sync[:mentions][:limit] <= counter
|
||||||
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||||
|
|
||||||
@tweet.to_group( tweet, @sync[:mentions][:group] )
|
@tweet.to_group( tweet, @sync[:mentions][:group_id] )
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class Channel::Twitter
|
||||||
break if @sync[:direct_messages][:limit] && @sync[:direct_messages][:limit] <= counter
|
break if @sync[:direct_messages][:limit] && @sync[:direct_messages][:limit] <= counter
|
||||||
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
break if Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||||
|
|
||||||
@tweet.to_group( tweet, @sync[:direct_messages][:group] )
|
@tweet.to_group( tweet, @sync[:direct_messages][:group_id] )
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
}
|
}
|
||||||
|
|
12
lib/tweet.rb
12
lib/tweet.rb
|
@ -90,12 +90,12 @@ class Tweet
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_ticket(tweet, user, group)
|
def to_ticket(tweet, user, group_id)
|
||||||
|
|
||||||
Rails.logger.debug "Create ticket from tweet..."
|
Rails.logger.debug "Create ticket from tweet..."
|
||||||
Rails.logger.debug tweet.inspect
|
Rails.logger.debug tweet.inspect
|
||||||
Rails.logger.debug user.inspect
|
Rails.logger.debug user.inspect
|
||||||
Rails.logger.debug group.inspect
|
Rails.logger.debug group_id.inspect
|
||||||
|
|
||||||
if tweet.class.to_s == 'Twitter::DirectMessage'
|
if tweet.class.to_s == 'Twitter::DirectMessage'
|
||||||
ticket = Ticket.find_by(
|
ticket = Ticket.find_by(
|
||||||
|
@ -112,7 +112,7 @@ class Tweet
|
||||||
Ticket.create(
|
Ticket.create(
|
||||||
customer_id: user.id,
|
customer_id: user.id,
|
||||||
title: "#{tweet.text[0, 37]}...",
|
title: "#{tweet.text[0, 37]}...",
|
||||||
group: Group.find_by( name: group ),
|
group_id: group_id,
|
||||||
state: Ticket::State.find_by( name: 'new' ),
|
state: Ticket::State.find_by( name: 'new' ),
|
||||||
priority: Ticket::Priority.find_by( name: '2 normal' ),
|
priority: Ticket::Priority.find_by( name: '2 normal' ),
|
||||||
)
|
)
|
||||||
|
@ -154,7 +154,7 @@ class Tweet
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_group(tweet, group)
|
def to_group(tweet, group_id)
|
||||||
|
|
||||||
Rails.logger.debug 'import tweet'
|
Rails.logger.debug 'import tweet'
|
||||||
|
|
||||||
|
@ -178,10 +178,10 @@ class Tweet
|
||||||
Rails.logger.debug 'import in_reply_tweet ' + tweet.in_reply_to_status_id.to_s
|
Rails.logger.debug 'import in_reply_tweet ' + tweet.in_reply_to_status_id.to_s
|
||||||
|
|
||||||
parent_tweet = @client.status( tweet.in_reply_to_status_id )
|
parent_tweet = @client.status( tweet.in_reply_to_status_id )
|
||||||
ticket = to_group( parent_tweet, group )
|
ticket = to_group( parent_tweet, group_id )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ticket = to_ticket(tweet, user, group)
|
ticket = to_ticket(tweet, user, group_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
to_article(tweet, user, ticket)
|
to_article(tweet, user, ticket)
|
||||||
|
|
|
@ -45,18 +45,18 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
search: [
|
search: [
|
||||||
{
|
{
|
||||||
term: '#citheo42',
|
term: '#citheo42',
|
||||||
group: 'Twitter',
|
group_id: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
term: '#citheo24',
|
term: '#citheo24',
|
||||||
group: 'Users',
|
group_id: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
mentions: {
|
mentions: {
|
||||||
group: 'Twitter',
|
group_id: 2,
|
||||||
},
|
},
|
||||||
direct_messages: {
|
direct_messages: {
|
||||||
group: 'Twitter',
|
group_id: 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,7 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
ticket = Ticket.create(
|
ticket = Ticket.create(
|
||||||
title: text[0, 40],
|
title: text[0, 40],
|
||||||
customer_id: user.id,
|
customer_id: user.id,
|
||||||
group: Group.find_by( name: 'Twitter' ),
|
group_id: 2,
|
||||||
state: Ticket::State.find_by( name: 'new' ),
|
state: Ticket::State.find_by( name: 'new' ),
|
||||||
priority: Ticket::Priority.find_by( name: '2 normal' ),
|
priority: Ticket::Priority.find_by( name: '2 normal' ),
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
|
|
Loading…
Reference in a new issue