diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-12-19 14:14:09 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-12-19 14:14:09 +0100 |
commit | 6d14a6640f89893792ad6c66b7f4362ef4ff9007 (patch) | |
tree | 7109c818a61f5b92e34e5202a7a544d1d191ad62 /lib/mattermost | |
parent | 4213bd56dea1d6cdbfa8baed8faa7e3ab86e61ab (diff) | |
download | gitlab-ce-6d14a6640f89893792ad6c66b7f4362ef4ff9007.tar.gz |
Minor adjustments API Mattermost
[ci skip]
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/command.rb | 13 | ||||
-rw-r--r-- | lib/mattermost/session.rb | 4 | ||||
-rw-r--r-- | lib/mattermost/team.rb | 17 |
3 files changed, 14 insertions, 20 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index 9c37d0b0d79..830e61b015e 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,14 +1,7 @@ module Mattermost - class Command < Session - def self.create(team_id, trigger: 'gitlab', url:, icon_url:) - - post_command(command)['token'] - end - - private - - def post_command(command) - post( "/teams/#{team_id}/commands/create", body: command.to_json).parsed_response + class Command + def self.create(session, team_id, command) + session.post("/api/v3/teams/#{team_id}/commands/create", body: command.to_json)['token'] end end end diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb index dcdff94814c..670f83bb6bc 100644 --- a/lib/mattermost/session.rb +++ b/lib/mattermost/session.rb @@ -30,6 +30,8 @@ module Mattermost begin yield self + rescue Errno::ECONNREFUSED + raise NoSessionError ensure destroy end @@ -112,4 +114,4 @@ module Mattermost end end end -end
\ No newline at end of file +end diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb index 714748aea3c..9e1b22623a3 100644 --- a/lib/mattermost/team.rb +++ b/lib/mattermost/team.rb @@ -1,21 +1,20 @@ module Mattermost - class Team < Session - def self.team_admin - return [] unless initial_load['team_members'] + class Team + def self.team_admin(session) + response_body = initial_load(session) + return [] unless response_body['team_members'] - team_ids = initial_load['team_members'].map do |team| + team_ids = response_body['team_members'].map do |team| team['team_id'] if team['roles'].split.include?('team_admin') end.compact - initial_load['teams'].select do |team| + response_body['teams'].select do |team| team_ids.include?(team['id']) end end - private - - def initial_load - @initial_load ||= get('/users/initial_load').parsed_response + def self.initial_load(session) + session.get('/api/v3/users/initial_load').parsed_response end end end |