Module: Trav3::GET

Defined in:
lib/trav3/get.rb

Class Method Summary collapse

Class Method Details

.call(travis, url, raw_reply = false) ⇒ Object

rubocop:disable Metrics/MethodLength


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trav3/get.rb', line 10

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