Class: RocketChat::Server

Inherits:
Object
  • Object
show all
Includes:
RequestHelper
Defined in:
lib/rocket_chat/server.rb

Overview

Rocket.Chat Server

Constant Summary

Constants included from RequestHelper

RequestHelper::DEFAULT_REQUEST_OPTIONS

Instance Attribute Summary collapse

Attributes included from RequestHelper

#server

Instance Method Summary collapse

Methods included from RequestHelper

#request

Constructor Details

#initialize(server, options = {}) ⇒ Server

Returns a new instance of Server.

Parameters:

  • server (URI, String)

    Server URI

  • options (Hash) (defaults to: {})

    Server options



17
18
19
20
# File 'lib/rocket_chat/server.rb', line 17

def initialize(server, options = {})
  self.server = server
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Server options



11
12
13
# File 'lib/rocket_chat/server.rb', line 11

def options
  @options
end

Instance Method Details

#infoInfo

Info REST API

Returns:

  • (Info)

    Rocket.Chat Info

Raises:



27
28
29
30
# File 'lib/rocket_chat/server.rb', line 27

def info
  response = request_json '/api/v1/info', fail_unless_ok: true
  Info.new response['info']
end

#login(username, password) ⇒ Session

Login REST API

Parameters:

  • username (String)

    Username

  • password (String)

    Password

Returns:

  • (Session)

    Rocket.Chat Session

Raises:



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rocket_chat/server.rb', line 39

def (username, password)
  response = request_json(
    '/api/v1/login',
    method: :post,
    body: {
      username: username,
      password: password
    }
  )
  Session.new self, Token.new(response['data'])
end

#request_json(path, options = {}) ⇒ Object



51
52
53
# File 'lib/rocket_chat/server.rb', line 51

def request_json(path, options = {})
  super(path, @options.merge(options))
end