lita-idobata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16f6fb191d180668394fbe402bfdcd9c357d2e50
4
+ data.tar.gz: 08c5745e43e0c6be961f0ed929dbf7c66ac60312
5
+ SHA512:
6
+ metadata.gz: 1fe353614331e7ffa523a1677ecbe651c9a630cc6d6786bbdde6098995c8d84205ce2897632d5f60473fcbf8ee08750b5e480d2e1b3b55e846e8401c3c005312
7
+ data.tar.gz: 90590590d3273ef73755259e3dea2eb0f36afe6f7e0acb150b1196b689e018fb6975f1916e87cf01f9947cc4c738b50776898ddffb6ace230d35c29a4972534b
data/.gitignore ADDED
@@ -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 lita-idobata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 fukayatsu
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,49 @@
1
+ # lita-idobata
2
+
3
+ **lita-idobata** is an adapter for [Lita](https://github.com/jimmycuadra/lita) that allows you to use the robot with [Idobata](https://idobata.io).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lita-idobata'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install lita-idobata
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ # Gemfile of your lita
23
+
24
+ source "https://rubygems.org"
25
+
26
+ gem 'lita', '~> 3.1.0'
27
+ gem "lita-idobata", github: 'fukayatsu/lita-idobata'
28
+ gem "pusher-client", github: 'pusher/pusher-ruby-client'
29
+ ...
30
+ ```
31
+
32
+ ```ruby
33
+ # lita_config.rb
34
+
35
+ Lita.configure do |config|
36
+ config.robot.name = "your-bot-name"
37
+ config.robot.log_level = :info
38
+ config.robot.adapter = :idobata
39
+ config.adapter.api_token = '123456abcd***'
40
+ end
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/fukayatsu/lita-idobata/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "lita/idobata/version"
2
+ require "lita/adapters/idobata"
@@ -0,0 +1,67 @@
1
+ require 'lita'
2
+ require 'lita/adapters/idobata/connector'
3
+
4
+ module Lita
5
+ module Adapters
6
+ class Idobata < Adapter
7
+ require_configs :api_token
8
+
9
+ def initialize(robot)
10
+ super
11
+ @connector = Connector.new(robot,
12
+ api_token: config.api_token,
13
+ pusher_key: pusher_key,
14
+ idobata_url: idobata_url,
15
+ debug: debug,
16
+ )
17
+ end
18
+ attr_reader :connector
19
+
20
+ # Idobata does not support these methods.
21
+ def join; end
22
+ def part; end
23
+ def set_topic; end
24
+
25
+ def send_messages(target, strings)
26
+ connector.message(target, strings)
27
+ end
28
+
29
+ def run
30
+ connector.connect
31
+ robot.trigger(:connected)
32
+ sleep
33
+ rescue Interrupt
34
+ shut_down
35
+ end
36
+
37
+ def shut_down
38
+ connector.shut_down
39
+ robot.trigger(:disconnected)
40
+ end
41
+
42
+ def mention_format(name)
43
+ "@#{name}"
44
+ end
45
+
46
+ private
47
+
48
+ def config
49
+ Lita.config.adapter
50
+ end
51
+
52
+ def debug
53
+ config.debug || false
54
+ end
55
+
56
+ def pusher_key
57
+ config.pusher_key || '44ffe67af1c7035be764'
58
+ end
59
+
60
+ def idobata_url
61
+ config.idobata_url || 'https://idobata.io'
62
+ end
63
+ end
64
+
65
+ Lita.register_adapter(:idobata, Idobata)
66
+ end
67
+ end
@@ -0,0 +1,88 @@
1
+ # require 'lita/acapters/idobata/callback'
2
+
3
+ require "lita/idobata/version"
4
+ require 'pusher-client'
5
+ require 'faraday'
6
+ require 'json'
7
+
8
+ module Lita
9
+ module Adapters
10
+ class Idobata < Adapter
11
+ class Connector
12
+ attr_reader :robot, :client, :roster
13
+
14
+ def initialize(robot, api_token: nil, pusher_key: nil, idobata_url: nil, debug: false)
15
+ @robot = robot
16
+ @api_token = api_token
17
+ @pusher_key = pusher_key
18
+ @idobata_url = idobata_url
19
+ @debug = debug
20
+ Lita.logger.info("Enabling log.") if @debug
21
+ end
22
+
23
+ def connect
24
+ raise "api_token is requeired." unless @api_token
25
+
26
+ response = http_client.get '/api/seed'
27
+ seed = JSON.parse(response.body)
28
+ @bot = seed['records']['bot']
29
+ channel_name = @bot['channel_name']
30
+
31
+ options = {
32
+ encrypted: !!@idobata_url.match(/^https/),
33
+ auth_method: auth_method
34
+ }
35
+ socket = PusherClient::Socket.new(@pusher_key, options)
36
+ socket.connect(true)
37
+ socket.bind('pusher:connection_established') do |data|
38
+ socket_id = JSON.parse(data)['socket_id'] # HACK
39
+ socket.subscribe(channel_name, socket_id)
40
+ end
41
+
42
+ socket.bind('message_created') do |data|
43
+ message = JSON.parse(data)["message"]
44
+ if message["sender_id"] != @bot['id']
45
+ user = User.new(message["sender_id"], name: message["sender_name"])
46
+ source = Source.new(user: user, room: message["room_id"])
47
+ message = Message.new(robot, message["body_plain"], source)
48
+ robot.receive(message)
49
+ end
50
+ end
51
+ end
52
+
53
+ def message(target, strings)
54
+ http_client.post '/api/messages', {
55
+ 'message[room_id]' => target.room,
56
+ 'message[source]' => strings.join("\n")
57
+ }
58
+ end
59
+
60
+ def rooms
61
+ end
62
+
63
+ def shut_down
64
+ end
65
+
66
+ private
67
+
68
+ def auth_method
69
+ -> (socket_id, channel) {
70
+ response = http_client.post "/pusher/auth", { channel_name: channel.name, socket_id: socket_id }
71
+ json = JSON.parse(response.body)
72
+ json["auth"]
73
+ }
74
+ end
75
+
76
+ def http_client
77
+ @conn ||= Faraday.new(url: @idobata_url) do |faraday|
78
+ faraday.request :url_encoded # form-encode POST params
79
+ faraday.response :logger # log requests to STDOUT
80
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
81
+ faraday.headers['X-API-Token'] = @api_token
82
+ faraday.headers['User-Agent'] = "lita-idobata / v#{Lita::Idobata::VERSION}"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,5 @@
1
+ module Lita
2
+ module Idobata
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lita/idobata/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lita-idobata"
8
+ spec.version = Lita::Idobata::VERSION
9
+ spec.authors = ["fukayatsu"]
10
+ spec.email = ["fukayatsu@gmail.com"]
11
+ spec.summary = %q{A Idobata adapter for Lita.}
12
+ spec.description = %q{A Idobata adapter for the Lita chat robot.}
13
+ spec.homepage = "https://github.com/fukayatsu/lita-idobata"
14
+ spec.license = "MIT"
15
+ spec.metadata = { "lita_plugin_type" => "adapter" }
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "lita", ">= 2.5"
23
+ spec.add_runtime_dependency 'faraday', '~> 0.9.0'
24
+ spec.add_runtime_dependency 'pusher-client', '~> 0.5.0'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "coveralls"
31
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-idobata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fukayatsu
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: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.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.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pusher-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.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.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0.beta2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0.beta2
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A Idobata adapter for the Lita chat robot.
126
+ email:
127
+ - fukayatsu@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - lib/lita-idobata.rb
138
+ - lib/lita/adapters/idobata.rb
139
+ - lib/lita/adapters/idobata/connector.rb
140
+ - lib/lita/idobata/version.rb
141
+ - lita-idobata.gemspec
142
+ homepage: https://github.com/fukayatsu/lita-idobata
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ lita_plugin_type: adapter
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.2.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: A Idobata adapter for Lita.
167
+ test_files: []