diff options
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/command.rb | 17 | ||||
-rw-r--r-- | lib/mattermost/session.rb | 4 | ||||
-rw-r--r-- | lib/mattermost/team.rb | 20 |
3 files changed, 17 insertions, 24 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index 9c37d0b0d79..afbf2ce3349 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,14 +1,13 @@ module Mattermost - class Command < Session - def self.create(team_id, trigger: 'gitlab', url:, icon_url:) + 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 - post_command(command)['token'] - end - - private - - def post_command(command) - post( "/teams/#{team_id}/commands/create", body: command.to_json).parsed_response + if response.has_key?('message') + response + else + response['token'] + end 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..c1b867629b6 100644 --- a/lib/mattermost/team.rb +++ b/lib/mattermost/team.rb @@ -1,21 +1,13 @@ module Mattermost - class Team < Session - def self.team_admin - return [] unless initial_load['team_members'] + class Team + def self.all(session) + response_body = retreive_teams(session) - team_ids = initial_load['team_members'].map do |team| - team['team_id'] if team['roles'].split.include?('team_admin') - end.compact - - initial_load['teams'].select do |team| - team_ids.include?(team['id']) - end + response_body.has_key?('message') ? response_body : response_body.values end - private - - def initial_load - @initial_load ||= get('/users/initial_load').parsed_response + def self.retreive_teams(session) + session.get('/api/v3/teams/all').parsed_response end end end |