Packages

Project repository template to set up all public Phoenix projects at Nimble

Current section

Files

Jump to
nimble_phx_gen_template lib nimble.phx.gen.template hex hex_client.ex
Raw

lib/nimble.phx.gen.template/hex/hex_client.ex

defmodule Nimble.Phx.Gen.Template.Hex.HexClient do
alias Nimble.Phx.Gen.Template.HttpClient.HttpAdapter
@base_url "https://hex.pm/api/"
def get(path) do
url = @base_url <> URI.encode(path)
case HttpAdapter.get(url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
{:ok, Jason.decode!(body)}
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
end
end
end