Class: Gitlab::QA::Support::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/support/http_request.rb

Class Method Summary collapse

Class Method Details

.make_http_request(method: 'get', url: nil, params: {}, headers: {}, show_response: false, fail_on_error: true) ⇒ Object

rubocop:disable Metrics/AbcSize



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/qa/support/http_request.rb', line 9

def self.make_http_request(method: 'get', url: nil, params: {}, headers: {}, show_response: false, fail_on_error: true)
  raise "URL not defined for making request. Exiting..." unless url

  res = HTTP.follow.method(method).call(url, json: params, headers: headers)

  if show_response
    if res.content_type.mime_type == "application/json"
      res_body = JSON.parse(res.body.to_s)
      pp res_body
    else
      res_body = res.body.to_s
      puts res_body
    end
  end

  raise "#{method.upcase} request failed!\nCode: #{res.code}\nResponse: #{res.body}\n" if fail_on_error && !res.status.success?

  res
end