ruboty-chatwork 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 +27 -0
- data/Rakefile +1 -0
- data/lib/ruboty/adapters/chatwork.rb +80 -0
- data/lib/ruboty/chatwork/version.rb +5 -0
- data/lib/ruboty/chatwork.rb +2 -0
- data/ruboty-chatwork.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd751d7807e587770464129d389eba4819eec9d0
|
4
|
+
data.tar.gz: d0507ec1c40abe6940ee86e59941901d5bec901a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90a4b30ce30bd2735ae5f1b9b271c2713762734e35a5a206113fabe7988c7fac5ae3966aa5c1984dc6f080c252d769910a0d7d91ceb529a1d8099a3a65be6fd0
|
7
|
+
data.tar.gz: 14bf7401a4da5ce231982511391d050176799cd3475c2be1b6ec7f9dfbf1059afbad74b26ca443d53b24b47ef7a10c7ff28dfdc26b37b06ef69549e7d8a0c0eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Seiei Higa
|
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,27 @@
|
|
1
|
+
# Ruboty::Chatwork
|
2
|
+
|
3
|
+
Chatwork adapter for [Ruboty](https://github.com/r7kamura/ruboty).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Get your ChatWork API Token
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
# Gemfile
|
10
|
+
gem 'ruboty-chatwork', github: "mhag/ruboty-chatwork"
|
11
|
+
```
|
12
|
+
|
13
|
+
## ENV
|
14
|
+
|
15
|
+
```
|
16
|
+
CHATWORK_API_TOKEN - ChatWork API Token
|
17
|
+
CHATWORK_ROOM - ChatWork Room ID
|
18
|
+
CHATWORK_API_RATE - ChatWork API Rate(Requests per Hour)
|
19
|
+
```
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( http://github.com/mhag/ruboty-chatwork/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
module Ruboty
|
7
|
+
module Adapters
|
8
|
+
class Chatwork < Base
|
9
|
+
include Mem
|
10
|
+
|
11
|
+
env :CHATWORK_API_TOKEN, "ChatWork API Token"
|
12
|
+
env :CHATWORK_ROOM, "ChatWork Room ID"
|
13
|
+
env :CHATWORK_API_RATE, "ChatWork API Rate(Request per Hour)"
|
14
|
+
|
15
|
+
def run
|
16
|
+
listen
|
17
|
+
end
|
18
|
+
|
19
|
+
def say(message)
|
20
|
+
pp message
|
21
|
+
req = Net::HTTP::Post.new(chatwork_messages_url.path, headers)
|
22
|
+
req.form_data = { 'body' => message[:body] }
|
23
|
+
https = Net::HTTP.new(chatwork_messages_url.host, chatwork_messages_url.port)
|
24
|
+
https.use_ssl = true
|
25
|
+
https.start {|https| https.request(req) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def chatwork_url
|
29
|
+
URI.parse(ENV["CHATWORK_URL"] || "https://api.chatwork.com/")
|
30
|
+
end
|
31
|
+
memoize :chatwork_url
|
32
|
+
|
33
|
+
def chatwork_api_token
|
34
|
+
ENV["CHATWORK_API_TOKEN"]
|
35
|
+
end
|
36
|
+
memoize :chatwork_api_token
|
37
|
+
|
38
|
+
def chatwork_room
|
39
|
+
ENV["CHATWORK_ROOM"]
|
40
|
+
end
|
41
|
+
memoize :chatwork_room
|
42
|
+
|
43
|
+
def chatwork_messages_url
|
44
|
+
URI.join(chatwork_url, "/v1/rooms/#{chatwork_room}/messages")
|
45
|
+
end
|
46
|
+
memoize :chatwork_messages_url
|
47
|
+
|
48
|
+
def chatwork_api_rate
|
49
|
+
ENV["CHATWORK_API_RATE"].to_i
|
50
|
+
end
|
51
|
+
memoize :chatwork_api_rate
|
52
|
+
|
53
|
+
def headers
|
54
|
+
{
|
55
|
+
'X-ChatWorkToken' => chatwork_api_token,
|
56
|
+
}
|
57
|
+
end
|
58
|
+
memoize :headers
|
59
|
+
|
60
|
+
def listen
|
61
|
+
loop do
|
62
|
+
req = Net::HTTP::Get.new(chatwork_messages_url.path, headers)
|
63
|
+
https = Net::HTTP.new(chatwork_messages_url.host, chatwork_messages_url.port)
|
64
|
+
https.use_ssl = true
|
65
|
+
res = https.start {|https| https.request(req) }
|
66
|
+
pp res.body
|
67
|
+
unless res.body.nil?
|
68
|
+
message = JSON.parse(res.body)
|
69
|
+
robot.receive(
|
70
|
+
body: message[0]['body'],
|
71
|
+
from_name: message[0]['account']['name']
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
sleep (60 * 60) / chatwork_api_rate
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/chatwork/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-chatwork"
|
8
|
+
spec.version = Ruboty::Chatwork::VERSION
|
9
|
+
spec.authors = ["mhag"]
|
10
|
+
spec.email = ["hagihar@gmail.com"]
|
11
|
+
spec.summary = %q{ChatWork adapter for Ruboty.}
|
12
|
+
spec.homepage = "https://github.com/mhag/ruboty-chatwork"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.required_ruby_version = ">= 2.2.0"
|
21
|
+
spec.add_dependency "ruboty"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-chatwork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mhag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- hagihar@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/ruboty/adapters/chatwork.rb
|
68
|
+
- lib/ruboty/chatwork.rb
|
69
|
+
- lib/ruboty/chatwork/version.rb
|
70
|
+
- ruboty-chatwork.gemspec
|
71
|
+
homepage: https://github.com/mhag/ruboty-chatwork
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.2.0
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: ChatWork adapter for Ruboty.
|
95
|
+
test_files: []
|