class Mattermost::Client

Attributes

headers[RW]
server[RW]
subdir[RW]
token[RW]

Public Class Methods

new(server) click to toggle source
# File lib/mattermost/client.rb, line 20
def initialize(server)
        self.server = URI.join(server, '/').to_s
        self.subdir = URI(server).path
        self.headers = {:Accept => "application/json"}
end

Public Instance Methods

base_uri() click to toggle source

DEPRECATED I'll remove this method soon

# File lib/mattermost/client.rb, line 15
def base_uri
        "#{server}/api/v4"
end
connect_websocket() { |ws_client| ... } click to toggle source
# File lib/mattermost/client.rb, line 47
def connect_websocket
        # TODO raise exception then connected? == false
        @ws_client = WebSocketClient.new "#{base_uri}/websocket", token, {:headers => self.headers}
        yield @ws_client if block_given?
        @ws_client
end
connected?() click to toggle source
# File lib/mattermost/client.rb, line 43
def connected?
        get_me.success?
end
login(username, password) click to toggle source
# File lib/mattermost/client.rb, line 26
def login(username, password)
        login_request = post('/users/login', :body => {:login_id => username, :password => password}.to_json)
        self.token = login_request.headers['token']
        update_token
end
logout() click to toggle source
# File lib/mattermost/client.rb, line 32
def logout
        post("/users/logout")
        self.token = nil
        update_token
end
use_access_token(token) click to toggle source
# File lib/mattermost/client.rb, line 38
def use_access_token(token)
        self.token = token
        update_token
end
ws_client() click to toggle source
# File lib/mattermost/client.rb, line 54
def ws_client
        @ws_client
end

Private Instance Methods

update_token() click to toggle source
# File lib/mattermost/client.rb, line 60
def update_token
        headers[:Authorization] = "Bearer #{token}"
end