16
17
18
19
20
21
22
23
24
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
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/twterm/streaming_client.rb', line 16
def connect_user_stream
return if user_stream_connected?
@streaming_thread = Thread.new do
begin
publish(Event::Notification::Info.new('Trying to connect to Twitter...'))
streaming_client.user do |event|
keep_alive!
case event
when ::
status = status_repository.create(event)
publish(Event::Status::Timeline.new(status))
publish(Event::Status::Mention.new(status)) if status.text.include?('@%s' % screen_name)
when ::Streaming::Event
case event.name
when :favorite
user = user_repository.create(event.source)
status = status_repository.create(event.target_object)
event = Event::Favorite.new(user, status, self)
publish(event)
when :follow
source = user_repository.create(event.source)
target = user_repository.create(event.target)
event = Event::Follow.new(source, target, self)
publish(event)
end
when ::DirectMessage
when ::Streaming::FriendList
user_stream_connected!
when ::Streaming::
publish(Event::Status::Delete.new(event.id))
end
end
rescue ::Error::TooManyRequests
publish(Event::Notification::Error.new('Rate limit exceeded'))
sleep 120
retry
rescue Errno::ENETUNREACH, Errno::ETIMEDOUT, Resolv::ResolvError
publish(Event::Notification::Error.new('Network is unavailable'))
sleep 30
retry
rescue ::Error => e
publish(Event::Notification::Error.new(e.message))
end
end
end
|