Module: Homebrew::API Private

Extended by:
Cachable, T::Sig
Defined in:
api.rb,
extend/os/linux/api/bottle.rb,
extend/os/linux/api/formula.rb,
extend/os/linux/api/analytics.rb,
api/cask.rb,
api/bottle.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, Bottle, 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"

Class Method Summary collapse

Methods included from Cachable

cache, clear_cache

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.

Parameters:

  • endpoint (String)
  • json (Boolean) (defaults to: true)

Returns:



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