Sha256: 24cfa3e4808d8885990ae3adbc16f83623eef6ab9cf55001c874731e861b7654

Contents?: true

Size: 948 Bytes

Versions: 146

Compression:

Stored size: 948 Bytes

Contents

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: {}, 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

146 entries across 146 versions & 1 rubygems

Version Path
gitlab-qa-7.34.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.33.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.32.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.31.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.30.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.29.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.29.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.27.2 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.27.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.27.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.26.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.25.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.25.0 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.6 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.5 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.4 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.3 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.2 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.1 lib/gitlab/qa/support/http_request.rb
gitlab-qa-7.24.0 lib/gitlab/qa/support/http_request.rb