summaryrefslogtreecommitdiff
path: root/lib/mattermost
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mattermost')
-rw-r--r--lib/mattermost/command.rb16
-rw-r--r--lib/mattermost/session.rb2
-rw-r--r--lib/mattermost/team.rb19
3 files changed, 23 insertions, 14 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb
index e159458a788..b6446935eb6 100644
--- a/lib/mattermost/command.rb
+++ b/lib/mattermost/command.rb
@@ -1,7 +1,7 @@
module Mattermost
- class Command
+ class Command < Session
def self.all(team_id)
- Mattermost::Mattermost.get("/teams/#{team_id}/commands/list_team_commands")
+ get("/teams/#{team_id}/commands/list_team_commands").parsed_response
end
# params should be a hash, which supplies _at least_:
@@ -9,18 +9,20 @@ module Mattermost
# - url => What is the URL to trigger here?
# - icon_url => Supply a link to the icon
def self.create(team_id, params)
- params = {
+ command = {
auto_complete: true,
auto_complete_desc: 'List all available commands',
auto_complete_hint: '[help]',
description: 'Perform common operations on GitLab',
display_name: 'GitLab',
method: 'P',
- user_name: 'GitLab'
- }..merge(params)
+ user_name: 'GitLab',
+ trigger: 'gitlab',
+ }.merge(params)
- Mattermost::Mattermost.post( "/teams/#{team_id}/commands/create", params.to_json).
- parsed_response['token']
+ response = post( "/teams/#{team_id}/commands/create", body: command.to_json)
+
+ response.parsed_response['token']
end
end
end
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index cc4cb1f4f12..15bf95a38c9 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -65,6 +65,7 @@ module Mattermost
return unless token_uri
self.class.headers("Cookie" => "MMAUTHTOKEN=#{request_token}")
+ self.class.headers("X-Requested-With" => 'XMLHttpRequest')
request_token
end
@@ -106,7 +107,6 @@ module Mattermost
def normalize_uri(uri)
uri << '/' unless uri.end_with?('/')
-
uri << 'api/v3'
end
end
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
index 76e238a866e..54d029cb022 100644
--- a/lib/mattermost/team.rb
+++ b/lib/mattermost/team.rb
@@ -1,10 +1,17 @@
module Mattermost
- class Team < Mattermost
- # After normalization this returns an array of hashes
- #
- # [{"id"=>"paf573pj9t81urupw3fanozeda", "display_name"=>"my team", <snip>}]
- def self.all
- @all_teams ||= get('/teams/all').parsed_response.values
+ class Team < Session
+ def self.team_admin
+ body = get('/users/initial_load').parsed_response
+
+ return [] unless body['team_members']
+
+ team_ids = body['team_members'].map do |team|
+ team['team_id'] if team['roles'].split.include?('team_admin')
+ end.compact
+
+ body['teams'].select do |team|
+ team_ids.include?(team['id'])
+ end
end
end
end