Sha256: 635d5c4b95c7dc437a879dd09ad2e8c24b284bddc6cc770f00caa303325f2f1a

Contents?: true

Size: 980 Bytes

Versions: 34

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

require 'http'
require 'json'

module Gitlab
  module QA
    module Support
      class HttpRequest
        # rubocop:disable Metrics/AbcSize
        def self.make_http_request(method: 'get', url: nil, params: nil, 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
        # rubocop:enable Metrics/AbcSize
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
gitlab-qa-15.2.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-15.1.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-15.0.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.21.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.20.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.19.2 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.19.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.19.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.18.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.17.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.16.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.15.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.14.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.13.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.12.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.11.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.9.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.8.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.8.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-14.7.0 lib/gitlab/qa/support/http_request.rb