Skip to content

Commit 3271e4d

Browse files
committed
Ability to get catalog
1 parent c55f9a9 commit 3271e4d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/beanie/registry_api.ex

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
defmodule Beanie.RegistryAPI do
2+
defmodule Registry do
3+
defstruct(location: nil, user: nil, password: nil, http_client: HTTPotion)
4+
5+
def at_url(location, user \\ nil, password \\ nil) do
6+
%Registry{
7+
location: location,
8+
user: user,
9+
password: password
10+
}
11+
end
12+
13+
def url(registry = %Registry{}, path) do
14+
[
15+
registry.location,
16+
"v2",
17+
path
18+
]
19+
|> Enum.join("/")
20+
end
21+
22+
def get(registry = %Registry{}, path) do
23+
response = registry.http_client.get!(
24+
url(registry, path),
25+
[basic_auth: {registry.user, registry.password}]
26+
)
27+
Poison.decode!(response.body)
28+
end
29+
end
30+
31+
def catalog(registry = %Registry{}) do
32+
Registry.get(registry, "_catalog")
33+
end
34+
end

mix.exs

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ defmodule Beanie.Mixfile do
1818
# Type `mix help compile.app` for more information.
1919
def application do
2020
[mod: {Beanie, []},
21-
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
22-
:phoenix_ecto, :postgrex]]
21+
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger,
22+
:gettext, :phoenix_ecto, :postgrex, :httpotion]]
2323
end
2424

2525
# Specifies which paths to compile per environment.
@@ -36,6 +36,8 @@ defmodule Beanie.Mixfile do
3636
{:postgrex, ">= 0.0.0"},
3737
{:phoenix_html, "~> 2.6"},
3838
{:phoenix_live_reload, "~> 1.0", only: :dev},
39+
{:httpotion, "~>3.0.1"},
40+
{:poison, "~>2.2.0"},
3941
{:gettext, "~> 0.11"},
4042
{:cowboy, "~> 1.0"}]
4143
end

mix.lock

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"ecto": {:hex, :ecto, "2.0.5", "7f4c79ac41ffba1a4c032b69d7045489f0069c256de606523c65d9f8188e502d", [:mix], [{:db_connection, "~> 1.0-rc.4", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.1.2 or ~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.12.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}]},
77
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []},
88
"gettext": {:hex, :gettext, "0.11.0", "80c1dd42d270482418fa158ec5ba073d2980e3718bacad86f3d4ad71d5667679", [:mix], []},
9+
"httpotion": {:hex, :httpotion, "3.0.1", "6165e7fe4052dfeadd4b480e4ed6619975242ac91d577e4868af92613f9e99df", [:mix], [{:ibrowse, "~> 4.2", [hex: :ibrowse, optional: false]}]},
10+
"ibrowse": {:hex, :ibrowse, "4.2.2", "b32b5bafcc77b7277eff030ed32e1acc3f610c64e9f6aea19822abcadf681b4b", [:rebar3], []},
911
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []},
1012
"phoenix": {:hex, :phoenix, "1.2.1", "6dc592249ab73c67575769765b66ad164ad25d83defa3492dc6ae269bd2a68ab", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.1", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
1113
"phoenix_ecto": {:hex, :phoenix_ecto, "3.0.1", "42eb486ef732cf209d0a353e791806721f33ff40beab0a86f02070a5649ed00a", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, optional: false]}, {:phoenix_html, "~> 2.6", [hex: :phoenix_html, optional: true]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}]},

0 commit comments

Comments
 (0)