summaryrefslogtreecommitdiff
path: root/lib/mattermost
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-19 23:53:19 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2016-12-19 23:56:21 +0100
commit34295036e2a9ecf18ca5440a5dd6dbb0c7f05643 (patch)
treea529cbc332882305520c7650cbe860301e12abb8 /lib/mattermost
parent921f411a41d92ff6b3fdea2560adbd861d97be57 (diff)
downloadgitlab-ce-34295036e2a9ecf18ca5440a5dd6dbb0c7f05643.tar.gz
Improve sources
- Add proper error handling, - Use flash[:alert] and flash[:notice], - Use `resource` instead of `resources`,
Diffstat (limited to 'lib/mattermost')
-rw-r--r--lib/mattermost/command.rb13
-rw-r--r--lib/mattermost/session.rb7
-rw-r--r--lib/mattermost/team.rb10
3 files changed, 23 insertions, 7 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
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index 670f83bb6bc..f0ce51d6a71 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -1,5 +1,10 @@
module Mattermost
- class NoSessionError < StandardError; end
+ class NoSessionError < StandardError
+ def message
+ 'No session could be set up, is Mattermost configured with Single Sign on?'
+ end
+ end
+
# This class' prime objective is to obtain a session token on a Mattermost
# instance with SSO configured where this GitLab instance is the provider.
#
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
index 5ee77aa9adf..2de01eced0b 100644
--- a/lib/mattermost/team.rb
+++ b/lib/mattermost/team.rb
@@ -1,7 +1,15 @@
module Mattermost
class Team
def self.all(session)
- session.get('/api/v3/teams/all').parsed_response
+ response = session.get('/api/v3/teams/all')
+
+ if response.success?
+ response.parsed_response
+ elsif response.parsed_response.try(:has_key?, 'message')
+ raise response.parsed_response['message']
+ else
+ raise 'Failed to list teams'
+ end
end
end
end