ellen-idobata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87100d71109c12171b2cca34c3a95fbaf71f9dc9
4
+ data.tar.gz: eb7d4f55d7015f3911f8e4817326e9de25830313
5
+ SHA512:
6
+ metadata.gz: 408430b19c57eac1cb1745b032d07d1e335f4fd54c89a547a12ca6d4ae8c83c8d10b30d66bb73e25cb6f5cca3529c3b8b1430f21f214695de0783cec4cfebe28
7
+ data.tar.gz: 4140de10f168f5cb30fa140cb77516ae9b032d19669f42e0d3cb5dffde9a3be638116ee90a233af4e3e20303b5a7287a24f92d2f1d4d62443a4718f7c2afd876
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-idobata.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,33 @@
1
+ # Ellen::Idobata
2
+
3
+ Idobata adapter for [Ellen](https://github.com/r7kamura/ellen).
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 'ellen-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/ellen-idobata/master/images/screenshot.png)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/<my-github-username>/ellen-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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ellen/idobata/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ellen-idobata"
8
+ spec.version = Ellen::Idobata::VERSION
9
+ spec.authors = ["Seiei Higa"]
10
+ spec.email = ["hanachin@gmail.com"]
11
+ spec.summary = %q{Idobata adapter for Ellen.}
12
+ spec.homepage = "https://github.com/hanachin/ellen-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 "pusher-client", "~> 0.5.0"
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
Binary file
@@ -0,0 +1,174 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'pp'
5
+ require 'pusher-client'
6
+
7
+ module Ellen
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(source)
26
+ req = Net::HTTP::Post.new(idobata_messages_url.path, headers)
27
+ req.form_data = { 'message[room_id]' => @last_room_id, 'message[source]' => source }
28
+ https = Net::HTTP.new(idobata_messages_url.host, idobata_messages_url.port)
29
+ https.use_ssl = true
30
+ https.start {|https| https.request(req) }
31
+ end
32
+
33
+ def on_connection_established(&block)
34
+ socket.bind('pusher:connection_established', &block)
35
+ end
36
+
37
+ memoize\
38
+ def idobata_url
39
+ URI.parse(ENV["IDOBATA_URL"] || "https://idobata.io/")
40
+ end
41
+
42
+ memoize\
43
+ def idobata_pusher_key
44
+ ENV["IDOBATA_PUSHER_KEY"] || "44ffe67af1c7035be764"
45
+ end
46
+
47
+ memoize\
48
+ def idobata_api_token
49
+ ENV["IDOBATA_API_TOKEN"]
50
+ end
51
+
52
+ memoize\
53
+ def idobata_seed_url
54
+ URI.join(idobata_url, '/api/seed')
55
+ end
56
+
57
+ memoize\
58
+ def idobata_pusher_auth_url
59
+ URI.join(idobata_url, '/pusher/auth')
60
+ end
61
+
62
+ memoize\
63
+ def idobata_messages_url
64
+ URI.join(idobata_url, '/api/messages')
65
+ end
66
+
67
+ memoize\
68
+ def headers
69
+ {
70
+ 'X-API-Token' => idobata_api_token,
71
+ 'User-Agent' => "ellen-idobata / v#{Ellen::Idobata::VERSION}"
72
+ }
73
+ end
74
+
75
+ memoize\
76
+ def seed_json
77
+ idobata_seed_url.read(headers)
78
+ end
79
+
80
+ memoize\
81
+ def seed
82
+ JSON.parse(seed_json)
83
+ end
84
+
85
+ memoize\
86
+ def records
87
+ seed["records"]
88
+ end
89
+
90
+ memoize\
91
+ def bot
92
+ records["bot"]
93
+ end
94
+
95
+ memoize\
96
+ def channel_name
97
+ bot["channel_name"]
98
+ end
99
+
100
+ memoize\
101
+ def auth_payload
102
+ {
103
+ socket_id: socket_id,
104
+ channel_name: channel_name
105
+ }
106
+ end
107
+
108
+ memoize\
109
+ def authorize
110
+ req = Net::HTTP::Post.new(idobata_pusher_auth_url.path, headers)
111
+ req.form_data = auth_payload
112
+ https = Net::HTTP.new(idobata_pusher_auth_url.host, idobata_pusher_auth_url.port)
113
+ https.use_ssl = true
114
+ https.start {|https| https.request(req) }
115
+ end
116
+
117
+ memoize\
118
+ def pusher_auth_json
119
+ authorize.body
120
+ end
121
+
122
+ memoize\
123
+ def pusher_auth
124
+ JSON.parse pusher_auth_json
125
+ end
126
+
127
+ memoize\
128
+ def socket
129
+ PusherClient::Socket.new(idobata_pusher_key, encrypted: true)
130
+ end
131
+
132
+ memoize\
133
+ def connect
134
+ socket.connect
135
+ end
136
+
137
+ memoize\
138
+ def connected?
139
+ socket.connected
140
+ end
141
+
142
+ memoize\
143
+ def socket_id
144
+ socket.socket_id
145
+ end
146
+
147
+ memoize\
148
+ def channel
149
+ socket.channels.add(channel_name)
150
+ end
151
+
152
+ memoize\
153
+ def join_channel
154
+ socket.authorize_callback(channel, pusher_auth["auth"], pusher_auth["channel_data"])
155
+ end
156
+
157
+ memoize\
158
+ def listen
159
+ channel.bind('message_created') do |message_json|
160
+ message = JSON.parse(message_json)['message']
161
+ @last_room_id = message['room_id']
162
+ robot.receive(body: message['body_plain'])
163
+ end
164
+ end
165
+
166
+ memoize\
167
+ def log_message
168
+ channel.bind('message_created') do |message_json|
169
+ pp JSON.parse message_json
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,2 @@
1
+ require "ellen/adapters/idobata"
2
+ require "ellen/idobata/version"
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module Idobata
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-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-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pusher-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.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.5.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
+ - hanachin@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
+ - ellen-idobata.gemspec
68
+ - images/screenshot.png
69
+ - lib/ellen/adapters/idobata.rb
70
+ - lib/ellen/idobata.rb
71
+ - lib/ellen/idobata/version.rb
72
+ homepage: https://github.com/hanachin/ellen-idobata
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Idobata adapter for Ellen.
96
+ test_files: []