ruboty-tweetstream 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82fd6a29c2eb198bc028cdaf0cc7795460543646
4
- data.tar.gz: 0706a612363b5f0f7ae1dab7c8ba818841e2f8da
3
+ metadata.gz: 60de20eb65af9dbc59a729bc31db428057da2af6
4
+ data.tar.gz: 14f205071ce869d0cf2cec8f399f428e6e8d30f7
5
5
  SHA512:
6
- metadata.gz: 2591f7c7baea9dd4fee1ea2b1dbe3f0da0ce41227ca003ab005b8b0ddbf6b01ed65ba632323d249ba9fa793b99fe85e5139673a5a0ff6bc5490a0850db21a859
7
- data.tar.gz: d2f7fb74fbd96ec6e7c7ece17de47dcbc2a17ee1a8a8d7cb55bf26997fdfc9baf20639d3e75db666689558d21e54f9c9bc17e20402ab4d6462116e1986cb98ed
6
+ metadata.gz: 99c38dfcc3152f26807419e29063e2e9a92eda341fad717cc993602a6cfce2303f12a4b9781de640eb235441467dccd2a92ed5efcf13199e6d993e686b5d1228
7
+ data.tar.gz: c40db43353d008dc945017183ca930379131a44c83ef022e51ac1f0cc2b67857ee63a2eb605d15bfc7a8fe57b80462d0b57ae3f8e0278fe0591c929f1c86ea6c
@@ -66,26 +66,26 @@ module Ruboty
66
66
  end
67
67
 
68
68
  def list(message)
69
- sorted_streams = streams.sort_by {|_id, hash| hash[:username]}
70
-
71
- if message[:all_flag]
72
- stream_list = sorted_streams.map do |id, hash|
73
- stream = "#{id}: @#{hash[:username]}"
74
- stream << " (#{hash[:channel]})" unless hash[:channel].nil?
75
- stream
76
- end
77
- else
78
- stream_list = sorted_streams.map { |id, hash|
79
- # Skip the channel that registered from other channel.
80
- next unless hash[:channel] == message.channel
81
-
82
- "#{id}: @#{hash[:username]}"
83
- }.compact
84
- end
85
-
86
- if stream_list.empty?
69
+ if streams.empty?
87
70
  message.reply("The stream doesn't exist.")
88
71
  else
72
+ sorted_streams = streams.sort_by {|_id, hash| hash[:username]}
73
+
74
+ if message[:all_flag]
75
+ stream_list = sorted_streams.map do |id, hash|
76
+ stream = "#{id}: @#{hash[:username]}"
77
+ stream << " (#{hash[:channel]})" unless hash[:channel].nil?
78
+ stream
79
+ end
80
+ else
81
+ stream_list = sorted_streams.map { |id, hash|
82
+ # Skip the channel that registered from other channel.
83
+ next unless hash[:channel] == message.channel
84
+
85
+ "#{id}: @#{hash[:username]}"
86
+ }.compact
87
+ end
88
+
89
89
  message.reply(stream_list.join("\n"), code: true)
90
90
  end
91
91
  end
@@ -10,10 +10,11 @@ end
10
10
  module Ruboty
11
11
  module Tweetstream
12
12
  class Stream
13
- attr_reader :hash, :thread
13
+ attr_reader :hash
14
14
 
15
15
  def initialize(hash)
16
16
  @hash = hash
17
+ @thread = nil
17
18
 
18
19
  @client = Twitter::Streaming::Client.new do |config|
19
20
  config.consumer_key = CONSUMER_KEY
@@ -24,7 +25,7 @@ module Ruboty
24
25
  end
25
26
 
26
27
  def start(robot)
27
- @thread = Thread.start do
28
+ @thread = interval_reconnect do
28
29
  @client.filter(follow: hash[:twitter_id].to_s) do |object|
29
30
  if object.is_a?(Twitter::Tweet) && object.is_pure_user_tweet?(hash[:username])
30
31
  Message.new(
@@ -35,8 +36,23 @@ module Ruboty
35
36
  end
36
37
  end
37
38
 
39
+ # Twitter::Streaming disconnects over time
40
+ def interval_reconnect
41
+ parent = Thread.start do
42
+ loop do
43
+ child = Thread.start do
44
+ yield
45
+ end
46
+ sleep 3600 # Disconnect every hour
47
+ child.kill
48
+ end
49
+ end
50
+
51
+ parent
52
+ end
53
+
38
54
  def stop
39
- thread.kill
55
+ @thread.kill
40
56
  end
41
57
  end
42
58
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Tweetstream
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -22,6 +22,4 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'pry'
26
- spec.add_development_dependency 'awesome_print'
27
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-tweetstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -80,34 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: awesome_print
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
83
  description: Ruboty handler to stream specified user's tweet from Twitter.
112
84
  email:
113
85
  - kaihar4@gmail.com