Class: Akane::Receivers::Stream
Instance Attribute Summary collapse
Instance Method Summary
collapse
#on, #on_delete, #on_event, #on_message, #on_tweet
Constructor Details
#initialize ⇒ Stream
Returns a new instance of Stream.
7
8
9
10
|
# File 'lib/akane/receivers/stream.rb', line 7
def initialize(*)
super
@thread = nil
end
|
Instance Attribute Details
#thread ⇒ Object
Returns the value of attribute thread.
23
24
25
|
# File 'lib/akane/receivers/stream.rb', line 23
def thread
@thread
end
|
Instance Method Details
#running? ⇒ Boolean
12
|
# File 'lib/akane/receivers/stream.rb', line 12
def running?() !!(@thread && @thread.alive?) end
|
#start ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/akane/receivers/stream.rb', line 25
def start
@logger.info "Stream : Starting"
@thread = Thread.new do
begin
stream.user do |obj|
case obj
when ::
invoke(:tweet, obj)
when ::DirectMessage
invoke(:message, obj)
when ::Streaming::
invoke(:delete, obj.user_id, obj.id)
when ::Streaming::Event
invoke(:event,
'event' => obj.name, 'source' => obj.source,
'target' => obj.target, 'target_object' => obj.target_object)
end
end
rescue Exception => e
raise e if defined?(::Streaming::MockClient)
@logger.error 'Error on stream'
@logger.error e.inspect
@logger.error e.backtrace
end
end
self
end
|
#stop ⇒ Object
55
56
57
58
59
|
# File 'lib/akane/receivers/stream.rb', line 55
def stop
@thread.tap(&:kill).join
@thread = nil
self
end
|
#stream ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/akane/receivers/stream.rb', line 14
def stream
@stream ||= ::Streaming::Client.new(
consumer_key: @consumer[:token],
consumer_secret: @consumer[:secret],
access_token: @account[:token],
access_token_secret: @account[:secret]
)
end
|