fluent-plugin-gree_community 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 todesking
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # fluent-plugin-gree_community
2
+
3
+ Fluentd input plugin from GREE community.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-gree_community'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-gree_community
18
+
19
+ ## Usage
20
+
21
+ # fluent.conf
22
+ <source>
23
+ type gree_community
24
+
25
+ tag gree
26
+
27
+ # http://gree.jp/community/{community_id}
28
+ community_id 2397366
29
+
30
+ # Regexp for thread title
31
+ thread_title_pattern 雑談|要望
32
+ # Top N threads to watch
33
+ recent_threads_num 4
34
+
35
+ # optional, default=true
36
+ # omit output when startup
37
+ silent_startup true
38
+
39
+ # Pit ID for GREE account('email' and 'password' required)
40
+ pit_id gree
41
+
42
+ # Update interval[sec]
43
+ interval_sec 20
44
+ </source>
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
53
+
54
+ ## Changes
55
+
56
+ ### 0.0.1
57
+
58
+ * Initial release.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+ Rake::TestTask.new(:test) do |test|
3
+ test.libs << 'lib' << 'test'
4
+ test.pattern = 'test/**/test_*.rb'
5
+ test.verbose = true
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "fluent-plugin-gree_community"
3
+ gem.version = "0.0.1"
4
+ gem.authors = ["todesking"]
5
+ gem.email = ["discommunicative@gmail.com"]
6
+ gem.summary = %q{Fluentd input plugin, source from GREE community}
7
+ gem.homepage = "https://github.com/todesking/fluent-plugin-gree_community"
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.require_paths = ["lib"]
13
+
14
+ gem.add_development_dependency "rake"
15
+ gem.add_development_dependency "fluentd"
16
+
17
+ gem.add_runtime_dependency "gree-community"
18
+ gem.add_runtime_dependency "fluentd"
19
+ gem.add_runtime_dependency "pit"
20
+ end
@@ -0,0 +1,102 @@
1
+ require 'fluent/plugin'
2
+ require 'fluent/config'
3
+ require 'fluent/input'
4
+
5
+ 1.tap do
6
+ # https://github.com/fluent/fluentd/issues/76
7
+ encoding = Encoding.default_internal
8
+ Encoding.default_internal = nil
9
+ require 'mime/types'
10
+ Encoding.default_internal = encoding
11
+ end
12
+
13
+ require 'gree-community'
14
+ require 'pit'
15
+
16
+ class Fluent::GreeCommunityInput < Fluent::Input
17
+ Fluent::Plugin.register_input('gree_community', self)
18
+
19
+ config_param :interval_sec, :integer
20
+ config_param :pit_id, :string
21
+ config_param :community_id, :integer
22
+ config_param :thread_title_pattern, :string
23
+ # Top N threads are watching target
24
+ config_param :recent_threads_num, :integer
25
+ config_param :tag, :string
26
+ config_param :silent_startup, :bool, default: true
27
+
28
+ def configure(config)
29
+ super
30
+ @thread_title_pattern = Regexp.new(@thread_title_pattern, {}, 'n')
31
+
32
+ user_info = Pit.get(@pit_id, require: {
33
+ 'email' => 'mail',
34
+ 'password' => 'password',
35
+ })
36
+ @fetcher = GREE::Community::Fetcher.new(
37
+ user_info['email'],
38
+ user_info['password']
39
+ )
40
+
41
+ @community = GREE::Community.new(@community_id)
42
+
43
+ # {[community_id, thread_id] => last_comment_id}
44
+ @last_comment_ids = {}
45
+
46
+ $log.info("gree_community: user=#{user_info['email']}")
47
+ $log.info("gree_community: community_id=#{@community_id}")
48
+ $log.info("gree_community: thread_title_pattern=#{@thread_title_pattern}")
49
+ $log.info("gree_community: interval_sec=#{@interval_sec}")
50
+ end
51
+
52
+ def start
53
+ @thread = Thread.new(&method(:run))
54
+ end
55
+
56
+ def shutdown
57
+ @thread.kill
58
+ end
59
+
60
+ def run
61
+ @first_time = true
62
+ loop do
63
+ begin
64
+ fetch_and_emit
65
+ rescue StandardError, Timeout::Error
66
+ $log.error("gree_community(community_id=#{@community_id}): #{$!.inspect}")
67
+ $log.error_backtrace
68
+ end
69
+ @first_time = false
70
+ sleep @interval_sec
71
+ end
72
+ end
73
+
74
+ def fetch_and_emit
75
+ @community.fetch(@fetcher)
76
+ @community.recent_threads[0...@recent_threads_num].select{|th| th.title =~ @thread_title_pattern}.each do|th|
77
+ th.fetch(@fetcher)
78
+ th.recent_comments.each do|comment|
79
+ last_comment_id = @last_comment_ids[[@community.id, th.id]]
80
+ next if last_comment_id && comment.id <= last_comment_id
81
+ @last_comment_ids[[@community.id, th.id]] = comment.id
82
+
83
+ next if @silent_startup && @first_time
84
+
85
+ Fluent::Engine.emit(@tag, Fluent::Engine.now, {
86
+ 'community' => {
87
+ 'id' => @community.id,
88
+ },
89
+ 'thread' => {
90
+ 'id' => th.id,
91
+ 'title' => th.title,
92
+ },
93
+ 'comment' => {
94
+ 'id' => comment.id,
95
+ 'user_name' => comment.user_name,
96
+ 'body_text' => comment.body_text.strip,
97
+ }
98
+ })
99
+ end
100
+ end
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-gree_community
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - todesking
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: gree-community
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: fluentd
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pit
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description:
95
+ email:
96
+ - discommunicative@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE
104
+ - README.md
105
+ - Rakefile
106
+ - fluent-plugin-gree_community.gemspec
107
+ - lib/fluent/plugin/in_gree_community.rb
108
+ homepage: https://github.com/todesking/fluent-plugin-gree_community
109
+ licenses: []
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.24
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Fluentd input plugin, source from GREE community
132
+ test_files: []