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
-
#server ⇒ Object
Server URI.
Instance Method Summary collapse
Instance Attribute Details
#server ⇒ Object
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, = {}) = DEFAULT_REQUEST_OPTIONS.merge() raise RocketChat::InvalidMethodError unless %i[get post].include? [:method] http = create_http() req = create_request(path, ) 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, = {}) fail_unless_ok = .delete :fail_unless_ok upstreamed_errors = Array(.delete(:upstreamed_errors)) response = request path, check_response response, fail_unless_ok response_json = parse_response(response.body) [:debug]&.puts("Response: #{response_json.inspect}") check_response_json response_json, upstreamed_errors response_json end |