summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-12-13 19:52:41 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-12-16 12:21:09 +0100
commit87d160634dfdaacd0dc382c26932786382d1be34 (patch)
tree3eb381dd13f1ebd0acdf6c5364f9c2639e057b26 /lib
parentdd385c7c3d3046da18c6c251bce25afab1129662 (diff)
downloadgitlab-ce-87d160634dfdaacd0dc382c26932786382d1be34.tar.gz
Base work for auto config MM slash commands
Diffstat (limited to 'lib')
-rw-r--r--lib/mattermost/command.rb26
-rw-r--r--lib/mattermost/session.rb13
-rw-r--r--lib/mattermost/team.rb10
3 files changed, 47 insertions, 2 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb
new file mode 100644
index 00000000000..e159458a788
--- /dev/null
+++ b/lib/mattermost/command.rb
@@ -0,0 +1,26 @@
+module Mattermost
+ class Command
+ def self.all(team_id)
+ Mattermost::Mattermost.get("/teams/#{team_id}/commands/list_team_commands")
+ end
+
+ # params should be a hash, which supplies _at least_:
+ # - trigger => The slash command, no spaces, cannot start with a /
+ # - url => What is the URL to trigger here?
+ # - icon_url => Supply a link to the icon
+ def self.create(team_id, params)
+ params = {
+ 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)
+
+ Mattermost::Mattermost.post( "/teams/#{team_id}/commands/create", params.to_json).
+ parsed_response['token']
+ end
+ end
+end
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index 81964666757..cc4cb1f4f12 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -20,6 +20,7 @@ module Mattermost
attr_accessor :current_resource_owner
def initialize(uri, current_user)
+ uri = normalize_uri(uri)
self.class.base_uri(uri)
@current_resource_owner = current_user
@@ -31,6 +32,8 @@ module Mattermost
destroy
result
+ rescue Errno::ECONNREFUSED
+ raise NoSessionError
end
# Next methods are needed for Doorkeeper
@@ -67,11 +70,11 @@ module Mattermost
end
def destroy
- post('/api/v3/users/logout')
+ post('/users/logout')
end
def oauth_uri
- response = get("/api/v3/oauth/gitlab/login", follow_redirects: false)
+ response = get("/oauth/gitlab/login", follow_redirects: false)
return unless 300 <= response.code && response.code < 400
redirect_uri = response.headers['location']
@@ -100,5 +103,11 @@ module Mattermost
def post(path, options = {})
self.class.post(path, options)
end
+
+ def normalize_uri(uri)
+ uri << '/' unless uri.end_with?('/')
+
+ uri << 'api/v3'
+ end
end
end
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
new file mode 100644
index 00000000000..76e238a866e
--- /dev/null
+++ b/lib/mattermost/team.rb
@@ -0,0 +1,10 @@
+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
+ end
+ end
+end