diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 01:53:19 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 01:56:21 +0300 |
commit | 34295036e2a9ecf18ca5440a5dd6dbb0c7f05643 (patch) | |
tree | a529cbc332882305520c7650cbe860301e12abb8 /lib/mattermost/command.rb | |
parent | 921f411a41d92ff6b3fdea2560adbd861d97be57 (diff) |
Improve sources
- Add proper error handling,
- Use flash[:alert] and flash[:notice],
- Use `resource` instead of `resources`,
Diffstat (limited to 'lib/mattermost/command.rb')
-rw-r--r-- | lib/mattermost/command.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index afbf2ce3349..5c6f5861a7f 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,12 +1,15 @@ module Mattermost class Command - def self.create(session, team_id, command) - response = session.post("/api/v3/teams/#{team_id}/commands/create", body: command.to_json).parsed_response + def self.create(session, params) + response = session.post("/api/v3/teams/#{params[:team_id]}/commands/create", + body: params.to_json) - if response.has_key?('message') - response + if response.success? + response.parsed_response['token'] + elsif response.parsed_response.try(:has_key?, 'message') + raise response.parsed_response['message'] else - response['token'] + raise 'Failed to create a new command' end end end |