From 87d160634dfdaacd0dc382c26932786382d1be34 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 13 Dec 2016 19:52:41 +0100 Subject: Base work for auto config MM slash commands --- lib/mattermost/session.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/mattermost/session.rb') 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 -- cgit v1.2.3