Class: StreamingHandler
- Inherits:
-
Object
- Object
- StreamingHandler
- Defined in:
- lib/chatterbot/streaming_handler.rb
Instance Attribute Summary collapse
-
#delete_handler ⇒ Object
readonly
Returns the value of attribute delete_handler.
-
#dm_handler ⇒ Object
readonly
Returns the value of attribute dm_handler.
-
#favorite_handler ⇒ Object
readonly
Returns the value of attribute favorite_handler.
-
#follow_handler ⇒ Object
readonly
Returns the value of attribute follow_handler.
-
#friends_handler ⇒ Object
readonly
Returns the value of attribute friends_handler.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#search_filter ⇒ Object
readonly
Returns the value of attribute search_filter.
-
#tweet_handler ⇒ Object
readonly
Returns the value of attribute tweet_handler.
Instance Method Summary collapse
- #apply(block) ⇒ Object
- #apply_main_block(&block) ⇒ Object
- #bot ⇒ Object
- #config ⇒ Object
- #connection_params ⇒ Object
- #delete(&block) ⇒ Object
- #direct_message(&block) ⇒ Object
-
#endpoint ⇒ Object
filter, firehose, sample, user.
- #favorited(&block) ⇒ Object
- #followed(&block) ⇒ Object
- #friends(&block) ⇒ Object
-
#initialize(bot, opts = {}) ⇒ StreamingHandler
constructor
A new instance of StreamingHandler.
- #search(query, opts = {}, &block) ⇒ Object
- #user(&block) ⇒ Object (also: #replies, #timeline, #sample, #filter)
Constructor Details
#initialize(bot, opts = {}) ⇒ StreamingHandler
Returns a new instance of StreamingHandler.
13 14 15 16 |
# File 'lib/chatterbot/streaming_handler.rb', line 13 def initialize(bot, opts = {}) @bot = bot @opts = opts end |
Instance Attribute Details
#delete_handler ⇒ Object (readonly)
Returns the value of attribute delete_handler.
7 8 9 |
# File 'lib/chatterbot/streaming_handler.rb', line 7 def delete_handler @delete_handler end |
#dm_handler ⇒ Object (readonly)
Returns the value of attribute dm_handler.
5 6 7 |
# File 'lib/chatterbot/streaming_handler.rb', line 5 def dm_handler @dm_handler end |
#favorite_handler ⇒ Object (readonly)
Returns the value of attribute favorite_handler.
4 5 6 |
# File 'lib/chatterbot/streaming_handler.rb', line 4 def favorite_handler @favorite_handler end |
#follow_handler ⇒ Object (readonly)
Returns the value of attribute follow_handler.
6 7 8 |
# File 'lib/chatterbot/streaming_handler.rb', line 6 def follow_handler @follow_handler end |
#friends_handler ⇒ Object (readonly)
Returns the value of attribute friends_handler.
8 9 10 |
# File 'lib/chatterbot/streaming_handler.rb', line 8 def friends_handler @friends_handler end |
#opts ⇒ Object
Returns the value of attribute opts.
11 12 13 |
# File 'lib/chatterbot/streaming_handler.rb', line 11 def opts @opts end |
#search_filter ⇒ Object (readonly)
Returns the value of attribute search_filter.
9 10 11 |
# File 'lib/chatterbot/streaming_handler.rb', line 9 def search_filter @search_filter end |
#tweet_handler ⇒ Object (readonly)
Returns the value of attribute tweet_handler.
3 4 5 |
# File 'lib/chatterbot/streaming_handler.rb', line 3 def tweet_handler @tweet_handler end |
Instance Method Details
#apply(block) ⇒ Object
93 94 95 |
# File 'lib/chatterbot/streaming_handler.rb', line 93 def apply(block) instance_exec &block end |
#apply_main_block(&block) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/chatterbot/streaming_handler.rb', line 84 def apply_main_block(&block) if !@tweet_handler.nil? warn "WARNING: when using streaming, you may only have one block of user/replies/timeline/sample/filter" raise RuntimeError, 'Unable to load bot' end @tweet_handler = block end |
#bot ⇒ Object
18 19 20 |
# File 'lib/chatterbot/streaming_handler.rb', line 18 def bot @bot end |
#config ⇒ Object
22 23 24 |
# File 'lib/chatterbot/streaming_handler.rb', line 22 def config bot.config end |
#connection_params ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chatterbot/streaming_handler.rb', line 65 def connection_params opts = { #:with => 'followings', #:replies => false, :stall_warnings => false }.merge(@opts) opts.delete(:endpoint) # convert true/false to strings opts.each { |k, v| opts[k] = v.to_s } if @search_filter opts[:track] = @search_filter end opts end |
#delete(&block) ⇒ Object
57 58 59 |
# File 'lib/chatterbot/streaming_handler.rb', line 57 def delete(&block) @delete_handler = block end |
#direct_message(&block) ⇒ Object
49 50 51 |
# File 'lib/chatterbot/streaming_handler.rb', line 49 def (&block) @dm_handler = block end |
#endpoint ⇒ Object
filter, firehose, sample, user
27 28 29 |
# File 'lib/chatterbot/streaming_handler.rb', line 27 def endpoint opts[:endpoint] || :user end |
#favorited(&block) ⇒ Object
45 46 47 |
# File 'lib/chatterbot/streaming_handler.rb', line 45 def favorited(&block) @favorite_handler = block end |
#followed(&block) ⇒ Object
53 54 55 |
# File 'lib/chatterbot/streaming_handler.rb', line 53 def followed(&block) @follow_handler = block end |
#friends(&block) ⇒ Object
61 62 63 |
# File 'lib/chatterbot/streaming_handler.rb', line 61 def friends(&block) @friends_handler = block end |
#search(query, opts = {}, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/chatterbot/streaming_handler.rb', line 31 def search(query, opts = {}, &block) @search_filter = query @search_opts = opts apply_main_block(&block) if block_given? end |
#user(&block) ⇒ Object Also known as: replies, timeline, sample, filter
37 38 39 |
# File 'lib/chatterbot/streaming_handler.rb', line 37 def user(&block) apply_main_block(&block) end |