|
|
@@ -7,7 +7,8 @@ module Agents
|
7
|
7
|
description <<-MD
|
8
|
8
|
The TwitterPublishAgent publishes tweets from the events it receives.
|
9
|
9
|
|
10
|
|
- You must set up a Twitter app and provide it's `consumer_key`, `consumer_secret`, `oauth_token` and `oauth_token_secret`, (Also shown as "Access token" on the Twitter developer's site.) along with the `username` of the Twitter user to publish as.
|
|
10
|
+ You must set up a Twitter app and provide it's `consumer_key`, `consumer_secret`, `oauth_token` and `oauth_token_secret`,
|
|
11
|
+ (Also shown as "Access token" on the Twitter developer's site.) along with the `username` of the Twitter user to publish as.
|
11
|
12
|
|
12
|
13
|
The `oauth_token` and `oauth_token_secret` specified determine which user the tweet will be sent as.
|
13
|
14
|
|
|
|
@@ -17,7 +18,12 @@ module Agents
|
17
|
18
|
MD
|
18
|
19
|
|
19
|
20
|
def validate_options
|
20
|
|
- unless options[:username].present? && options[:expected_update_period_in_days].present? && options[:consumer_key].present? && options[:consumer_secret].present? && options[:oauth_token].present? && options[:oauth_token_secret].present?
|
|
21
|
+ unless options[:username].present? &&
|
|
22
|
+ options[:expected_update_period_in_days].present? &&
|
|
23
|
+ options[:consumer_key].present? &&
|
|
24
|
+ options[:consumer_secret].present? &&
|
|
25
|
+ options[:oauth_token].present? &&
|
|
26
|
+ options[:oauth_token_secret].present?
|
21
|
27
|
errors.add(:base, "expected_update_period_in_days, username, consumer_key, consumer_secret, oauth_token and oauth_token_secret are required")
|
22
|
28
|
end
|
23
|
29
|
end
|
|
|
@@ -47,9 +53,20 @@ module Agents
|
47
|
53
|
tweet_text = Utils.value_at(event.payload, options[:message_path])
|
48
|
54
|
begin
|
49
|
55
|
publish_tweet tweet_text
|
50
|
|
- create_event :payload => {:success => true, :published_tweet => tweet_text, :agent_id => event.agent_id, :event_id => event.id}
|
|
56
|
+ create_event :payload => {
|
|
57
|
+ :success => true,
|
|
58
|
+ :published_tweet => tweet_text,
|
|
59
|
+ :agent_id => event.agent_id,
|
|
60
|
+ :event_id => event.id
|
|
61
|
+ }
|
51
|
62
|
rescue Twitter::Error => e
|
52
|
|
- create_event :payload => {:success => false, :error => e.message, :failed_tweet => tweet_text, :agent_id => event.agent_id, :event_id => event.id}
|
|
63
|
+ create_event :payload => {
|
|
64
|
+ :success => false,
|
|
65
|
+ :error => e.message,
|
|
66
|
+ :failed_tweet => tweet_text,
|
|
67
|
+ :agent_id => event.agent_id,
|
|
68
|
+ :event_id => event.id
|
|
69
|
+ }
|
53
|
70
|
end
|
54
|
71
|
end
|
55
|
72
|
end
|