aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/curl.rb
diff options
context:
space:
mode:
authorMike McQuaid2016-06-03 13:05:18 +0100
committerGitHub2016-06-03 13:05:18 +0100
commit8e0e1642ad9cf87cd71521aabd03f03b8e7ddc8d (patch)
tree7e1cd52cd52f2868a043971bd930873316f11d40 /Library/Homebrew/utils/curl.rb
parentb2c9625d780277f021c63e21cac4a7c954170784 (diff)
downloadbrew-8e0e1642ad9cf87cd71521aabd03f03b8e7ddc8d.tar.bz2
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.
Diffstat (limited to 'Library/Homebrew/utils/curl.rb')
-rw-r--r--Library/Homebrew/utils/curl.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb
new file mode 100644
index 000000000..a1653d46c
--- /dev/null
+++ b/Library/Homebrew/utils/curl.rb
@@ -0,0 +1,24 @@
+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