diff options
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/command.rb | 8 | ||||
-rw-r--r-- | lib/mattermost/team.rb | 14 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index 108a2a47a4b..7d4710bb94d 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -14,9 +14,13 @@ module Mattermost icon_url: icon_url } - response = post( "/teams/#{team_id}/commands/create", body: command.to_json) + post_command(command)['token'] + end + + private - response.parsed_response['token'] + def post_command(command) + post( "/teams/#{team_id}/commands/create", body: command.to_json).parsed_response end end end diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb index 54d029cb022..714748aea3c 100644 --- a/lib/mattermost/team.rb +++ b/lib/mattermost/team.rb @@ -1,17 +1,21 @@ module Mattermost class Team < Session def self.team_admin - body = get('/users/initial_load').parsed_response + return [] unless initial_load['team_members'] - return [] unless body['team_members'] - - team_ids = body['team_members'].map do |team| + team_ids = initial_load['team_members'].map do |team| team['team_id'] if team['roles'].split.include?('team_admin') end.compact - body['teams'].select do |team| + initial_load['teams'].select do |team| team_ids.include?(team['id']) end end + + private + + def initial_load + @initial_load ||= get('/users/initial_load').parsed_response + end end end |