Skip to content

Commit ddbed65

Browse files
committed
Subscribe to the Playplay.io mailing list.
1 parent b575ab9 commit ddbed65

File tree

12 files changed

+129
-48
lines changed

12 files changed

+129
-48
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ AllCops:
66
Style:
77
Enabled: false
88

9+
Metrics:
10+
Enabled: false
11+
912
inherit_from: .rubocop_todo.yml

.rubocop_todo.yml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-04-12 09:24:52 -0400 using RuboCop version 0.67.2.
3+
# on 2019-04-16 15:29:36 -0400 using RuboCop version 0.67.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -11,28 +11,10 @@ Lint/HandleExceptions:
1111
Exclude:
1212
- 'slack-shellbot/models/vi_program.rb'
1313

14-
# Offense count: 13
15-
Metrics/AbcSize:
16-
Max: 48
17-
18-
# Offense count: 17
19-
# Configuration parameters: CountComments, ExcludedMethods.
20-
# ExcludedMethods: refine
21-
Metrics/BlockLength:
22-
Max: 100
23-
24-
# Offense count: 4
25-
Metrics/CyclomaticComplexity:
26-
Max: 11
27-
28-
# Offense count: 9
29-
# Configuration parameters: CountComments, ExcludedMethods.
30-
Metrics/MethodLength:
31-
Max: 26
32-
33-
# Offense count: 4
34-
Metrics/PerceivedComplexity:
35-
Max: 12
14+
# Offense count: 1
15+
Lint/UselessAssignment:
16+
Exclude:
17+
- 'spec/api/endpoints/teams_endpoint_spec.rb'
3618

3719
# Offense count: 1
3820
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
@@ -48,9 +30,3 @@ Naming/HeredocDelimiterNaming:
4830
Exclude:
4931
- 'slack-shellbot/commands/help.rb'
5032
- 'slack-shellbot/info.rb'
51-
52-
# Offense count: 125
53-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
54-
# URISchemes: http, https
55-
Metrics/LineLength:
56-
Max: 163

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
33
ruby '2.6.2'
44

55
gem 'giphy'
6+
gem 'irb'
67
gem 'kaminari-grape'
78
gem 'mongoid'
89
gem 'mongoid-scroll'
@@ -11,6 +12,7 @@ gem 'newrelic_rpm'
1112
gem 'rack-robotz'
1213
gem 'rack-server-pages'
1314
gem 'slack-ruby-bot-server'
15+
gem 'slack-ruby-bot-server-mailchimp'
1416
gem 'unicorn'
1517

1618
group :development, :test do

Gemfile.lock

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ GEM
4848
descendants_tracker (0.0.4)
4949
thread_safe (~> 0.3, >= 0.3.1)
5050
diff-lcs (1.3)
51+
domain_name (0.5.20180417)
52+
unf (>= 0.0.5, < 1.0.0)
5153
equalizer (0.0.11)
5254
fabrication (2.20.1)
5355
faker (1.9.3)
@@ -89,6 +91,8 @@ GEM
8991
grape (>= 0.16.2)
9092
hashdiff (0.3.8)
9193
hashie (3.6.0)
94+
http-cookie (1.0.3)
95+
domain_name (~> 0.5)
9296
hyperclient (0.9.0)
9397
faraday (>= 0.9.0)
9498
faraday-digestauth
@@ -99,6 +103,7 @@ GEM
99103
i18n (1.6.0)
100104
concurrent-ruby (~> 1.0)
101105
ice_nine (0.11.2)
106+
irb (1.0.0)
102107
jaro_winkler (1.5.2)
103108
kaminari-core (1.1.1)
104109
kaminari-grape (1.0.1)
@@ -107,6 +112,11 @@ GEM
107112
kgio (2.11.2)
108113
launchy (2.4.3)
109114
addressable (~> 2.3)
115+
mailchimp_api_v3 (0.2.18)
116+
rest-client (~> 2)
117+
mime-types (3.2.2)
118+
mime-types-data (~> 3.2015)
119+
mime-types-data (3.2019.0331)
110120
mini_mime (1.0.1)
111121
mini_portile2 (2.4.0)
112122
minitest (5.11.3)
@@ -132,14 +142,15 @@ GEM
132142
mustermann-grape (1.0.0)
133143
mustermann (~> 1.0.0)
134144
net-http-digest_auth (1.4.1)
145+
netrc (0.11.0)
135146
newrelic-slack-ruby-bot (0.2.1)
136147
newrelic_rpm
137148
slack-ruby-bot (>= 0.10.5)
138149
newrelic_rpm (6.2.0.354)
139150
nio4r (2.3.1)
140151
nokogiri (1.10.2)
141152
mini_portile2 (~> 2.4.0)
142-
oj (3.7.11)
153+
oj (3.7.12)
143154
parallel (1.17.0)
144155
parser (2.6.2.1)
145156
ast (~> 2.4.0)
@@ -164,6 +175,10 @@ GEM
164175
declarative (< 0.1.0)
165176
declarative-option (< 0.2.0)
166177
uber (< 0.2.0)
178+
rest-client (2.0.2)
179+
http-cookie (>= 1.0.2, < 2.0)
180+
mime-types (>= 1.16, < 4.0)
181+
netrc (~> 0.8)
167182
roar (1.1.0)
168183
representable (~> 3.0.0)
169184
rspec (3.8.0)
@@ -207,6 +222,9 @@ GEM
207222
rack-rewrite
208223
rack-server-pages
209224
slack-ruby-bot (>= 0.12.0)
225+
slack-ruby-bot-server-mailchimp (0.2.0)
226+
mailchimp_api_v3
227+
slack-ruby-bot-server (>= 0.10.0)
210228
slack-ruby-client (0.14.2)
211229
activesupport
212230
faraday (>= 0.9)
@@ -220,6 +238,9 @@ GEM
220238
tzinfo (1.2.5)
221239
thread_safe (~> 0.1)
222240
uber (0.1.0)
241+
unf (0.1.4)
242+
unf_ext
243+
unf_ext (0.0.7.5)
223244
unicode-display_width (1.5.0)
224245
unicorn (5.5.0)
225246
kgio (~> 2.6)
@@ -252,6 +273,7 @@ DEPENDENCIES
252273
foreman
253274
giphy
254275
hyperclient
276+
irb
255277
kaminari-grape
256278
mongoid
257279
mongoid-scroll
@@ -266,6 +288,7 @@ DEPENDENCIES
266288
rubocop
267289
selenium-webdriver
268290
slack-ruby-bot-server
291+
slack-ruby-bot-server-mailchimp
269292
unicorn
270293
vcr
271294
webmock

config.ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SlackShellbot::App.instance.prepare!
1313
Thread.abort_on_exception = true
1414

1515
Thread.new do
16-
SlackShellbot::Service.instance.start_from_database!
16+
SlackRubyBotServer::Service.instance.start_from_database!
1717
end
1818

1919
run Api::Middleware.instance
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SlackRubyBotServer::Mailchimp.configure do |config|
2+
config.mailchimp_api_key = ENV['MAILCHIMP_API_KEY']
3+
config.mailchimp_list_id = ENV['MAILCHIMP_LIST_ID']
4+
config.additional_member_tags = ['shell']
5+
config.additional_merge_fields = { 'BOT' => 'Shell' }
6+
end

slack-shellbot.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
require 'slack-shellbot/api'
1717
require 'slack-shellbot/app'
1818
require 'slack-shellbot/server'
19-
require 'slack-shellbot/service'
2019
require 'slack-shellbot/commands'

slack-shellbot/api/endpoints/teams_endpoint.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,33 @@ class TeamsEndpoint < Grape::API
4545
)
4646

4747
token = rc['bot']['bot_access_token']
48+
bot_user_id = rc['bot']['bot_user_id']
49+
user_id = rc['user_id']
50+
access_token = rc['access_token']
4851
team = Team.where(token: token).first
4952
team ||= Team.where(team_id: rc['team_id']).first
50-
if team && !team.active?
53+
54+
if team
55+
team.update_attributes!(
56+
activated_user_id: user_id,
57+
activated_user_access_token: access_token,
58+
bot_user_id: bot_user_id
59+
)
60+
raise "Team #{team.name} is already registered." if team.active?
61+
5162
team.activate!(token)
52-
elsif team
53-
raise "Team #{team.name} is already registered."
5463
else
5564
team = Team.create!(
5665
token: token,
5766
team_id: rc['team_id'],
58-
name: rc['team_name']
67+
name: rc['team_name'],
68+
activated_user_id: user_id,
69+
activated_user_access_token: access_token,
70+
bot_user_id: bot_user_id
5971
)
6072
end
6173

62-
SlackShellbot::Service.instance.start!(team)
74+
SlackRubyBotServer::Service.instance.create!(team)
6375
present team, with: Api::Presenters::TeamPresenter
6476
end
6577
end

slack-shellbot/service.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

spec/api/endpoints/teams_endpoint_spec.rb

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,34 @@
4747

4848
context 'register' do
4949
before do
50-
oauth_access = { 'bot' => { 'bot_access_token' => 'token' }, 'team_id' => 'team_id', 'team_name' => 'team_name' }
51-
ENV['SLACK_CLIENT_ID'] = 'client_id'
52-
ENV['SLACK_CLIENT_SECRET'] = 'client_secret'
50+
oauth_access = {
51+
'bot' => {
52+
'bot_access_token' => 'token',
53+
'bot_user_id' => 'bot_user_id'
54+
},
55+
'access_token' => 'access_token',
56+
'user_id' => 'activated_user_id',
57+
'team_id' => 'team_id',
58+
'team_name' => 'team_name'
59+
}
60+
5361
allow_any_instance_of(Slack::Web::Client).to receive(:oauth_access).with(
5462
hash_including(
5563
code: 'code',
5664
client_id: 'client_id',
5765
client_secret: 'client_secret'
5866
)
5967
).and_return(oauth_access)
68+
69+
ENV['SLACK_CLIENT_ID'] = 'client_id'
70+
ENV['SLACK_CLIENT_SECRET'] = 'client_secret'
6071
end
6172
after do
6273
ENV.delete('SLACK_CLIENT_ID')
6374
ENV.delete('SLACK_CLIENT_SECRET')
6475
end
6576
it 'creates a team' do
66-
expect(SlackShellbot::Service.instance).to receive(:start!)
77+
expect(SlackRubyBotServer::Service.instance).to receive(:start!)
6778
expect do
6879
team = client.teams._post(code: 'code')
6980
expect(team.team_id).to eq 'team_id'
@@ -73,7 +84,7 @@
7384
end.to change(Team, :count).by(1)
7485
end
7586
it 'reactivates a deactivated team' do
76-
expect(SlackShellbot::Service.instance).to receive(:start!)
87+
expect(SlackRubyBotServer::Service.instance).to receive(:start!)
7788
existing_team = Fabricate(:team, token: 'token', active: false)
7889
expect do
7990
team = client.teams._post(code: 'code')
@@ -93,7 +104,7 @@
93104
end
94105
end
95106
it 'reactivates a deactivated team with a different code' do
96-
expect(SlackShellbot::Service.instance).to receive(:start!)
107+
expect(SlackRubyBotServer::Service.instance).to receive(:start!)
97108
existing_team = Fabricate(:team, token: 'old', team_id: 'team_id', active: false)
98109
expect do
99110
team = client.teams._post(code: 'code')
@@ -105,6 +116,58 @@
105116
expect(team.active).to be true
106117
end.to_not change(Team, :count)
107118
end
119+
context 'with mailchimp settings' do
120+
before do
121+
SlackRubyBotServer::Mailchimp.configure do |config|
122+
config.mailchimp_api_key = 'api-key'
123+
config.mailchimp_list_id = 'list-id'
124+
end
125+
end
126+
after do
127+
SlackRubyBotServer::Mailchimp.config.reset!
128+
end
129+
130+
let(:list) { double(Mailchimp::List, members: double(Mailchimp::List::Members)) }
131+
132+
it 'subscribes to the mailing list' do
133+
expect(SlackRubyBotServer::Service.instance).to receive(:start!)
134+
135+
allow_any_instance_of(Slack::Web::Client).to receive(:users_info).with(
136+
user: 'activated_user_id'
137+
).and_return(
138+
user: {
139+
profile: {
140+
141+
first_name: 'First',
142+
last_name: 'Last'
143+
}
144+
}
145+
)
146+
147+
allow_any_instance_of(Mailchimp::Client).to receive(:lists).with('list-id').and_return(list)
148+
149+
expect(list.members).to receive(:where).with(email_address: '[email protected]').and_return([])
150+
151+
expect(list.members).to receive(:create_or_update).with(
152+
email_address: '[email protected]',
153+
merge_fields: {
154+
'FNAME' => 'First',
155+
'LNAME' => 'Last',
156+
'BOT' => 'Shell'
157+
},
158+
status: 'pending',
159+
name: nil,
160+
tags: %w[shell],
161+
unique_email_id: 'team_id-activated_user_id'
162+
)
163+
164+
client.teams._post(code: 'code')
165+
end
166+
after do
167+
ENV.delete('MAILCHIMP_API_KEY')
168+
ENV.delete('MAILCHIMP_LIST_ID')
169+
end
170+
end
108171
end
109172
end
110173
end

0 commit comments

Comments
 (0)