rbitter 0.2.0-java → 0.2.1-java

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +23 -22
  3. data/.rspec +2 -2
  4. data/.travis.yml +15 -15
  5. data/Gemfile +12 -12
  6. data/LICENSE.txt +22 -22
  7. data/Rakefile +8 -8
  8. data/bin/rbitter +20 -20
  9. data/lib/rbitter/arcserver.rb +169 -165
  10. data/lib/rbitter/console.rb +93 -93
  11. data/lib/rbitter/default/config_json.rb +41 -41
  12. data/lib/rbitter/dlthread.rb +62 -62
  13. data/lib/rbitter/env.rb +116 -116
  14. data/lib/rbitter/override/gems/rubysl-socket/socket.rb +8 -8
  15. data/lib/rbitter/override/gems/twitter/connection.rb +45 -45
  16. data/lib/rbitter/override.rb +47 -47
  17. data/lib/rbitter/progress.rb +23 -0
  18. data/lib/rbitter/records.rb +127 -127
  19. data/lib/rbitter/records_migrate/20150327_add_index.rb +11 -11
  20. data/lib/rbitter/records_migrate/20150504_add_replyto_column.rb +11 -11
  21. data/lib/rbitter/streaming.rb +104 -104
  22. data/lib/rbitter/version.rb +20 -20
  23. data/lib/rbitter/xmlrpc.rb +3 -3
  24. data/lib/rbitter/xmlrpcd/base.rb +24 -24
  25. data/lib/rbitter/xmlrpcd/rpchandles.rb +11 -11
  26. data/lib/rbitter/xmlrpcd/xmlrpc_auth_server.rb +82 -82
  27. data/lib/rbitter/xmlrpcd/xmlrpcd.rb +69 -69
  28. data/lib/rbitter.rb +62 -62
  29. data/rbitter.gemspec +46 -46
  30. data/spec/config/default.json +32 -32
  31. data/spec/rbitter/arcserver_spec.rb +30 -30
  32. data/spec/rbitter/console_spec.rb +9 -9
  33. data/spec/rbitter/default/config_json_spec.rb +3 -3
  34. data/spec/rbitter/dlthread_spec.rb +8 -8
  35. data/spec/rbitter/env_spec.rb +76 -76
  36. data/spec/rbitter/override/gems/twitter/connection_spec.rb +8 -8
  37. data/spec/rbitter/progress_spec.rb +1 -0
  38. data/spec/rbitter/records_spec.rb +13 -13
  39. data/spec/rbitter/streaming_spec.rb +9 -9
  40. data/spec/rbitter/version_spec.rb +8 -8
  41. data/spec/rbitter/xmlrpc_spec.rb +8 -8
  42. data/spec/rbitter/xmlrpcd/base_spec.rb +29 -29
  43. data/spec/rbitter/xmlrpcd/rpchandles_spec.rb +10 -10
  44. data/spec/rbitter/xmlrpcd/xmlrpc_auth_server_spec.rb +8 -8
  45. data/spec/rbitter/xmlrpcd/xmlrpcd_spec.rb +9 -9
  46. data/spec/rbitter_spec.rb +38 -38
  47. data/spec/spec_helper.rb +39 -39
  48. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c9c0ff087a6aacd028509c314aaefcbbf58dd36
4
- data.tar.gz: 920cd1f50bf68313d4c53bc63ce702d94eec3e44
3
+ metadata.gz: 06bfae2b2f77d2fc7187c107ddcb42f3b8240860
4
+ data.tar.gz: 6956d800f7d306b1ae4b6b1b78b3a4e1c383e954
5
5
  SHA512:
6
- metadata.gz: 234b2fddc686b01706d92146da6230d0c45f323bf0dd75447522f71f5543e21bc6afe2bf4ad98865d1524802e54aef9e7671d15abc2ea5b4f5198054dc0f9af2
7
- data.tar.gz: 7d11d501b9f3fcb2b5f78a76d4c3c1f197e0562aca9e59cdcfdbd0c54f16bed0c6c673c6b4d96af0c7abb6dd09b9eb9ea64ee596bd359738912a10eb86fef3c4
6
+ metadata.gz: 8d745a88bc36645e6e3b2b2224a192a44e4ca6dfb09f136b82ba275bdcc29abe2fe01ff7c51bd9dd9d8d1187eaab56b58e66cf8977c4da625b2c8c547036efb9
7
+ data.tar.gz: 1676d89e1c4b4fdb7b24a3d0f6d9263148d327fb82547de298dc7ed81f734df502a734bd083b61b3c003e59719b6867cf19e25a46a4be78ab0f5ee667b0962bb
data/.gitignore CHANGED
@@ -1,22 +1,23 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /build/
11
- /vendor/
12
- *.bundle
13
- *.so
14
- *.o
15
- *.a
16
- mkmf.log
17
- *.gem
18
- *.json
19
- *.sqlite
20
- *.png
21
- .rbitter
22
- .rbitter/*
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /build/
11
+ /vendor/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+ *.gem
18
+ *.json
19
+ *.sqlite
20
+ *.png
21
+ .rbitter
22
+ .rbitter/*
23
+ .ruby-version
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --require spec_helper
1
+ --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,15 +1,15 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.1.0
5
- - 2.2.0
6
- - jruby-19mode
7
- - jruby-head
8
- - rbx-2
9
-
10
- env: LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"
11
-
12
- matrix:
13
- allow_failures:
14
- - rvm: ruby-head
15
- - rvm: rbx-2
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - 2.2.0
6
+ - jruby-19mode
7
+ - jruby-head
8
+ - rbx-2
9
+
10
+ env: LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: rbx-2
data/Gemfile CHANGED
@@ -1,12 +1,12 @@
1
- source "https://rubygems.org"
2
-
3
- group :test do
4
- gem 'rspec', '~>3.0'
5
- gem 'simplecov', :require => false, :group => :test
6
- gem 'coveralls', :require => false
7
- end
8
-
9
- gem "bundler"
10
- gem 'jruby-openssl', platforms: :jruby
11
-
12
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ gem 'rspec', '~>3.0'
5
+ gem 'simplecov', :require => false, :group => :test
6
+ gem 'coveralls', :require => false
7
+ end
8
+
9
+ gem "bundler"
10
+ gem 'jruby-openssl', platforms: :jruby
11
+
12
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2015 Nidev Plontra
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2015 Nidev Plontra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task :default => :spec
7
- task :basic_test => :spec
8
-
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :basic_test => :spec
8
+
data/bin/rbitter CHANGED
@@ -1,20 +1,20 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rbitter"
4
-
5
- Rbitter.rbitter_header
6
-
7
- if ARGV.length < 1 || (not Rbitter::BOOTSTRAP_ARGS.include?(ARGV[0]))
8
- Rbitter.rbitter_help_msg
9
- exit -1
10
- else
11
- Rbitter.bootstrap(ARGV)
12
-
13
- if ARGV[0] == "configure"
14
- puts "Writing config.json done"
15
- puts "You can put config.json one of these locations:"
16
- puts "[1] config.json (current folder)"
17
- puts "[2] .rbitter/config.json (current folder)"
18
- end
19
- end
20
-
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rbitter"
4
+
5
+ Rbitter.rbitter_header
6
+
7
+ if ARGV.length < 1 || (not Rbitter::BOOTSTRAP_ARGS.include?(ARGV[0]))
8
+ Rbitter.rbitter_help_msg
9
+ exit -1
10
+ else
11
+ Rbitter.bootstrap(ARGV)
12
+
13
+ if ARGV[0] == "configure"
14
+ puts "Writing config.json done"
15
+ puts "You can put config.json one of these locations:"
16
+ puts "[1] config.json (current folder)"
17
+ puts "[2] .rbitter/config.json (current folder)"
18
+ end
19
+ end
20
+
@@ -1,165 +1,169 @@
1
- # encoding: utf-8
2
-
3
- require "json"
4
- require "date"
5
- require "twitter"
6
- require "resolv"
7
-
8
- require "rbitter/records"
9
- require "rbitter/streaming"
10
- require "rbitter/dlthread"
11
- require "rbitter/xmlrpc"
12
-
13
- module Rbitter
14
- class ArcServer
15
- LOG_NORMAL = 0
16
- LOG_INIT = 1
17
- LOG_HALT = 2
18
- LOG_ERROR = 4
19
-
20
- def initialize(xmlrpcd_class = Rbitter::RPCServer)
21
- @xmlrpcd_class = xmlrpcd_class
22
- @dt = DLThread.new(
23
- Rbitter['media_downloader']['download_dir'],
24
- Rbitter['media_downloader']['large_image'])
25
- end
26
-
27
- def arsupport_init
28
- ARSupport.connect_database
29
-
30
- if not ARSupport.prepared?
31
- puts "Initiate database table..."
32
- if Rbitter['activerecord'] == 'mysql2'
33
- ARSupport.prepare "DEFAULT CHARSET=utf8mb4"
34
- else
35
- ARSupport.prepare
36
- end
37
- end
38
-
39
- ARSupport.update_database_scheme
40
- end
41
-
42
- def arsupport_halt
43
- ARSupport.disconnect_database
44
- end
45
-
46
- def xmlrpcd_start
47
- if Rbitter['xmlrpc']['enable']
48
- @rpc_service = Thread.new {
49
- rpc_server = @xmlrpcd_class.new(Rbitter['xmlrpc']['bind_host'], Rbitter['xmlrpc']['bind_port'])
50
- rpc_server.main_loop
51
- }
52
- else
53
- @rpc_service = nil
54
- end
55
- end
56
-
57
- def xmlrpcd_stop
58
- unless @rpc_service.nil?
59
- if @rpc_service.alive?
60
- puts "Finishing RPCServer (impl: #{@xmlrpcd_class})"
61
- @rpc_service.terminate
62
- @rpc_service.join
63
- @rpc_service = nil
64
- end
65
- end
66
- end
67
-
68
- def mark(code, message)
69
- Record.create({:marker => code,
70
- :marker_msg => message,
71
- :userid => nil,
72
- :username => nil,
73
- :tweetid => nil,
74
- :replyto => nil,
75
- :tweet => nil,
76
- :date => ARSupport.any_to_datestring(DateTime.now),
77
- :rt_count => 0,
78
- :fav_count => 0})
79
- end
80
-
81
- def mark_init
82
- mark(LOG_INIT, "Archiving service started")
83
- end
84
-
85
- def mark_halt
86
- mark(LOG_HALT, "Archiving service halted")
87
- end
88
-
89
- def mark_error(exception_string, err_msg)
90
- mark(LOG_ERROR, "Errored (#{exception_string}, #{err_msg}")
91
- end
92
-
93
- def resurrect_loop?
94
- if Rbitter.env['twitter']['connection']['reconnect']
95
- puts "[rbitter] Try to reconnect..."
96
- sleep Rbitter.env['twitter']['connection']['timeout_secs']
97
- true
98
- else
99
- puts "[rbitter] Give up!"
100
- false
101
- end
102
- end
103
-
104
- def main_loop(streaming_adapter = Rbitter::StreamClient)
105
- xmlrpcd_start if Rbitter['xmlrpc']['enable']
106
-
107
- arsupport_init
108
-
109
- begin
110
- mark_init
111
-
112
- streaming_adapter.new(Rbitter['twitter']).run { |a|
113
- @dt << a['media_urls']
114
-
115
- record = Record.find_or_initialize_by(tweetid: a['tweetid'])
116
- record.update({:marker => 0,
117
- :marker_msg => "normal",
118
- :userid => a['userid'],
119
- :username => a['screen_name'],
120
- :tweetid => a['tweetid'],
121
- :replyto => a['replyto'],
122
- :tweet => a['tweet'],
123
- :date => a['date'],
124
- :rt_count => a['rt_count'],
125
- :fav_count => a['fav_count']})
126
-
127
- record.save
128
- }
129
- rescue Interrupt => e
130
- puts ""
131
- puts "Interrupted..."
132
- mark_error(e.to_s, "(exit) SIGINT - interrupted by user")
133
- rescue Twitter::Error::Unauthorized => e
134
- warn "Twitter access unauthorized:"
135
- warn " Possible solutions"
136
- warn " 1. Configure Twitter token on config.json"
137
- warn " 2. Check system time (Time is important on authentication)"
138
- warn " 3. Check Twitter account status"
139
- rescue Twitter::Error::ServerError => e
140
- puts "Service unavailable now. Retry in 5 seconds..."
141
- mark_error(e.to_s, "(retry) Twitter server unavailable / Timeout")
142
-
143
- retry if resurrect_loop?
144
- rescue Resolv::ResolvError, Errno::ECONNABORTED,
145
- Errno::ECONNREFUSED, Errno::ECONNRESET => e
146
- puts "Network problem. Retry in 5 seconds..."
147
- mark_error(e.to_s, "(retry) Network problem")
148
-
149
- retry if resurrect_loop?
150
- rescue Twitter::Error => e
151
- warn "Twitter Error: #{e.inspect}"
152
- warn "Rbitter halts due to Twitter::Error"
153
- mark_error(e.to_s, "(exit) Twitter Error")
154
- ensure
155
- xmlrpcd_stop if Rbitter['xmlrpc']['enable']
156
- @dt.job_cleanup
157
-
158
- mark_halt
159
- end
160
-
161
- arsupport_halt
162
- end
163
-
164
- end
165
- end
1
+ # encoding: utf-8
2
+
3
+ require "json"
4
+ require "date"
5
+ require "twitter"
6
+ require "resolv"
7
+
8
+ require "rbitter/records"
9
+ require "rbitter/streaming"
10
+ require "rbitter/dlthread"
11
+ require "rbitter/xmlrpc"
12
+ require "rbitter/progress"
13
+
14
+ module Rbitter
15
+ class ArcServer
16
+ include Progress
17
+
18
+ LOG_NORMAL = 0
19
+ LOG_INIT = 1
20
+ LOG_HALT = 2
21
+ LOG_ERROR = 4
22
+
23
+ def initialize(xmlrpcd_class = Rbitter::RPCServer)
24
+ @xmlrpcd_class = xmlrpcd_class
25
+ @dt = DLThread.new(
26
+ Rbitter['media_downloader']['download_dir'],
27
+ Rbitter['media_downloader']['large_image'])
28
+ end
29
+
30
+ def arsupport_init
31
+ ARSupport.connect_database
32
+
33
+ if not ARSupport.prepared?
34
+ puts "Initiate database table..."
35
+ if Rbitter['activerecord'] == 'mysql2'
36
+ ARSupport.prepare "DEFAULT CHARSET=utf8mb4"
37
+ else
38
+ ARSupport.prepare
39
+ end
40
+ end
41
+
42
+ ARSupport.update_database_scheme
43
+ end
44
+
45
+ def arsupport_halt
46
+ ARSupport.disconnect_database
47
+ end
48
+
49
+ def xmlrpcd_start
50
+ if Rbitter['xmlrpc']['enable']
51
+ @rpc_service = Thread.new {
52
+ rpc_server = @xmlrpcd_class.new(Rbitter['xmlrpc']['bind_host'], Rbitter['xmlrpc']['bind_port'])
53
+ rpc_server.main_loop
54
+ }
55
+ else
56
+ @rpc_service = nil
57
+ end
58
+ end
59
+
60
+ def xmlrpcd_stop
61
+ unless @rpc_service.nil?
62
+ if @rpc_service.alive?
63
+ puts "Finishing RPCServer (impl: #{@xmlrpcd_class})"
64
+ @rpc_service.terminate
65
+ @rpc_service.join
66
+ @rpc_service = nil
67
+ end
68
+ end
69
+ end
70
+
71
+ def mark(code, message)
72
+ Record.create({:marker => code,
73
+ :marker_msg => message,
74
+ :userid => nil,
75
+ :username => nil,
76
+ :tweetid => nil,
77
+ :replyto => nil,
78
+ :tweet => nil,
79
+ :date => ARSupport.any_to_datestring(DateTime.now),
80
+ :rt_count => 0,
81
+ :fav_count => 0})
82
+ end
83
+
84
+ def mark_init
85
+ mark(LOG_INIT, "Archiving service started")
86
+ end
87
+
88
+ def mark_halt
89
+ mark(LOG_HALT, "Archiving service halted")
90
+ end
91
+
92
+ def mark_error(exception_string, err_msg)
93
+ mark(LOG_ERROR, "Errored (#{exception_string}, #{err_msg}")
94
+ end
95
+
96
+ def resurrect_loop?
97
+ if Rbitter.env['twitter']['connection']['reconnect']
98
+ puts "[rbitter] Try to reconnect..."
99
+ sleep Rbitter.env['twitter']['connection']['timeout_secs']
100
+ true
101
+ else
102
+ puts "[rbitter] Give up!"
103
+ false
104
+ end
105
+ end
106
+
107
+ def main_loop(streaming_adapter = Rbitter::StreamClient)
108
+ xmlrpcd_start if Rbitter['xmlrpc']['enable']
109
+
110
+ arsupport_init
111
+
112
+ begin
113
+ mark_init
114
+
115
+ streaming_adapter.new(Rbitter['twitter']).run { |a|
116
+ @dt << a['media_urls']
117
+
118
+ record = Record.find_or_initialize_by(tweetid: a['tweetid'])
119
+ record.update({:marker => 0,
120
+ :marker_msg => "normal",
121
+ :userid => a['userid'],
122
+ :username => a['screen_name'],
123
+ :tweetid => a['tweetid'],
124
+ :replyto => a['replyto'],
125
+ :tweet => a['tweet'],
126
+ :date => a['date'],
127
+ :rt_count => a['rt_count'],
128
+ :fav_count => a['fav_count']})
129
+
130
+ record.save
131
+ draw "[rbitter] saving tweet: #{a['tweetid']}"
132
+ }
133
+ rescue Interrupt => e
134
+ puts ""
135
+ puts "Interrupted..."
136
+ mark_error(e.to_s, "(exit) SIGINT - interrupted by user")
137
+ rescue Twitter::Error::Unauthorized => e
138
+ warn "Twitter access unauthorized:"
139
+ warn " Possible solutions"
140
+ warn " 1. Configure Twitter token on config.json"
141
+ warn " 2. Check system time (Time is important on authentication)"
142
+ warn " 3. Check Twitter account status"
143
+ rescue Twitter::Error::ServerError => e
144
+ puts "Service unavailable now. Retry in 5 seconds..."
145
+ mark_error(e.to_s, "(retry) Twitter server unavailable / Timeout")
146
+
147
+ retry if resurrect_loop?
148
+ rescue Resolv::ResolvError, Errno::ECONNABORTED,
149
+ Errno::ECONNREFUSED, Errno::ECONNRESET => e
150
+ puts "Network problem. Retry in 5 seconds..."
151
+ mark_error(e.to_s, "(retry) Network problem")
152
+
153
+ retry if resurrect_loop?
154
+ rescue Twitter::Error => e
155
+ warn "Twitter Error: #{e.inspect}"
156
+ warn "Rbitter halts due to Twitter::Error"
157
+ mark_error(e.to_s, "(exit) Twitter Error")
158
+ ensure
159
+ xmlrpcd_stop if Rbitter['xmlrpc']['enable']
160
+ @dt.job_cleanup
161
+
162
+ mark_halt
163
+ end
164
+
165
+ arsupport_halt
166
+ end
167
+
168
+ end
169
+ end