Packages

A type-safe CoinGecko API client for Gleam

Current section

Files

Jump to
coinglecko src coinglecko@client.erl
Raw

src/coinglecko@client.erl

-module(coinglecko@client).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/coinglecko/client.gleam").
-export([base_url/1, api_key/1, api_tier/1, new_demo/1, new_pro/1]).
-export_type([api_tier/0, client/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Configuration and client construction for the CoinGecko API.\n").
-type api_tier() :: demo | pro.
-opaque client() :: {client, binary(), binary(), api_tier()}.
-file("src/coinglecko/client.gleam", 44).
?DOC(" Get the base URL from the client.\n").
-spec base_url(client()) -> binary().
base_url(Client) ->
erlang:element(2, Client).
-file("src/coinglecko/client.gleam", 49).
?DOC(" Get the API key from the client.\n").
-spec api_key(client()) -> binary().
api_key(Client) ->
erlang:element(3, Client).
-file("src/coinglecko/client.gleam", 54).
?DOC(" Get the API tier from the client.\n").
-spec api_tier(client()) -> api_tier().
api_tier(Client) ->
erlang:element(4, Client).
-file("src/coinglecko/client.gleam", 27).
?DOC(
" Create a client for the CoinGecko Demo (free) API.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let client = client.new_demo(api_key: \"CG-your-key-here\")\n"
" ```\n"
).
-spec new_demo(binary()) -> client().
new_demo(Key) ->
{client, <<"https://api.coingecko.com/api/v3"/utf8>>, Key, demo}.
-file("src/coinglecko/client.gleam", 39).
?DOC(
" Create a client for the CoinGecko Pro (paid) API.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let client = client.new_pro(api_key: \"CG-your-pro-key\")\n"
" ```\n"
).
-spec new_pro(binary()) -> client().
new_pro(Key) ->
{client, <<"https://pro-api.coingecko.com/api/v3"/utf8>>, Key, pro}.