diff options
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/command.rb | 13 | ||||
-rw-r--r-- | lib/mattermost/session.rb | 7 | ||||
-rw-r--r-- | lib/mattermost/team.rb | 10 |
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 |