slack-ruby-bot-server 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -9
  3. data/CHANGELOG.md +7 -1
  4. data/Gemfile +16 -0
  5. data/README.md +31 -4
  6. data/UPGRADING.md +25 -0
  7. data/lib/slack-ruby-bot-server.rb +6 -5
  8. data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +1 -1
  9. data/lib/slack-ruby-bot-server/api/helpers/cursor_helpers.rb +31 -18
  10. data/lib/slack-ruby-bot-server/api/helpers/error_helpers.rb +12 -10
  11. data/lib/slack-ruby-bot-server/api/helpers/sort_helpers.rb +5 -1
  12. data/lib/slack-ruby-bot-server/api/middleware.rb +6 -1
  13. data/lib/slack-ruby-bot-server/api/presenters/status_presenter.rb +7 -3
  14. data/lib/slack-ruby-bot-server/app.rb +4 -23
  15. data/lib/slack-ruby-bot-server/config.rb +16 -0
  16. data/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb +27 -0
  17. data/lib/slack-ruby-bot-server/config/database_adapters/mongoid.rb +24 -0
  18. data/lib/slack-ruby-bot-server/models/team/activerecord.rb +13 -0
  19. data/lib/slack-ruby-bot-server/models/team/methods.rb +55 -0
  20. data/lib/slack-ruby-bot-server/models/team/mongoid.rb +22 -0
  21. data/lib/slack-ruby-bot-server/version.rb +1 -1
  22. data/sample_apps/README.md +11 -0
  23. data/{sample_app → sample_apps/sample_app_activerecord}/.rspec +0 -0
  24. data/sample_apps/sample_app_activerecord/.standalone_migrations +3 -0
  25. data/sample_apps/sample_app_activerecord/Gemfile +23 -0
  26. data/{sample_app → sample_apps/sample_app_activerecord}/Procfile +0 -0
  27. data/sample_apps/sample_app_activerecord/README.md +11 -0
  28. data/sample_apps/sample_app_activerecord/Rakefile +13 -0
  29. data/{sample_app → sample_apps/sample_app_activerecord}/commands.rb +0 -0
  30. data/{sample_app → sample_apps/sample_app_activerecord}/commands/help.rb +0 -0
  31. data/{sample_app → sample_apps/sample_app_activerecord}/commands/whoami.rb +0 -0
  32. data/sample_apps/sample_app_activerecord/config.ru +21 -0
  33. data/{sample_app → sample_apps/sample_app_activerecord}/config/newrelic.yml +0 -0
  34. data/sample_apps/sample_app_activerecord/config/postgresql.yml +17 -0
  35. data/sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb +13 -0
  36. data/sample_apps/sample_app_activerecord/db/schema.rb +26 -0
  37. data/sample_apps/sample_app_activerecord/spec/api/root_spec.rb +16 -0
  38. data/{sample_app → sample_apps/sample_app_activerecord}/spec/commands/help_spec.rb +0 -0
  39. data/{sample_app → sample_apps/sample_app_activerecord}/spec/commands/whoami_spec.rb +0 -0
  40. data/sample_apps/sample_app_activerecord/spec/spec_helper.rb +19 -0
  41. data/sample_apps/sample_app_mongoid/.rspec +3 -0
  42. data/{sample_app → sample_apps/sample_app_mongoid}/Gemfile +6 -1
  43. data/sample_apps/sample_app_mongoid/Procfile +1 -0
  44. data/{sample_app → sample_apps/sample_app_mongoid}/README.md +13 -0
  45. data/{sample_app → sample_apps/sample_app_mongoid}/Rakefile +0 -0
  46. data/sample_apps/sample_app_mongoid/commands.rb +2 -0
  47. data/sample_apps/sample_app_mongoid/commands/help.rb +19 -0
  48. data/sample_apps/sample_app_mongoid/commands/whoami.rb +6 -0
  49. data/{sample_app → sample_apps/sample_app_mongoid}/config.ru +0 -0
  50. data/{sample_app → sample_apps/sample_app_mongoid}/config/mongoid.yml +0 -0
  51. data/sample_apps/sample_app_mongoid/config/newrelic.yml +217 -0
  52. data/sample_apps/sample_app_mongoid/spec/api/root_spec.rb +16 -0
  53. data/sample_apps/sample_app_mongoid/spec/commands/help_spec.rb +14 -0
  54. data/sample_apps/sample_app_mongoid/spec/commands/whoami_spec.rb +14 -0
  55. data/{sample_app → sample_apps/sample_app_mongoid}/spec/spec_helper.rb +2 -0
  56. data/slack-ruby-bot-server.gemspec +1 -5
  57. metadata +43 -76
  58. data/lib/slack-ruby-bot-server/models/team.rb +0 -68
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ def app
4
+ SlackRubyBotServer::Api::Middleware.instance
5
+ end
6
+
7
+ describe 'API' do
8
+ include Rack::Test::Methods
9
+
10
+ it 'root' do
11
+ get '/api'
12
+ expect(last_response.status).to eq 200
13
+ links = JSON.parse(last_response.body)['_links']
14
+ expect(links.keys.sort).to eq(%w(self status team teams).sort)
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'commands/help'
3
+
4
+ describe Help do
5
+ let!(:team) { Fabricate(:team) }
6
+ let(:app) { SlackRubyBotServer::Server.new(team: team) }
7
+ let(:client) { app.send(:client) }
8
+ let(:message_hook) { SlackRubyBot::Hooks::Message.new }
9
+ it 'default' do
10
+ expect(client).to receive(:say).with(channel: 'channel', text: [Help::HELP, SlackRubyBotServer::INFO].join("\n"))
11
+ expect(client).to receive(:say).with(channel: 'channel', gif: 'help')
12
+ message_hook.call(client, Hashie::Mash.new(channel: 'channel', text: "#{SlackRubyBot.config.user} help"))
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'commands/whoami'
3
+
4
+ describe Whoami do
5
+ let(:team) { Fabricate(:team) }
6
+ let(:app) { SlackRubyBotServer::Server.new(team: team) }
7
+ context 'whoami' do
8
+ it 'returns username' do
9
+ expect(message: "#{SlackRubyBot.config.user} whoami", channel: 'channel', user: 'user').to respond_with_slack_message(
10
+ '<@user>'
11
+ )
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,8 @@ $LOAD_PATH.unshift File.expand_path('..', __dir__)
2
2
 
3
3
  ENV['RACK_ENV'] = 'test'
4
4
 
5
+ require 'mongoid'
6
+ require 'database_cleaner'
5
7
  require 'slack-ruby-bot-server/rspec'
6
8
 
7
9
  Mongoid.load!(File.expand_path('../config/mongoid.yml', __dir__), ENV['RACK_ENV'])
@@ -17,16 +17,12 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.add_dependency 'slack-ruby-bot'
19
19
  spec.add_dependency 'celluloid-io'
20
- spec.add_dependency 'mongoid'
21
20
  spec.add_dependency 'unicorn'
22
21
  spec.add_dependency 'grape'
23
22
  spec.add_dependency 'grape-swagger'
24
- spec.add_dependency 'roar', '~> 1.0.4'
25
- spec.add_dependency 'grape-roar'
23
+ spec.add_dependency 'grape-roar', '>= 0.4.0'
26
24
  spec.add_dependency 'rack-cors'
27
- spec.add_dependency 'kaminari-mongoid'
28
25
  spec.add_dependency 'kaminari-grape'
29
- spec.add_dependency 'mongoid-scroll'
30
26
  spec.add_dependency 'rack-rewrite'
31
27
  spec.add_dependency 'rack-server-pages'
32
28
  spec.add_dependency 'foreman'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-bot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-bot
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: mongoid
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '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'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: unicorn
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,34 +80,20 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: roar
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.0.4
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.0.4
111
83
  - !ruby/object:Gem::Dependency
112
84
  name: grape-roar
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
116
88
  - !ruby/object:Gem::Version
117
- version: '0'
89
+ version: 0.4.0
118
90
  type: :runtime
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
94
  - - ">="
123
95
  - !ruby/object:Gem::Version
124
- version: '0'
96
+ version: 0.4.0
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: rack-cors
127
99
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +108,6 @@ dependencies:
136
108
  - - ">="
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: kaminari-mongoid
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
111
  - !ruby/object:Gem::Dependency
154
112
  name: kaminari-grape
155
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +122,6 @@ dependencies:
164
122
  - - ">="
165
123
  - !ruby/object:Gem::Version
166
124
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: mongoid-scroll
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :runtime
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
125
  - !ruby/object:Gem::Dependency
182
126
  name: rack-rewrite
183
127
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +211,8 @@ files:
267
211
  - lib/slack-ruby-bot-server/api/presenters/teams_presenter.rb
268
212
  - lib/slack-ruby-bot-server/app.rb
269
213
  - lib/slack-ruby-bot-server/config.rb
214
+ - lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb
215
+ - lib/slack-ruby-bot-server/config/database_adapters/mongoid.rb
270
216
  - lib/slack-ruby-bot-server/ext.rb
271
217
  - lib/slack-ruby-bot-server/ext/bson/object_id.rb
272
218
  - lib/slack-ruby-bot-server/ext/grape/sort_extension.rb
@@ -275,7 +221,9 @@ files:
275
221
  - lib/slack-ruby-bot-server/ext/slack-ruby-bot/commands/base.rb
276
222
  - lib/slack-ruby-bot-server/info.rb
277
223
  - lib/slack-ruby-bot-server/models.rb
278
- - lib/slack-ruby-bot-server/models/team.rb
224
+ - lib/slack-ruby-bot-server/models/team/activerecord.rb
225
+ - lib/slack-ruby-bot-server/models/team/methods.rb
226
+ - lib/slack-ruby-bot-server/models/team/mongoid.rb
279
227
  - lib/slack-ruby-bot-server/rspec.rb
280
228
  - lib/slack-ruby-bot-server/rspec/fabricators/team.rb
281
229
  - lib/slack-ruby-bot-server/server.rb
@@ -289,21 +237,40 @@ files:
289
237
  - public/scripts/register.js
290
238
  - public/scripts/stats.js
291
239
  - public/scripts/url.min.js
292
- - sample_app/.env
293
- - sample_app/.rspec
294
- - sample_app/Gemfile
295
- - sample_app/Procfile
296
- - sample_app/README.md
297
- - sample_app/Rakefile
298
- - sample_app/commands.rb
299
- - sample_app/commands/help.rb
300
- - sample_app/commands/whoami.rb
301
- - sample_app/config.ru
302
- - sample_app/config/mongoid.yml
303
- - sample_app/config/newrelic.yml
304
- - sample_app/spec/commands/help_spec.rb
305
- - sample_app/spec/commands/whoami_spec.rb
306
- - sample_app/spec/spec_helper.rb
240
+ - sample_apps/README.md
241
+ - sample_apps/sample_app_activerecord/.rspec
242
+ - sample_apps/sample_app_activerecord/.standalone_migrations
243
+ - sample_apps/sample_app_activerecord/Gemfile
244
+ - sample_apps/sample_app_activerecord/Procfile
245
+ - sample_apps/sample_app_activerecord/README.md
246
+ - sample_apps/sample_app_activerecord/Rakefile
247
+ - sample_apps/sample_app_activerecord/commands.rb
248
+ - sample_apps/sample_app_activerecord/commands/help.rb
249
+ - sample_apps/sample_app_activerecord/commands/whoami.rb
250
+ - sample_apps/sample_app_activerecord/config.ru
251
+ - sample_apps/sample_app_activerecord/config/newrelic.yml
252
+ - sample_apps/sample_app_activerecord/config/postgresql.yml
253
+ - sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb
254
+ - sample_apps/sample_app_activerecord/db/schema.rb
255
+ - sample_apps/sample_app_activerecord/spec/api/root_spec.rb
256
+ - sample_apps/sample_app_activerecord/spec/commands/help_spec.rb
257
+ - sample_apps/sample_app_activerecord/spec/commands/whoami_spec.rb
258
+ - sample_apps/sample_app_activerecord/spec/spec_helper.rb
259
+ - sample_apps/sample_app_mongoid/.rspec
260
+ - sample_apps/sample_app_mongoid/Gemfile
261
+ - sample_apps/sample_app_mongoid/Procfile
262
+ - sample_apps/sample_app_mongoid/README.md
263
+ - sample_apps/sample_app_mongoid/Rakefile
264
+ - sample_apps/sample_app_mongoid/commands.rb
265
+ - sample_apps/sample_app_mongoid/commands/help.rb
266
+ - sample_apps/sample_app_mongoid/commands/whoami.rb
267
+ - sample_apps/sample_app_mongoid/config.ru
268
+ - sample_apps/sample_app_mongoid/config/mongoid.yml
269
+ - sample_apps/sample_app_mongoid/config/newrelic.yml
270
+ - sample_apps/sample_app_mongoid/spec/api/root_spec.rb
271
+ - sample_apps/sample_app_mongoid/spec/commands/help_spec.rb
272
+ - sample_apps/sample_app_mongoid/spec/commands/whoami_spec.rb
273
+ - sample_apps/sample_app_mongoid/spec/spec_helper.rb
307
274
  - script/console
308
275
  - slack-ruby-bot-server.gemspec
309
276
  - tasks/db.rake
@@ -1,68 +0,0 @@
1
- class Team
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- SORT_ORDERS = ['created_at', '-created_at', 'updated_at', '-updated_at'].freeze
6
-
7
- field :team_id, type: String
8
- field :name, type: String
9
- field :domain, type: String
10
- field :token, type: String
11
- field :active, type: Boolean, default: true
12
-
13
- attr_accessor :server # server at runtime
14
-
15
- scope :active, -> { where(active: true) }
16
-
17
- validates_uniqueness_of :token, message: 'has already been used'
18
- validates_presence_of :token
19
- validates_presence_of :team_id
20
-
21
- def deactivate!
22
- update_attributes!(active: false)
23
- end
24
-
25
- def activate!(token)
26
- update_attributes!(active: true, token: token)
27
- end
28
-
29
- def to_s
30
- {
31
- name: name,
32
- domain: domain,
33
- id: team_id
34
- }.map do |k, v|
35
- "#{k}=#{v}" if v
36
- end.compact.join(', ')
37
- end
38
-
39
- def ping!
40
- client = Slack::Web::Client.new(token: token)
41
- auth = client.auth_test
42
- {
43
- auth: auth,
44
- presence: client.users_getPresence(user: auth['user_id'])
45
- }
46
- end
47
-
48
- def self.find_or_create_from_env!
49
- token = ENV['SLACK_API_TOKEN']
50
- return unless token
51
- team = Team.where(token: token).first
52
- team ||= Team.new(token: token)
53
- info = Slack::Web::Client.new(token: token).team_info
54
- team.team_id = info['team']['id']
55
- team.name = info['team']['name']
56
- team.domain = info['team']['domain']
57
- team.save!
58
- team
59
- end
60
-
61
- def self.purge!
62
- # destroy teams inactive for two weeks
63
- Team.where(active: false, :updated_at.lte => 2.weeks.ago).each do |team|
64
- Mongoid.logger.info "Destroying #{team}, inactive since #{team.updated_at}, over two weeks ago."
65
- team.destroy
66
- end
67
- end
68
- end