Sha256: 75826a182b01942bb20a7f78e61c21420161f5e1750caac0b4f995e6290139b3

Contents?: true

Size: 1.12 KB

Versions: 21

Compression:

Stored size: 1.12 KB

Contents

module RocketChat
  #
  # Rocket.Chat Server
  #
  class Server
    include RocketChat::RequestHelper

    # Server options
    attr_reader :options

    #
    # @param [URI, String] server Server URI
    # @param [Hash] options Server options
    #
    def initialize(server, options = {})
      self.server = server
      @options = options
    end

    #
    # Info REST API
    # @return [Info] Rocket.Chat Info
    # @raise [HTTPError, StatusError]
    #
    def info
      response = request_json '/api/v1/info', fail_unless_ok: true
      Info.new response['info']
    end

    #
    # Login REST API
    # @param [String] username Username
    # @param [String] password Password
    # @return [Session] Rocket.Chat Session
    # @raise [HTTPError, StatusError]
    #
    def login(username, password)
      response = request_json(
        '/api/v1/login',
        method: :post,
        body: {
          username: username,
          password: password
        }
      )
      Session.new self, Token.new(response['data'])
    end

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rocketchat-0.1.18 lib/rocket_chat/server.rb
rocketchat-0.1.17 lib/rocket_chat/server.rb
rocketchat-0.1.16 lib/rocket_chat/server.rb
rocketchat-0.1.15 lib/rocket_chat/server.rb
rocketchat-0.1.14 lib/rocket_chat/server.rb
rocketchat-0.1.13 lib/rocket_chat/server.rb
rocketchat-0.1.12 lib/rocket_chat/server.rb
rocketchat-0.1.11 lib/rocket_chat/server.rb
rocketchat-0.1.10 lib/rocket_chat/server.rb
rocketchat-0.1.9 lib/rocket_chat/server.rb
rocketchat-0.1.8 lib/rocket_chat/server.rb
rocketchat-0.1.7 lib/rocket_chat/server.rb
rocketchat-0.1.6 lib/rocket_chat/server.rb
rocketchat-0.1.5 lib/rocket_chat/server.rb
rocketchat-0.1.4 lib/rocket_chat/server.rb
rocketchat-0.1.3 lib/rocket_chat/server.rb
rocketchat-0.1.2 lib/rocket_chat/server.rb
rocketchat-0.1.1 lib/rocket_chat/server.rb
rocketchat-0.0.8 lib/rocket_chat/server.rb
rocketchat-0.0.7 lib/rocket_chat/server.rb