diff options
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 |