hiptail 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0e93d540b2f1571b8f569104d2e18f4d7e06821
4
+ data.tar.gz: 5fa982bc4db63b72ddc5d9332a88b6712813d16a
5
+ SHA512:
6
+ metadata.gz: 2cbabffdc336194845becc62302485913d814847ae763b371a03a1709e8326c841b43426af5e61833c0e5d8347c9a5772ddf071474111a45e0f4285d5bf555e4
7
+ data.tar.gz: b9f9bafe8438cbd34cfc9044c76c296aa70138b6919b2cf0b9814c10849775ab62d61a46841235cde8e3120301e1f6c018c04236d7fcfdf0284fbf87f683cf1f
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 dayflower
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,31 @@
1
+ # HipTail
2
+
3
+ HipChat Add-on Framework
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hiptail'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hiptail
20
+
21
+ ## Usage
22
+
23
+ See examples.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/dayflower/hiptail/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hiptail'
4
+ gem 'sqlite3' # for HipTail::SQLite3AuthorityProvider
5
+ gem 'sinatra'
@@ -0,0 +1,9 @@
1
+ # Sinatra Integration Example with HipTail
2
+
3
+ ## Installation
4
+
5
+ $ bundle install
6
+ $ bundle exec -- rackup
7
+
8
+ Then install this add-on on integrations page in HipChat administration page.
9
+ Specify the application capability URL (e.g. http://example.com:4567/cap).
@@ -0,0 +1,58 @@
1
+ require 'sinatra'
2
+ require 'hiptail'
3
+ require 'hiptail/authority/sqlite3_provider'
4
+ require 'sqlite3'
5
+
6
+ db = SQLite3::Database.new('hiptail.db')
7
+
8
+ manager = HipTail::Manager.new(:authority_provider => HipTail::SQLite3AuthorityProvider.new(db))
9
+
10
+ manager.on_room_message do |event|
11
+ message = event.message.message
12
+ if message =~ %r{(yellow|green|red|purple|gray)}xm
13
+ color = $1
14
+ else
15
+ color = 'random'
16
+ end
17
+
18
+ event.authority.send_notification(
19
+ :room_id => event.room.id,
20
+ :color => color,
21
+ :message => message,
22
+ :notify => true,
23
+ :message_format => 'text',
24
+ )
25
+ end
26
+
27
+ handler = HipTail::Web::Handler.new(manager)
28
+
29
+ get '/' do
30
+ 'Hello, World!'
31
+ end
32
+
33
+ get '/cap' do
34
+ capability_params = {
35
+ :key => "com.example.hiptail.sinatra",
36
+ :name => "Colorizer",
37
+ :vendor_name => "hiptail",
38
+ :message_filter => "(yellow|green|red|purple|gray)",
39
+ :base_path => "/",
40
+ :capability_path => "/cap",
41
+ :webhook_path => "/event",
42
+ :installed_path => "/install",
43
+ }
44
+
45
+ handler.handle_capability(request, capability_params)
46
+ end
47
+
48
+ post '/install' do
49
+ handler.handle_install(request)
50
+ end
51
+
52
+ delete '/install/:oauth_id' do
53
+ handler.handle_uninstall(request, params[:oauth_id])
54
+ end
55
+
56
+ post '/event' do
57
+ handler.handle_event(request)
58
+ end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hiptail'
4
+ gem 'sqlite3' # for HipTail::SQLite3AuthorityProvider
@@ -0,0 +1,9 @@
1
+ # Simple Rack Application Example with HipTail
2
+
3
+ ## Installation
4
+
5
+ $ bundle install
6
+ $ bundle exec -- rackup
7
+
8
+ Then install this add-on on integrations page in HipChat administration page.
9
+ Specify the application capability URL (e.g. http://example.com:9292/cap).
@@ -0,0 +1,56 @@
1
+ require 'bundler/setup'
2
+ require 'rack'
3
+ require 'hiptail'
4
+ require 'hiptail/authority/sqlite3_provider'
5
+ require 'sqlite3'
6
+
7
+ db = SQLite3::Database.new('hiptail.db')
8
+
9
+ manager = HipTail::Manager.new(:authority_provider => HipTail::SQLite3AuthorityProvider.new(db))
10
+
11
+ manager.on_install do |authority|
12
+ if authority.global?
13
+ authority.get_all_rooms.rooms.each do |room|
14
+ authority.send_notification(
15
+ :room_id => room.id,
16
+ :message => "Installed.",
17
+ :notify => false,
18
+ :message_format => 'text',
19
+ )
20
+ end
21
+ else
22
+ authority.send_notification(
23
+ :room_id => authority.room_id,
24
+ :message => "Installed.",
25
+ :notify => false,
26
+ :message_format => 'text',
27
+ )
28
+ end
29
+ end
30
+
31
+ manager.on_room_message do |event|
32
+ event.authority.send_notification(
33
+ :room_id => event.room.id,
34
+ :color => 'green',
35
+ :message => event.message.message.reverse,
36
+ :notify => true,
37
+ :message_format => 'text',
38
+ )
39
+ end
40
+
41
+ manager.on_room_enter do |event|
42
+ event.authority.send_notification(
43
+ :room_id => event.room.id,
44
+ :color => 'red',
45
+ :message => "Welcome, @#{event.sender.mention_name}!",
46
+ :notify => true,
47
+ :message_format => "text",
48
+ )
49
+ end
50
+
51
+ run HipTail::Web::RackApp.new(
52
+ :manager => manager,
53
+ :key => "com.example.hiptail.simple1",
54
+ :name => "Mr. Reverse",
55
+ :vendor_name => "hiptail",
56
+ )
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hiptail'
4
+ gem 'sqlite3' # for HipTail::SQLite3AuthorityProvider
@@ -0,0 +1,9 @@
1
+ # Simple Rack Application Example with HipTail
2
+
3
+ ## Installation
4
+
5
+ $ bundle install
6
+ $ bundle exec -- rackup
7
+
8
+ Then install this add-on on integrations page in HipChat administration page.
9
+ Specify the application capability URL (e.g. http://example.com:9292/cap).
@@ -0,0 +1,42 @@
1
+ require 'hiptail'
2
+ require 'hiptail/authority/sqlite3_provider'
3
+ require 'sqlite3'
4
+
5
+ class SimpleAddon2 < HipTail::Web::RackApp
6
+ def initialize
7
+ super(
8
+ :manager => setup_manager(),
9
+ :key => "com.example.hiptail.simple2",
10
+ :name => "Colorizer",
11
+ :vendor_name => "hiptail",
12
+ :message_filter => "(yellow|green|red|purple|gray)",
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ def setup_manager
19
+ db = SQLite3::Database.new('hiptail.db')
20
+
21
+ manager = HipTail::Manager.new(:authority_provider => HipTail::SQLite3AuthorityProvider.new(db))
22
+
23
+ manager.on_room_message do |event|
24
+ message = event.message.message
25
+ if message =~ %r{(yellow|green|red|purple|gray)}xm
26
+ color = $1
27
+ else
28
+ color = 'random'
29
+ end
30
+
31
+ event.authority.send_notification(
32
+ :room_id => event.room.id,
33
+ :color => color,
34
+ :message => message,
35
+ :notify => true,
36
+ :message_format => 'text',
37
+ )
38
+ end
39
+
40
+ manager
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ require 'rack'
2
+ require './app.rb'
3
+
4
+ run SimpleAddon2.new()
data/hiptail.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hiptail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hiptail"
8
+ spec.version = HipTail::VERSION
9
+ spec.authors = ["ITO Nobuaki"]
10
+ spec.email = ["daydream.trippers@gmail.com"]
11
+ spec.summary = %q{HipChat Add-on Framework}
12
+ spec.description = %q{HipChat Add-on Framework}
13
+ spec.homepage = "https://github.com/dayflower/hiptail"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = %w[
17
+ hiptail.gemspec
18
+ README.md
19
+ LICENSE.txt
20
+ Gemfile
21
+ Rakefile
22
+ lib/hiptail.rb
23
+ lib/hiptail/atom.rb
24
+ lib/hiptail/authority.rb
25
+ lib/hiptail/authority/provider.rb
26
+ lib/hiptail/authority/sqlite3_provider.rb
27
+ lib/hiptail/event.rb
28
+ lib/hiptail/manager.rb
29
+ lib/hiptail/web/handler.rb
30
+ lib/hiptail/web/rack_app.rb
31
+ lib/hiptail/util.rb
32
+ lib/hiptail/version.rb
33
+ examples/simple_rack_app_1/Gemfile
34
+ examples/simple_rack_app_1/config.ru
35
+ examples/simple_rack_app_1/README.md
36
+ examples/simple_rack_app_2/Gemfile
37
+ examples/simple_rack_app_2/app.rb
38
+ examples/simple_rack_app_2/config.ru
39
+ examples/simple_rack_app_2/README.md
40
+ examples/integrate_sinatra/Gemfile
41
+ examples/integrate_sinatra/app.rb
42
+ examples/integrate_sinatra/README.md
43
+ ]
44
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
45
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
46
+ spec.require_paths = ["lib"]
47
+
48
+ spec.add_dependency "rack"
49
+ spec.add_dependency "oauth2"
50
+
51
+ spec.add_development_dependency "bundler", "~> 1.7"
52
+ spec.add_development_dependency "rake", "~> 10.0"
53
+ end
@@ -0,0 +1,303 @@
1
+ require 'time'
2
+
3
+ module HipTail
4
+ class User
5
+ attr_reader :raw
6
+
7
+ # @return [HipTail::User]
8
+ def initialize(params)
9
+ @raw = params.dup
10
+ end
11
+
12
+ class << self
13
+ # @return [HipTail::User]
14
+ def create(params)
15
+ if params.is_a?(String)
16
+ return User::Notify.new({ :name => params })
17
+ else
18
+ return User::Person.new(params)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ class User::Notify < User
25
+ # @attribute [r] name
26
+ # @return [String]
27
+ def name
28
+ @raw['name']
29
+ end
30
+ end
31
+
32
+ class User::Person < User
33
+ # @attribute [r] id
34
+ # @return [String]
35
+ def id
36
+ @raw['id']
37
+ end
38
+
39
+ # @attribute [r] mention_name
40
+ # @return [String]
41
+ def mention_name
42
+ @raw['mention_name']
43
+ end
44
+
45
+ # @attribute [r] name
46
+ # @return [String]
47
+ def name
48
+ @raw['name']
49
+ end
50
+ end
51
+
52
+ class Message
53
+ attr_reader :raw
54
+
55
+ def initialize(params)
56
+ @raw = params.dup
57
+ end
58
+
59
+ # @attribute [r] id
60
+ # @return [String]
61
+ def id
62
+ @raw['id']
63
+ end
64
+
65
+ # @attribute [r] date
66
+ # @return [Time]
67
+ def date
68
+ @date ||= Time.parse(@raw['date'])
69
+ @date
70
+ end
71
+
72
+ # @attribute [r] from
73
+ # @return [HipTail::User]
74
+ def from
75
+ @from ||= User.create(@raw['from'])
76
+ @from
77
+ end
78
+
79
+ # @attribute [r] mentions
80
+ # @return [Array] Array of HipTail::User.
81
+ def mentions
82
+ @mentions ||= (@raw['mentions'] || []).map { |data| User.create(data) }
83
+ @mentions
84
+ end
85
+
86
+ # @attribute [r] message
87
+ # @return [String]
88
+ def message
89
+ @raw['message']
90
+ end
91
+
92
+ # @attribute [r] text
93
+ # @return [String]
94
+ def text
95
+ message
96
+ end
97
+
98
+ # @attribute [r] is_talk?
99
+ def is_talk?
100
+ false
101
+ end
102
+
103
+ # @attribute [r] is_notification?
104
+ def is_notification?
105
+ false
106
+ end
107
+ end
108
+
109
+ class Message::Talk < Message
110
+ def is_talk?; true; end
111
+ def is_notification?; false; end
112
+ end
113
+
114
+ class Message::Notification < Message
115
+ def is_talk?; false; end
116
+ def is_notification?; true; end
117
+
118
+ # @attribute [r] message_format
119
+ # @return [String]
120
+ def message_format
121
+ @raw['message_format']
122
+ end
123
+
124
+ # @attribute [r] is_text?
125
+ # @return [Boolean]
126
+ def is_text?
127
+ message_format == 'text'
128
+ end
129
+
130
+ # @attribute [r] is_html?
131
+ # @return [Boolean]
132
+ def is_html?
133
+ message_format == 'html'
134
+ end
135
+
136
+ # @attribute [r] html?
137
+ # @return [String]
138
+ def html
139
+ message
140
+ end
141
+
142
+ # @attribute [r] color
143
+ # @return [String]
144
+ def color
145
+ @raw['color']
146
+ end
147
+ end
148
+
149
+ class Room
150
+ attr_reader :raw
151
+
152
+ def initialize(params)
153
+ @raw = params.dup
154
+ end
155
+
156
+ def detailed?
157
+ false
158
+ end
159
+
160
+ # @attribute [r] id
161
+ # @return [String]
162
+ def id
163
+ @raw['id']
164
+ end
165
+
166
+ # @attribute [r] name
167
+ # @return [String]
168
+ def name
169
+ @raw['name']
170
+ end
171
+ end
172
+
173
+ class Room::Detail < Room
174
+ # @attribute [r] created
175
+ # @return [Time]
176
+ def created
177
+ @created ||= Time.parse(@raw['created'])
178
+ @created
179
+ end
180
+
181
+ # @attribute [r] last_active
182
+ # @return [Time]
183
+ def last_active
184
+ @last_active ||= Time.parse(@raw['last_active'])
185
+ @last_active
186
+ end
187
+
188
+ # @attribute [r] privacy
189
+ # @return [String]
190
+ def privacy
191
+ @raw['privacy']
192
+ end
193
+
194
+ # @attribute [r] is_public
195
+ # @return [Boolean]
196
+ def is_public
197
+ privacy == 'public'
198
+ end
199
+ alias public? is_public
200
+
201
+ # @attribute [r] is_private
202
+ # @return [Boolean]
203
+ def is_private
204
+ privacy == 'private'
205
+ end
206
+ alias private? is_private
207
+
208
+ # @attribute [r] is_archived
209
+ # @return [Boolean]
210
+ def is_archived
211
+ @raw['is_archived']
212
+ end
213
+ alias archived? is_archived
214
+
215
+ # @attribute [r] is_guest_accessible
216
+ # @return [Boolean]
217
+ def is_guest_accessible
218
+ @raw['is_guest_accessible']
219
+ end
220
+ alias guest_accessible? is_guest_accessible
221
+
222
+ # @attribute [r] guest_access_url
223
+ # @return [String]
224
+ def guest_access_url
225
+ @raw['guest_access_url']
226
+ end
227
+
228
+ # @attribute [r] owner
229
+ # @return [User]
230
+ def owner
231
+ @owner ||= User.new(@raw['owner'])
232
+ end
233
+
234
+ # @attribute [r] participants
235
+ # @return [Array] Array of HipTail::User.
236
+ def participants
237
+ @participants ||= @raw['participants'].map { |user| User.new(user) }
238
+ @participants
239
+ end
240
+
241
+ # @attribute [r] topic
242
+ # @return [String]
243
+ def topic
244
+ @raw['topic']
245
+ end
246
+
247
+ # @attribute [r] xmpp_jid
248
+ # @return [String]
249
+ def xmpp_jid
250
+ @raw['xmpp_jid']
251
+ end
252
+ end
253
+
254
+ class Rooms
255
+ attr_reader :raw
256
+
257
+ def initialize(params)
258
+ @raw = params.dup
259
+ end
260
+
261
+ # @attribute [r] rooms
262
+ # @return [Array] Array of HipTail::Room.
263
+ def rooms
264
+ @rooms ||= @raw['items'].map { |item| Room.new(item) }
265
+ @rooms
266
+ end
267
+
268
+ # @attribute [r] start_index
269
+ def start_index
270
+ @raw['startIndex']
271
+ end
272
+
273
+ # @attribute [r] max_results
274
+ def max_results
275
+ @raw['maxResults']
276
+ end
277
+ end
278
+
279
+ class Users
280
+ attr_reader :raw
281
+
282
+ def initialize(params)
283
+ @raw = params.dup
284
+ end
285
+
286
+ # @attribute [r] users
287
+ # @return [Array] Array of HipTail::User.
288
+ def users
289
+ @users ||= @raw['items'].map { |item| User.new(item) }
290
+ @users
291
+ end
292
+
293
+ # @attribute [r] start_index
294
+ def start_index
295
+ @raw['startIndex']
296
+ end
297
+
298
+ # @attribute [r] max_results
299
+ def max_results
300
+ @raw['maxResults']
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,65 @@
1
+ module HipTail
2
+ # @abstract
3
+ class AuthorityProvider
4
+ # @param [String] oauth_id
5
+ # @return [HipTail::Authority]
6
+ def [](oauth_id)
7
+ get(oauth_id)
8
+ end
9
+
10
+ # @param [String] oauth_id
11
+ # @param [HipTail::Authority] authority
12
+ # @return [HipTail::Authority]
13
+ def []=(oauth_id, authority)
14
+ register(oauth_id, authority)
15
+ end
16
+
17
+ # @abstract
18
+ # @param [String] oauth_id
19
+ # @return [HipTail::Authority]
20
+ def get(oauth_id)
21
+ raise
22
+ end
23
+
24
+ # @abstract
25
+ # @param [String] oauth_id
26
+ # @param [HipTail::Authority] authority
27
+ # @return [HipTail::Authority]
28
+ def register(oauth_id, authority)
29
+ raise
30
+ end
31
+
32
+ # @abstract
33
+ # @param [String] oauth_id
34
+ # @return [void]
35
+ def unregister(oauth_id)
36
+ raise
37
+ end
38
+ end
39
+
40
+ class MemoryAuthorityProvider < AuthorityProvider
41
+ # @return [HipTail::MemoryAuthorityProvider]
42
+ def initialize
43
+ @authorities = {}
44
+ end
45
+
46
+ # @param [String] oauth_id
47
+ # @return [HipTail::Authority]
48
+ def get(oauth_id)
49
+ @authorities[oauth_id]
50
+ end
51
+
52
+ # @param [String] oauth_id
53
+ # @param [HipTail::Authority] authority
54
+ # @return [HipTail::Authority]
55
+ def register(oauth_id, authority)
56
+ @authorities[oauth_id] = authority
57
+ end
58
+
59
+ # @param [String] oauth_id
60
+ # @return [void]
61
+ def unregister(oauth_id)
62
+ @authorities.delete(oauth_id)
63
+ end
64
+ end
65
+ end