ruboty-idobata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/images/screenshot.png +0 -0
- data/lib/ruboty/adapters/idobata.rb +180 -0
- data/lib/ruboty/idobata/version.rb +5 -0
- data/lib/ruboty/idobata.rb +2 -0
- data/ruboty-idobata.gemspec +24 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75c418f9a87848606cdbba57fe771c3eecf150ca
|
4
|
+
data.tar.gz: 18e295d7dea611db09feb62c8bcad1ed40ac6a9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cbb8969254b29d1ae801ef57b03a89456e1235211b4e2946abfd380472676987e507ad9c8b0cea04c791a7b2af33e543ed7786c4067f4986af42d24789146ef
|
7
|
+
data.tar.gz: ed320fc4dfc6441a21f2b4373c7f598d5907a242af1dedb7cddb8eabafd5dba29bcf48f12e7cbef22e9d47af6eec372c399dbef943252d892b8aed57fdc767ce
|
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,33 @@
|
|
1
|
+
# Ruboty::Idobata
|
2
|
+
|
3
|
+
Idobata adapter for [Ruboty](https://github.com/r7kamura/ruboty).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Get your idobata bots api token
|
7
|
+
|
8
|
+
- from organization setting page: https://idobata.io/#/organization/YOUR_ORGANIZATION/bots
|
9
|
+
- or room setting page: https://idobata.io/#/organization/YOUR_ORGANIZATION/room/YOUR_ROOM/settings
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
# Gemfile
|
13
|
+
gem 'ruboty-idobata'
|
14
|
+
```
|
15
|
+
|
16
|
+
## ENV
|
17
|
+
|
18
|
+
```
|
19
|
+
IDOBATA_URL - Idobata url
|
20
|
+
IDOBATA_PUSHER_KEY - Idobata's pusher key
|
21
|
+
IDOBATA_API_TOKEN - Idobata bots api token
|
22
|
+
```
|
23
|
+
|
24
|
+
## Screenshot
|
25
|
+
![](https://raw.githubusercontent.com/hanachin/ruboty-idobata/master/images/screenshot.png)
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( http://github.com/<my-github-username>/ruboty-idobata/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
Binary file
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'pp'
|
5
|
+
require 'pusher-client'
|
6
|
+
|
7
|
+
module Ruboty
|
8
|
+
module Adapters
|
9
|
+
class Idobata < Base
|
10
|
+
include Mem
|
11
|
+
|
12
|
+
env :IDOBATA_URL, "Idobata url", optional: true
|
13
|
+
env :IDOBATA_PUSHER_KEY, "Idobata's pusher key", optional: true
|
14
|
+
env :IDOBATA_API_TOKEN, "Idobata bots api token"
|
15
|
+
|
16
|
+
def run
|
17
|
+
on_connection_established do
|
18
|
+
join_channel
|
19
|
+
log_message
|
20
|
+
listen
|
21
|
+
end
|
22
|
+
connect
|
23
|
+
end
|
24
|
+
|
25
|
+
def say(message)
|
26
|
+
pp message
|
27
|
+
req = Net::HTTP::Post.new(idobata_messages_url.path, headers)
|
28
|
+
req.form_data = { 'message[room_id]' => message[:original][:room_id], 'message[source]' => message[:body] }
|
29
|
+
https = Net::HTTP.new(idobata_messages_url.host, idobata_messages_url.port)
|
30
|
+
https.use_ssl = true
|
31
|
+
https.start {|https| https.request(req) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_connection_established(&block)
|
35
|
+
socket.bind('pusher:connection_established', &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
memoize\
|
39
|
+
def idobata_url
|
40
|
+
URI.parse(ENV["IDOBATA_URL"] || "https://idobata.io/")
|
41
|
+
end
|
42
|
+
|
43
|
+
memoize\
|
44
|
+
def idobata_pusher_key
|
45
|
+
ENV["IDOBATA_PUSHER_KEY"] || "44ffe67af1c7035be764"
|
46
|
+
end
|
47
|
+
|
48
|
+
memoize\
|
49
|
+
def idobata_api_token
|
50
|
+
ENV["IDOBATA_API_TOKEN"]
|
51
|
+
end
|
52
|
+
|
53
|
+
memoize\
|
54
|
+
def idobata_seed_url
|
55
|
+
URI.join(idobata_url, '/api/seed')
|
56
|
+
end
|
57
|
+
|
58
|
+
memoize\
|
59
|
+
def idobata_pusher_auth_url
|
60
|
+
URI.join(idobata_url, '/pusher/auth')
|
61
|
+
end
|
62
|
+
|
63
|
+
memoize\
|
64
|
+
def idobata_messages_url
|
65
|
+
URI.join(idobata_url, '/api/messages')
|
66
|
+
end
|
67
|
+
|
68
|
+
memoize\
|
69
|
+
def headers
|
70
|
+
{
|
71
|
+
'X-API-Token' => idobata_api_token,
|
72
|
+
'User-Agent' => "ruboty-idobata / v#{Ruboty::Idobata::VERSION}"
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
memoize\
|
77
|
+
def seed_json
|
78
|
+
idobata_seed_url.read(headers)
|
79
|
+
end
|
80
|
+
|
81
|
+
memoize\
|
82
|
+
def seed
|
83
|
+
JSON.parse(seed_json)
|
84
|
+
end
|
85
|
+
|
86
|
+
memoize\
|
87
|
+
def records
|
88
|
+
seed["records"]
|
89
|
+
end
|
90
|
+
|
91
|
+
memoize\
|
92
|
+
def bot
|
93
|
+
records["bot"]
|
94
|
+
end
|
95
|
+
|
96
|
+
memoize\
|
97
|
+
def channel_name
|
98
|
+
bot["channel_name"]
|
99
|
+
end
|
100
|
+
|
101
|
+
memoize\
|
102
|
+
def auth_payload
|
103
|
+
{
|
104
|
+
socket_id: socket_id,
|
105
|
+
channel_name: channel_name
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
memoize\
|
110
|
+
def authorize
|
111
|
+
req = Net::HTTP::Post.new(idobata_pusher_auth_url.path, headers)
|
112
|
+
req.form_data = auth_payload
|
113
|
+
https = Net::HTTP.new(idobata_pusher_auth_url.host, idobata_pusher_auth_url.port)
|
114
|
+
https.use_ssl = true
|
115
|
+
https.start {|https| https.request(req) }
|
116
|
+
end
|
117
|
+
|
118
|
+
memoize\
|
119
|
+
def pusher_auth_json
|
120
|
+
authorize.body
|
121
|
+
end
|
122
|
+
|
123
|
+
memoize\
|
124
|
+
def pusher_auth
|
125
|
+
JSON.parse pusher_auth_json
|
126
|
+
end
|
127
|
+
|
128
|
+
memoize\
|
129
|
+
def socket
|
130
|
+
PusherClient::Socket.new(idobata_pusher_key, encrypted: true)
|
131
|
+
end
|
132
|
+
|
133
|
+
memoize\
|
134
|
+
def connect
|
135
|
+
socket.connect
|
136
|
+
end
|
137
|
+
|
138
|
+
memoize\
|
139
|
+
def connected?
|
140
|
+
socket.connected
|
141
|
+
end
|
142
|
+
|
143
|
+
memoize\
|
144
|
+
def socket_id
|
145
|
+
socket.socket_id
|
146
|
+
end
|
147
|
+
|
148
|
+
memoize\
|
149
|
+
def channel
|
150
|
+
socket.channels.add(channel_name)
|
151
|
+
end
|
152
|
+
|
153
|
+
memoize\
|
154
|
+
def join_channel
|
155
|
+
socket.authorize_callback(channel, pusher_auth["auth"], pusher_auth["channel_data"])
|
156
|
+
end
|
157
|
+
|
158
|
+
memoize\
|
159
|
+
def listen
|
160
|
+
channel.bind('message_created') do |message_json|
|
161
|
+
message = JSON.parse(message_json)['message']
|
162
|
+
robot.receive(
|
163
|
+
body: message['body_plain'],
|
164
|
+
from: message['sender_id'],
|
165
|
+
from_name: message['sender_name'],
|
166
|
+
room_id: message['room_id'],
|
167
|
+
room_name: message['room_name']
|
168
|
+
)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
memoize\
|
173
|
+
def log_message
|
174
|
+
channel.bind('message_created') do |message_json|
|
175
|
+
pp JSON.parse message_json
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
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/idobata/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-idobata"
|
8
|
+
spec.version = Ruboty::Idobata::VERSION
|
9
|
+
spec.authors = ["Seiei Higa"]
|
10
|
+
spec.email = ["hanachin@gmail.com"]
|
11
|
+
spec.summary = %q{Idobata adapter for Ruboty.}
|
12
|
+
spec.homepage = "https://github.com/hanachin/ruboty-idobata"
|
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.add_dependency "ruboty", "~> 1.0.1"
|
21
|
+
spec.add_dependency "pusher-client", "~> 0.5.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-idobata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seiei Higa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-01 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: 1.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pusher-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hanachin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- images/screenshot.png
|
82
|
+
- lib/ruboty/adapters/idobata.rb
|
83
|
+
- lib/ruboty/idobata.rb
|
84
|
+
- lib/ruboty/idobata/version.rb
|
85
|
+
- ruboty-idobata.gemspec
|
86
|
+
homepage: https://github.com/hanachin/ruboty-idobata
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Idobata adapter for Ruboty.
|
110
|
+
test_files: []
|