Module: RocketChat::RequestHelper

Included in:
Server
Defined in:
lib/rocket_chat/request_helper.rb

Overview

Rocket.Chat HTTP request helper

Constant Summary collapse

DEFAULT_REQUEST_OPTIONS =
{
  method: :get,
  body: nil,
  headers: nil,
  ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER,
  ssl_ca_file: nil
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serverObject

Server URI



21
22
23
# File 'lib/rocket_chat/request_helper.rb', line 21

def server
  @server
end

Instance Method Details

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



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

def request(path, options = {})
  options = DEFAULT_REQUEST_OPTIONS.merge(options)

  raise RocketChat::InvalidMethodError unless %i[get post].include? options[:method]

  http = create_http(options)
  req = create_request(path, options)
  http.start { http.request(req) }
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rocket_chat/request_helper.rb', line 27

def request_json(path, options = {})
  fail_unless_ok = options.delete :fail_unless_ok
  upstreamed_errors = Array(options.delete(:upstreamed_errors))

  response = request path, options
  check_response response, fail_unless_ok

  response_json = parse_response(response.body)
  options[:debug]&.puts("Response: #{response_json.inspect}")
  check_response_json response_json, upstreamed_errors

  response_json
end