Skip to content

Commit

Permalink
The set api method will display team API URL when on. Closes #103.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Apr 28, 2016
1 parent 5014089 commit 9a3f489
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-04-23 16:51:24 -0400 using RuboCop version 0.34.2.
# on 2016-04-28 13:58:39 -0400 using RuboCop version 0.34.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -35,7 +35,7 @@ Lint/RescueException:

# Offense count: 44
Metrics/AbcSize:
Max: 90
Max: 94

# Offense count: 5
Metrics/BlockNesting:
Expand All @@ -50,7 +50,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 19

# Offense count: 540
# Offense count: 548
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 208
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changelog

* [#103](https://github.com/dblock/slack-gamebot/issues/103): The `set api` method will display team API URL when on - [@dblock](https://github.com/dblock).
* [#105](https://github.com/dblock/slack-gamebot/issues/105): Fix: `rank` displays multiple unranked users - [@dblock](https://github.com/dblock).
* [#104](https://github.com/dblock/slack-gamebot/issues/104): Fix: `rank` leaks users from other teams - [@dblock](https://github.com/dblock).
* [#102](https://github.com/dblock/slack-gamebot/issues/102), [#101](https://github.com/dblock/slack-gamebot/issues/101): Unable to set options with existing challenges - [@dblock](https://github.com/dblock).
Expand Down
6 changes: 5 additions & 1 deletion DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ game.save!

#### GIPHY_API_KEY

Slack-Gamebot replies with animated GIFs. While it's currently not necessary, uyou may need to set `GIPHY_API_KEY` in the future, see [github.com/Giphy/GiphyAPI](https://github.com/Giphy/GiphyAPI) for details.
Slack-Gamebot replies with animated GIFs. While it's currently not necessary, you may need to set `GIPHY_API_KEY` in the future, see [github.com/Giphy/GiphyAPI](https://github.com/Giphy/GiphyAPI) for details.

#### API_URL

The root of your API location, used when displaying the API URL for teams when invoking `set api`.

#### Multi-Game Setup

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,13 @@ Remove all aliases with `set aliases none`.

#### gamebot set api on|off

Enable/disable team data in the public API for your team.
Enable/disable team data in the public API for your team and displays team API URL.

```
gamebot set api on
API for team China is on!
http://bots.playplay.io/teams/57224e65bc526eac95bfe316
```

## API
Expand Down
6 changes: 5 additions & 1 deletion slack-gamebot/commands/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def self.call(client, data, match)
logger.info "SET: #{client.owner} - #{user.user_name} GIFs are #{client.owner.gifs? ? 'on' : 'off'}"
when 'api' then
client.owner.update_attributes!(api: v.to_b) unless v.nil?
client.say(channel: data.channel, text: "API for team #{client.owner.name} is #{client.owner.api? ? 'on!' : 'off.'}", gif: 'programmer')
message = [
"API for team #{client.owner.name} is #{client.owner.api? ? 'on!' : 'off.'}",
client.owner.api_url
].compact.join("\n")
client.say(channel: data.channel, text: message, gif: 'programmer')
logger.info "SET: #{client.owner} - #{user.user_name} API is #{client.owner.api? ? 'on' : 'off'}"
when 'aliases' then
if v == 'none'
Expand Down
5 changes: 5 additions & 0 deletions slack-gamebot/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def nudge!
inform! "Challenge someone to a game of #{game.name} today!", 'nudge'
end

def api_url
return unless api? && ENV.key?('API_URL')
"#{ENV['API_URL']}/teams/#{id}"
end

def inform!(message, gif_name = nil)
client = Slack::Web::Client.new(token: token)
channels = client.channels_list['channels'].select { |channel| channel['is_member'] }
Expand Down
22 changes: 21 additions & 1 deletion spec/slack-gamebot/commands/set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"API for team #{team.name} is on!"
)
end
it 'shows current value of API' do
it 'shows current value of API off' do
team.update_attributes!(api: false)
expect(message: "#{SlackRubyBot.config.user} set api").to respond_with_slack_message(
"API for team #{team.name} is off."
Expand All @@ -65,6 +65,26 @@
)
expect(team.reload.api).to be false
end
context 'with API_URL' do
before do
ENV['API_URL'] = 'http://local.api'
end
after do
ENV.delete 'API_URL'
end
it 'shows current value of API on with API URL' do
team.update_attributes!(api: true)
expect(message: "#{SlackRubyBot.config.user} set api").to respond_with_slack_message(
"API for team #{team.name} is on!\nhttp://local.api/teams/#{team.id}"
)
end
it 'shows current value of API off without API URL' do
team.update_attributes!(api: false)
expect(message: "#{SlackRubyBot.config.user} set api").to respond_with_slack_message(
"API for team #{team.name} is off."
)
end
end
end
context 'aliases' do
context 'with aliases' do
Expand Down

0 comments on commit 9a3f489

Please sign in to comment.