Make exclude_replies configurable

Vlad 9 年之前
父节点
当前提交
ca2d2acaec
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12 1
      app/models/agents/twitter_user_agent.rb

+ 12 - 1
app/models/agents/twitter_user_agent.rb

@@ -13,6 +13,8 @@ module Agents
13 13
       You must also provide the `username` of the Twitter user to monitor.
14 14
 
15 15
       Set `include_retweets` to `false` to not include retweets (default: `true`)
16
+      
17
+      Set `exclude_replies` to `true` to exclude replies (default: `false`)
16 18
 
17 19
       Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
18 20
 
@@ -53,6 +55,7 @@ module Agents
53 55
       {
54 56
         'username' => 'tectonic',
55 57
         'include_retweets' => 'true',
58
+        'exclude_replies' => 'false',
56 59
         'expected_update_period_in_days' => '2'
57 60
       }
58 61
     end
@@ -64,6 +67,10 @@ module Agents
64 67
       if options[:include_retweets].present? && !%w[true false].include?(options[:include_retweets])
65 68
         errors.add(:base, "include_retweets must be a boolean value string (true/false)")
66 69
       end
70
+      
71
+      if options[:exclude_replies].present? && !%w[true false].include?(options[:exclude_replies])
72
+        errors.add(:base, "exclude_replies must be a boolean value string (true/false)")
73
+      end
67 74
 
68 75
       if options[:starting_at].present?
69 76
         Time.parse(options[:starting_at]) rescue errors.add(:base, "Error parsing starting_at")
@@ -81,10 +88,14 @@ module Agents
81 88
     def include_retweets?
82 89
       interpolated[:include_retweets] != "false"
83 90
     end
91
+    
92
+    def exclude_replies?
93
+      interpolated[:exclude_replies] != "false"
94
+    end
84 95
 
85 96
     def check
86 97
       since_id = memory['since_id'] || nil
87
-      opts = {:count => 200, :include_rts => include_retweets?, :exclude_replies => false, :include_entities => true, :contributor_details => true}
98
+      opts = {:count => 200, :include_rts => include_retweets?, :exclude_replies => exclude_replies?, :include_entities => true, :contributor_details => true}
88 99
       opts.merge! :since_id => since_id unless since_id.nil?
89 100
 
90 101
       # http://rdoc.info/gems/twitter/Twitter/REST/Timelines#user_timeline-instance_method