New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor API methods #11831
Refactor API methods #11831
Conversation
Review period will end on 2021-08-09 at 08:31:56 UTC. |
After this PR, I'll open one that adds |
Review period ended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this cleanup. Some improved test coverage would be nice but both that and my comment are non-blocking.
I wrote some tests for |
Fine with me 👍🏻 |
https://github.com/Homebrew/homebrew-core/pull/83028/checks?check_run_id=3283057919#step:7:37 🙈 |
Oops, thanks! Fix in #11839 |
Should be fixed now @carlocab @dtrodrigues |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This PR refactors all calls to
https://formulae.brew.sh/api/
into a newHomebrew::API
module. I think this makes it easier to understand what's happening and also allows for some shared logic between them (i.e. fetching and parsing a JSON file). This is mainly motivated by the (in my opinion) poorly-namesBottleAPI
module. Now, some of the functionality from that module has been moved toHomebrew::API::Bottle
, and some toHomebrew::API::Versions
.Now, these are the modules and functions available after using
require "api"
Homebrew::API
: Helper module but can be used for any API call::fetch(endpoint, json: false)
: Takes anendpoint
(e.g.formula/wget.json
) and returns the API response (parsing to JSON if desired)Homebrew::API::Analytics
: For/api/analytics
or/api/analytics-linux
::fetch(category, days)
: Makes a request to/api/analytics/{category}/{days}d.json
or/api/analytics-linux/{category}/{days}d.json
Homebrew::API::Bottle
: For/api/bottle
or/api/bottle-linux
::fetch(name)
: Makes a request to/api/bottle/{name}.json
or/api/bottle-linux/{name}.json
BottleAPI
module includingavailable?
andfetch_bottles
(among others)Homebrew::API::Cask
: For/api/cask
(there's no way to call/api/cask.json
at the moment because this is not used anywhere)::fetch(token)
: Makes a request to/api/cask/{token}.json
Homebrew::API::Formula
: For/api/formula
or/api/formula-linux
(there's no way to call/api/formula.json
at the moment because this is not used anywhere)::fetch(name)
: Makes a request to/api/formula/{name}.json
or/api/formula-linux/{name}.json
Homebrew::API::Versions
: For/api/versions-{formulae,linux,casks}
::formula
: Makes a request to/api/versions-formulae
::linux
: Makes a request to/api/versions-linux
::casks
: Makes a request to/api/versions-casks
::latest_formula_version(name)
: Returns thePkgVersion
ofname
using/api/versions-formulae
or/api/versions-linux
::latest_cask_version(token)
: Returns theVersion
oftoken
using/api/versions-casks