Module: Homebrew::API Private
- Extended by:
- Cachable, T::Sig
- Defined in:
- api.rb,
api/cask.rb,
api/formula.rb,
api/versions.rb,
api/analytics.rb,
api/cask-source.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helper functions for using Homebrew’s formulae.brew.sh API.
Defined Under Namespace
Modules: Analytics, Cask, CaskSource, Formula, Versions
Constant Summary collapse
- API_DOMAIN =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"https://formulae.brew.sh/api"
- HOMEBREW_CACHE_API =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
(HOMEBREW_CACHE/"api").freeze
Class Method Summary collapse
Methods included from Cachable
Class Method Details
.fetch(endpoint, json: true) ⇒ String, Hash
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'api.rb', line 26 def fetch(endpoint, json: true) return cache[endpoint] if cache.present? && cache.key?(endpoint) api_url = "#{API_DOMAIN}/#{endpoint}" output = Utils::Curl.curl_output("--fail", api_url, max_time: 5) raise ArgumentError, "No file found at #{Tty.underline}#{api_url}#{Tty.reset}" unless output.success? cache[endpoint] = if json JSON.parse(output.stdout) else output.stdout end rescue JSON::ParserError raise ArgumentError, "Invalid JSON file: #{Tty.underline}#{api_url}#{Tty.reset}" end |