module Hoe::Travis

def travis_github_request(path, body = nil,

def travis_github_request(path, body = nil,
                          method = body ? Net::HTTP::Post : Net::HTTP::Get)
  begin
    require 'json'
  rescue LoadError => e
    raise unless e.message.end_with? 'json'
    abort 'Please gem install json like modern ruby versions have'
  end
  uri = @github_api + path
  http = Net::HTTP.new uri.host, uri.port
  http.use_ssl = uri.scheme.downcase == 'https'
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.cert_store = OpenSSL::X509::Store.new
  http.cert_store.set_default_paths
  req = method.new uri.request_uri
  if body then
    req.content_type = 'application/json'
    req.body = JSON.dump body
  end
  user = `git config github.user`.chomp
  pass = `git config github.password`.chomp
  req.basic_auth user, pass
  res = http.request req
  body = JSON.parse res.body if res.class.body_permitted?
  unless Net::HTTPSuccess === res then
    message = ": #{res['message']}" if body
    raise "github API error #{res.code}#{message}"
  end
  body
end