Mike McQuaid 8e0e1642ad Use curl for the GitHub API (#295)
* Move GitHub API module to utils/github.rb.

* Move curl method to utils/curl.rb.

* global: use long curl arguments and an array.

This makes the code more self-documenting.

* utils/curl: support reading curl's output.

* utils/github: use curl instead of open-uri.

It has far better proxy support.

* pull: set Homebrew user agent.

* gist-logs: remove trailing whitespace.

* gist-logs: use first instead of [0].

Easier to read.

* gist-logs: use curl-based GitHub.open method.
2016-06-03 13:05:18 +01:00

25 lines
624 B
Ruby

require "pathname"
def curl_args(extra_args=[])
curl = Pathname.new ENV["HOMEBREW_CURL"]
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
raise "#{curl} is not executable" unless curl.exist? && curl.executable?
flags = HOMEBREW_CURL_ARGS
flags -= ["--progress-bar"] if ARGV.verbose?
args = ["#{curl}"] + flags + extra_args
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
args
end
def curl(*args)
safe_system(*curl_args(args))
end
def curl_output(*args)
curl_args = curl_args(args) - ["--fail"]
Utils.popen_read_text(*curl_args)
end