chatwork_bridge 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/chatwork_bridge +5 -0
- data/chatwork_bridge.gemspec +27 -0
- data/lib/chatwork_bridge/cli.rb +36 -0
- data/lib/chatwork_bridge/notifiers/debug_notifier.rb +12 -0
- data/lib/chatwork_bridge/notifiers/email_notifier.rb +38 -0
- data/lib/chatwork_bridge/notifiers.rb +3 -0
- data/lib/chatwork_bridge/settings.rb +28 -0
- data/lib/chatwork_bridge/version.rb +3 -0
- data/lib/chatwork_bridge/watcher.rb +77 -0
- data/lib/chatwork_bridge.rb +11 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02b75e5e432d56f20f1a46bb8b5ccf64a28ca77d
|
4
|
+
data.tar.gz: 5d04db745226695270de97efbd7db1aef2230753
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41110f99bde83d78c00135f3dafca00f19b28191f55da87aa994016502787abb0e032118efd2b03842451f2442904fc711260c4ef2ed370a655d07f02245a936
|
7
|
+
data.tar.gz: 43036775e55d6dfea481f87e12aae1ea2bdeef8ab5e8446c30c136b7a2f18aab3e2445f805340f478e44b0d5317b6d0952dd7fe1c2e5449a70ebaf4b3192d2b8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ryota Arai
|
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/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# ChatworkBridge
|
2
|
+
|
3
|
+
Send ChatWork notifications via email, stdout or etc...
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install chatwork_bridge
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Put a config file named `~/.chatwork_bridge.config.rb`:
|
12
|
+
```ruby
|
13
|
+
self.chatwork_login_url = 'https://www.chatwork.com/login.php'
|
14
|
+
self.chatwork_email = ''
|
15
|
+
self.chatwork_password = ''
|
16
|
+
|
17
|
+
notifier :debug do
|
18
|
+
end
|
19
|
+
|
20
|
+
notifier :email do
|
21
|
+
self.to = ''
|
22
|
+
self.from = ''
|
23
|
+
self.smtp_host = 'smtp.gmail.com'
|
24
|
+
self.smtp_port = 587
|
25
|
+
self.smtp_user = ''
|
26
|
+
self.smtp_password = ''
|
27
|
+
self.enable_tls = true
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Run watcher:
|
32
|
+
```
|
33
|
+
$ chatwork_bridge watch
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/chatwork_bridge
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chatwork_bridge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chatwork_bridge"
|
8
|
+
spec.version = ChatworkBridge::VERSION
|
9
|
+
spec.authors = ["Ryota Arai"]
|
10
|
+
spec.email = ["ryota.arai@gmail.com"]
|
11
|
+
spec.description = %q{Send ChatWork notifications via email, stdout and so on}
|
12
|
+
spec.summary = %q{Send ChatWork notifications via email, stdout and so on}
|
13
|
+
spec.homepage = "https://github.com/ryotarai/chatwork_bridge"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.4.0.pre.1"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "thor"
|
25
|
+
spec.add_dependency "selenium-webdriver"
|
26
|
+
spec.add_dependency "mail"
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'chatwork_bridge'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module ChatworkBridge
|
5
|
+
class CLI < Thor
|
6
|
+
class_option :config, type: :string
|
7
|
+
|
8
|
+
desc 'watch', 'Start watching chatwork'
|
9
|
+
def watch
|
10
|
+
settings = load_settings
|
11
|
+
watcher = Watcher.new({
|
12
|
+
chatwork_login_url: settings.chatwork_login_url,
|
13
|
+
chatwork_email: settings.chatwork_email,
|
14
|
+
chatwork_password: settings.chatwork_password,
|
15
|
+
})
|
16
|
+
watcher.notifiers = settings.notifiers
|
17
|
+
watcher.run
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def load_settings
|
22
|
+
config_paths = %w! ~/.chatwork_bridge.config.rb !
|
23
|
+
config_paths.unshift(options[:config]) if options[:config]
|
24
|
+
config_paths.map! {|path| File.expand_path(path) }
|
25
|
+
config_path = config_paths.find {|path| File.exists?(path) }
|
26
|
+
if config_path.nil?
|
27
|
+
$logger.fatal "Config file is not found. (Search Paths: #{config_paths})"
|
28
|
+
abort
|
29
|
+
end
|
30
|
+
Settings.new.tap do |s|
|
31
|
+
s.instance_eval File.read(config_path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'chatwork_bridge'
|
2
|
+
require 'net/smtp'
|
3
|
+
require 'mail'
|
4
|
+
|
5
|
+
module ChatworkBridge
|
6
|
+
module Notifiers
|
7
|
+
class EmailNotifier
|
8
|
+
attr_accessor :to, :from, :smtp_host, :smtp_port, :enable_tls, :smtp_user, :smtp_password
|
9
|
+
|
10
|
+
def notify(notification)
|
11
|
+
send_email(
|
12
|
+
"[ChatWork] #{notification['room_name']}",
|
13
|
+
notification['content']
|
14
|
+
)
|
15
|
+
$logger.info "Email sent to #{self.to}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_email(subject, body)
|
19
|
+
to_addr = self.to
|
20
|
+
from_addr = self.from
|
21
|
+
mail = Mail.new do
|
22
|
+
to to_addr
|
23
|
+
from from_addr
|
24
|
+
subject subject
|
25
|
+
body body
|
26
|
+
end
|
27
|
+
mail.charset = 'utf-8'
|
28
|
+
|
29
|
+
smtp = Net::SMTP.new(self.smtp_host, self.smtp_port)
|
30
|
+
smtp.enable_starttls if self.enable_tls
|
31
|
+
smtp.start(self.smtp_host, self.smtp_user, self.smtp_password, :login) do
|
32
|
+
smtp.send_message(mail.encoded, mail.from, mail.to)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'chatwork_bridge'
|
2
|
+
|
3
|
+
module ChatworkBridge
|
4
|
+
class Settings
|
5
|
+
attr_reader :notifiers
|
6
|
+
attr_accessor :chatwork_login_url, :chatwork_email, :chatwork_password
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@notifiers = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def notifier(type, &block)
|
13
|
+
clazz = Notifiers.const_get("#{type.to_s.capitalize}Notifier")
|
14
|
+
notifier = clazz.new
|
15
|
+
notifier.instance_eval(&block)
|
16
|
+
@notifiers << notifier
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_device=(device)
|
20
|
+
$logger = Logger.new(device)
|
21
|
+
end
|
22
|
+
|
23
|
+
def log_level=(level)
|
24
|
+
$logger.level = level
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'chatwork_bridge'
|
2
|
+
require 'selenium-webdriver'
|
3
|
+
|
4
|
+
module ChatworkBridge
|
5
|
+
class Watcher
|
6
|
+
attr_accessor :notifiers
|
7
|
+
|
8
|
+
def initialize(opts={})
|
9
|
+
opts = {interval: 1, browser: :phantomjs}.merge(opts)
|
10
|
+
@interval = opts.fetch(:interval)
|
11
|
+
@browser = opts.fetch(:browser)
|
12
|
+
@chatwork_login_url = opts.fetch(:chatwork_login_url)
|
13
|
+
@chatwork_email = opts.fetch(:chatwork_email)
|
14
|
+
@chatwork_password = opts.fetch(:chatwork_password)
|
15
|
+
@notifiers = opts[:notifiers] || []
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
begin
|
20
|
+
init_driver
|
21
|
+
login
|
22
|
+
inject_code
|
23
|
+
loop do
|
24
|
+
notification = fetch_latest_notification
|
25
|
+
unless notification.nil?
|
26
|
+
process_notification(notification)
|
27
|
+
end
|
28
|
+
sleep @interval
|
29
|
+
end
|
30
|
+
ensure
|
31
|
+
quit_driver
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def init_driver
|
37
|
+
$logger.info "Creating selenium webdriver..."
|
38
|
+
@driver = Selenium::WebDriver.for @browser
|
39
|
+
$logger.info "Done."
|
40
|
+
end
|
41
|
+
|
42
|
+
def quit_driver
|
43
|
+
@driver.quit
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_latest_notification
|
47
|
+
@driver.execute_script("return NotificationLogs.shift();")
|
48
|
+
end
|
49
|
+
|
50
|
+
def login
|
51
|
+
$logger.info "Logging in..."
|
52
|
+
@driver.navigate.to @chatwork_login_url
|
53
|
+
@driver.find_element(:css, '#login_email').send_keys(@chatwork_email)
|
54
|
+
@driver.find_element(:css, 'input[name=password]').send_keys(@chatwork_password)
|
55
|
+
@driver.find_element(:css, 'input[name=login]').click
|
56
|
+
$logger.info "Done."
|
57
|
+
end
|
58
|
+
|
59
|
+
def inject_code
|
60
|
+
$logger.info "Injecting code..."
|
61
|
+
@driver.execute_script(<<-EOC)
|
62
|
+
NotificationLogs = [];
|
63
|
+
CW.enable_popup = true;
|
64
|
+
CW.view.popup = function(a, b, c, d) {
|
65
|
+
NotificationLogs.push({icon: a, room_id: d, room_name: b, content: c});
|
66
|
+
};
|
67
|
+
EOC
|
68
|
+
$logger.info "Done."
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_notification(notification)
|
72
|
+
@notifiers.each do |notifier|
|
73
|
+
notifier.notify(notification)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "chatwork_bridge/version"
|
2
|
+
require "chatwork_bridge/cli"
|
3
|
+
require "chatwork_bridge/settings"
|
4
|
+
require "chatwork_bridge/watcher"
|
5
|
+
require "chatwork_bridge/notifiers"
|
6
|
+
|
7
|
+
require 'logger'
|
8
|
+
$logger = Logger.new(STDOUT)
|
9
|
+
|
10
|
+
module ChatworkBridge
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chatwork_bridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryota Arai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0.pre.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.0.pre.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: selenium-webdriver
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mail
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Send ChatWork notifications via email, stdout and so on
|
84
|
+
email:
|
85
|
+
- ryota.arai@gmail.com
|
86
|
+
executables:
|
87
|
+
- chatwork_bridge
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/chatwork_bridge
|
97
|
+
- chatwork_bridge.gemspec
|
98
|
+
- lib/chatwork_bridge.rb
|
99
|
+
- lib/chatwork_bridge/cli.rb
|
100
|
+
- lib/chatwork_bridge/notifiers.rb
|
101
|
+
- lib/chatwork_bridge/notifiers/debug_notifier.rb
|
102
|
+
- lib/chatwork_bridge/notifiers/email_notifier.rb
|
103
|
+
- lib/chatwork_bridge/settings.rb
|
104
|
+
- lib/chatwork_bridge/version.rb
|
105
|
+
- lib/chatwork_bridge/watcher.rb
|
106
|
+
homepage: https://github.com/ryotarai/chatwork_bridge
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.0.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Send ChatWork notifications via email, stdout and so on
|
130
|
+
test_files: []
|