twterm 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twterm/app.rb +4 -1
- data/lib/twterm/client.rb +5 -3
- data/lib/twterm/notification/base.rb +1 -1
- data/lib/twterm/scheduler.rb +4 -2
- data/lib/twterm/status.rb +20 -8
- data/lib/twterm/tab/statuses_tab.rb +2 -1
- data/lib/twterm/user.rb +33 -6
- data/lib/twterm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47e25077b5997ac024770d29a7faa63b0367d200
|
4
|
+
data.tar.gz: 752e5cc8daf0a00ab054602a2bc1c437f98b80e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40f134f4fd0eeaaed2998883330a9d132b4e99862c0aeebeb2a57326be3c76b08ed2899c83d9366172f82cc8c7b871226e284751645b4bd45df145e9416ac60c
|
7
|
+
data.tar.gz: 7cba404740e73eefec2a29b5c64368d1cfd2882e58e9847c6aae858470bcca7e27c7b9fb7cbcbc588e206c7188df7b3b92fb0dae1ab15c4f27305ffde82057a8
|
data/lib/twterm/app.rb
CHANGED
data/lib/twterm/client.rb
CHANGED
@@ -32,6 +32,10 @@ module Twterm
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def stream
|
35
|
+
@stream_client.on_friends do
|
36
|
+
Notifier.instance.show_message 'Connection established'
|
37
|
+
end
|
38
|
+
|
35
39
|
@stream_client.on_timeline_status do |tweet|
|
36
40
|
status = Status.new(tweet)
|
37
41
|
invoke_callbacks(:timeline_status, status)
|
@@ -57,18 +61,16 @@ module Twterm
|
|
57
61
|
|
58
62
|
def connect_stream
|
59
63
|
@stream_client.stop_stream
|
60
|
-
@streaming_thread.kill if @streaming_thread.is_a? Thread
|
61
64
|
|
62
|
-
Notifier.instance.show_message 'Trying to connect to Twitter...'
|
63
65
|
@streaming_thread = Thread.new do
|
64
66
|
begin
|
67
|
+
Notifier.instance.show_message 'Trying to connect to Twitter...'
|
65
68
|
@stream_client.userstream
|
66
69
|
rescue EventMachine::ConnectionError
|
67
70
|
Notifier.instance.show_error 'Connection failed'
|
68
71
|
sleep 30
|
69
72
|
retry
|
70
73
|
end
|
71
|
-
Notifier.instance.show_message 'Connection established'
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
data/lib/twterm/scheduler.rb
CHANGED
data/lib/twterm/status.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Twterm
|
2
2
|
class Status
|
3
|
-
|
3
|
+
MAX_CACHED_TIME = 3600
|
4
4
|
|
5
|
-
attr_reader :id, :text, :created_at, :created_at_for_sort, :retweet_count, :favorite_count, :in_reply_to_status_id, :favorited, :retweeted, :
|
5
|
+
attr_reader :id, :text, :created_at, :created_at_for_sort, :retweet_count, :favorite_count, :in_reply_to_status_id, :favorited, :retweeted, :user_id, :retweeted_by_user_id, :urls, :media, :touched_at
|
6
6
|
alias_method :favorited?, :favorited
|
7
7
|
alias_method :retweeted?, :retweeted
|
8
8
|
|
@@ -15,7 +15,8 @@ module Twterm
|
|
15
15
|
|
16
16
|
def initialize(tweet)
|
17
17
|
unless tweet.retweeted_status.is_a? Twitter::NullObject
|
18
|
-
@
|
18
|
+
@retweeted_by_user_id = tweet.user.id
|
19
|
+
User.create(tweet.user)
|
19
20
|
retweeted_at = Status.parse_time(tweet.created_at)
|
20
21
|
tweet = tweet.retweeted_status
|
21
22
|
end
|
@@ -34,7 +35,8 @@ module Twterm
|
|
34
35
|
@media = tweet.media
|
35
36
|
@urls = tweet.urls
|
36
37
|
|
37
|
-
@
|
38
|
+
@user_id = tweet.user.id
|
39
|
+
User.create(tweet.user)
|
38
40
|
|
39
41
|
@splitted_text = {}
|
40
42
|
|
@@ -95,15 +97,27 @@ module Twterm
|
|
95
97
|
Client.current.show_status(@in_reply_to_status_id, &block)
|
96
98
|
end
|
97
99
|
|
100
|
+
def retweeted_by
|
101
|
+
User.find(@retweeted_by_user_id)
|
102
|
+
end
|
103
|
+
|
98
104
|
def touch!
|
99
105
|
@touched_at = Time.now
|
100
106
|
end
|
101
107
|
|
108
|
+
def user
|
109
|
+
User.find(user_id)
|
110
|
+
end
|
111
|
+
|
102
112
|
def ==(other)
|
103
113
|
other.is_a?(self.class) && id == other.id
|
104
114
|
end
|
105
115
|
|
106
116
|
class << self
|
117
|
+
def all
|
118
|
+
@@instances.values
|
119
|
+
end
|
120
|
+
|
107
121
|
def find(id)
|
108
122
|
@@instances[id]
|
109
123
|
end
|
@@ -113,13 +127,11 @@ module Twterm
|
|
113
127
|
end
|
114
128
|
|
115
129
|
def cleanup
|
116
|
-
count = MAX_CACHED_STATUSES_COUNT
|
117
|
-
return if @@instances.count < count
|
118
|
-
|
119
130
|
TabManager.instance.each_tab do |tab|
|
120
131
|
tab.touch_statuses if tab.is_a?(Tab::StatusesTab)
|
121
132
|
end
|
122
|
-
|
133
|
+
cond = -> (status) { status.touched_at > Time.now - MAX_CACHED_TIME }
|
134
|
+
statuses = all.select(&cond)
|
123
135
|
status_ids = statuses.map(&:id)
|
124
136
|
@@instances = status_ids.zip(statuses).to_h
|
125
137
|
end
|
@@ -104,7 +104,7 @@ module Twterm
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def touch_statuses
|
107
|
-
statuses.take(100).each(&:touch!)
|
107
|
+
statuses.reverse.take(100).each(&:touch!)
|
108
108
|
end
|
109
109
|
|
110
110
|
def update
|
@@ -246,6 +246,7 @@ module Twterm
|
|
246
246
|
end
|
247
247
|
|
248
248
|
def sort
|
249
|
+
@status_ids &= Status.all.map(&:id)
|
249
250
|
@status_ids.sort_by! { |id| Status.find(id).created_at_for_sort }
|
250
251
|
end
|
251
252
|
|
data/lib/twterm/user.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module Twterm
|
2
2
|
class User
|
3
|
-
attr_reader :id, :name, :screen_name, :description, :location, :website,
|
4
|
-
|
3
|
+
attr_reader :id, :name, :screen_name, :description, :location, :website,
|
4
|
+
:following, :protected, :statuses_count, :friends_count,
|
5
|
+
:followers_count, :touched_at, :color
|
5
6
|
alias_method :following?, :following
|
6
7
|
alias_method :protected?, :protected
|
8
|
+
class << self
|
9
|
+
alias_method :create, :new
|
10
|
+
end
|
7
11
|
|
12
|
+
MAX_CACHED_TIME = 3600
|
8
13
|
COLORS = [:red, :blue, :green, :cyan, :yellow, :magenta]
|
9
14
|
|
10
|
-
@@instances =
|
15
|
+
@@instances = {}
|
11
16
|
|
12
17
|
def self.new(user)
|
13
|
-
|
14
|
-
instance = @@instances.find(&detector)
|
18
|
+
instance = find(user.id)
|
15
19
|
instance.nil? ? super : instance.update!(user)
|
16
20
|
end
|
17
21
|
|
@@ -19,8 +23,13 @@ module Twterm
|
|
19
23
|
@id = user.id
|
20
24
|
update!(user)
|
21
25
|
@color = COLORS[@id % 6]
|
26
|
+
touch!
|
27
|
+
|
28
|
+
@@instances[@id] = self
|
29
|
+
end
|
22
30
|
|
23
|
-
|
31
|
+
def touch!
|
32
|
+
@touched_at = Time.now
|
24
33
|
end
|
25
34
|
|
26
35
|
def update!(user)
|
@@ -39,5 +48,23 @@ module Twterm
|
|
39
48
|
|
40
49
|
self
|
41
50
|
end
|
51
|
+
|
52
|
+
def self.all
|
53
|
+
@@instances.values
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.find(id)
|
57
|
+
@@instances[id]
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.cleanup
|
61
|
+
referenced_users = Status.all.map(&:user)
|
62
|
+
referenced_users.each(&:touch!)
|
63
|
+
|
64
|
+
cond = -> (user) { user.touched_at > Time.now - MAX_CACHED_TIME }
|
65
|
+
users = all.select(&cond)
|
66
|
+
user_ids = users.map(&:id)
|
67
|
+
@@instances = user_ids.zip(users).to_h
|
68
|
+
end
|
42
69
|
end
|
43
70
|
end
|
data/lib/twterm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twterm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Kameoka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|