Sha256: e8b84fd5e00a36d04f05be867727c977b2a1085f9a58cb7e7f065aad7403ef28

Contents?: true

Size: 730 Bytes

Versions: 1

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

require 'net/http'
require 'uri'
require 'json'

module Trav3
  module GET
    # rubocop:disable Metrics/MethodLength
    def self.call(travis, url, raw_reply = false)
      uri = URI(url)
      req = Net::HTTP::Get.new(uri.request_uri)
      travis.headers.each_pair do |header, value|
        req[header] = value
      end
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = (uri.scheme == 'https')
      response = http.request(req)

      return response.body if raw_reply

      if Net::HTTPOK == response.code_type
        Success.new(travis, response)
      else
        RequestError.new(travis, response)
      end
    end
    # rubocop:enable Metrics/MethodLength
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trav3-0.2.1 lib/trav3/get.rb