Skip to content

Instantly share code, notes, and snippets.

@bryannaegele
Created June 13, 2024 16:35
Show Gist options
  • Save bryannaegele/4b9d11bc927d3887267028d1ea9f64f9 to your computer and use it in GitHub Desktop.
Save bryannaegele/4b9d11bc927d3887267028d1ea9f64f9 to your computer and use it in GitHub Desktop.
defmodule PackageTest do
def main() do
Hex.start()
[package, _] = System.argv()
package(nil, package)
|> :json.encode()
|> IO.iodata_to_binary()
|> IO.puts()
end
defp package(organization, package) do
auth = organization && Mix.Tasks.Hex.auth_info(:read)
case Hex.API.Package.get(organization, package, auth) do
{:ok, {code, body, _}} when code in 200..299 ->
body
{:ok, {404, _, _}} ->
Hex.Shell.error("No package with name #{package}")
Mix.Tasks.Hex.set_exit_code(1)
other ->
Hex.Shell.error("Failed to retrieve package information")
Hex.Utils.print_error_result(other)
Mix.Tasks.Hex.set_exit_code(1)
end
end
end
PackageTest.main()
# `mix run hex-package-demo.exs jason --no-mix-exs`
{
"configs": {
"erlang.mk": "dep_jason = hex 1.4.1",
"mix.exs": "{:jason, \"~> 1.4\"}",
"rebar.config": "{jason, \"1.4.1\"}"
},
"docs_html_url": "https://hexdocs.pm/jason/",
"downloads": { "all": 159921943, "day": 70521, "recent": 5040609, "week": 378615 },
"html_url": "https://hex.pm/packages/jason",
"inserted_at": "2017-12-22T09:32:40Z",
"latest_stable_version": "1.4.1",
"latest_version": "1.5.0-alpha.2",
"meta": {
"description": "A blazing fast JSON parser and generator in pure Elixir.",
"licenses": ["Apache-2.0"],
"links": { "GitHub": "https://github.com/michalmuskala/jason" },
"maintainers": []
},
"name": "jason",
"owners": [
{
"email": "michal@muskala.eu",
"url": "https://hex.pm/api/users/michalmuskala",
"username": "michalmuskala"
}
],
"releases": [
{
"has_docs": true,
"inserted_at": "2023-07-07T10:11:17Z",
"url": "https://hex.pm/api/packages/jason/releases/1.5.0-alpha.2",
"version": "1.5.0-alpha.2"
},
{
"has_docs": true,
"inserted_at": "2022-10-16T20:11:41Z",
"url": "https://hex.pm/api/packages/jason/releases/1.5.0-alpha.1",
"version": "1.5.0-alpha.1"
},
{
"has_docs": true,
"inserted_at": "2023-07-07T09:28:26Z",
"url": "https://hex.pm/api/packages/jason/releases/1.4.1",
"version": "1.4.1"
},
{
"has_docs": true,
"inserted_at": "2022-09-12T19:53:18Z",
"url": "https://hex.pm/api/packages/jason/releases/1.4.0",
"version": "1.4.0"
},
{
"has_docs": true,
"inserted_at": "2021-12-21T14:22:24Z",
"url": "https://hex.pm/api/packages/jason/releases/1.3.0",
"version": "1.3.0"
},
{
"has_docs": true,
"inserted_at": "2020-09-08T20:01:45Z",
"url": "https://hex.pm/api/packages/jason/releases/1.2.2",
"version": "1.2.2"
},
{
"has_docs": true,
"inserted_at": "2020-05-04T19:46:36Z",
"url": "https://hex.pm/api/packages/jason/releases/1.2.1",
"version": "1.2.1"
},
{
"has_docs": true,
"inserted_at": "2020-03-17T21:22:55Z",
"url": "https://hex.pm/api/packages/jason/releases/1.2.0",
"version": "1.2.0"
},
{
"has_docs": true,
"inserted_at": "2018-10-19T18:01:19Z",
"url": "https://hex.pm/api/packages/jason/releases/1.1.2",
"version": "1.1.2"
},
{
"has_docs": true,
"inserted_at": "2018-07-10T20:14:17Z",
"url": "https://hex.pm/api/packages/jason/releases/1.1.1",
"version": "1.1.1"
},
{
"has_docs": true,
"inserted_at": "2018-07-02T18:18:58Z",
"url": "https://hex.pm/api/packages/jason/releases/1.1.0",
"version": "1.1.0"
},
{
"has_docs": true,
"inserted_at": "2018-07-02T10:08:56Z",
"url": "https://hex.pm/api/packages/jason/releases/1.0.1",
"version": "1.0.1"
},
{
"has_docs": true,
"inserted_at": "2018-01-26T09:58:27Z",
"url": "https://hex.pm/api/packages/jason/releases/1.0.0",
"version": "1.0.0"
},
{
"has_docs": true,
"inserted_at": "2018-01-26T09:40:44Z",
"url": "https://hex.pm/api/packages/jason/releases/1.0.0-rc.3",
"version": "1.0.0-rc.3"
},
{
"has_docs": true,
"inserted_at": "2018-01-07T10:14:28Z",
"url": "https://hex.pm/api/packages/jason/releases/1.0.0-rc.2",
"version": "1.0.0-rc.2"
},
{
"has_docs": true,
"inserted_at": "2017-12-22T09:32:40Z",
"url": "https://hex.pm/api/packages/jason/releases/1.0.0-rc.1",
"version": "1.0.0-rc.1"
}
],
"repository": "hexpm",
"retirements": {},
"updated_at": "2023-07-07T10:11:20Z",
"url": "https://hex.pm/api/packages/jason"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment