From 1c0cf4cc68cfa8982b163c7371eeaed951c0356e Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Tue, 25 Jun 2024 15:22:19 +0200 Subject: [PATCH] Add UsageRecords and bump version --- .tool-versions | 4 +- CHANGELOG.md | 6 +++ README.md | 16 ++++++-- lib/lemon_ex/checkouts/checkouts.ex | 12 +++--- lib/lemon_ex/customers/customers.ex | 8 ++-- .../discount_redemptions.ex | 8 ++-- lib/lemon_ex/discounts/discounts.ex | 20 +++++----- lib/lemon_ex/files/files.ex | 8 ++-- lib/lemon_ex/license_keys/license_keys.ex | 8 ++-- lib/lemon_ex/order_items/order_items.ex | 8 ++-- lib/lemon_ex/orders/orders.ex | 8 ++-- lib/lemon_ex/products/products.ex | 8 ++-- lib/lemon_ex/request.ex | 34 ++++++++++------- lib/lemon_ex/stores/stores.ex | 8 ++-- .../subscription_invoices.ex | 8 ++-- lib/lemon_ex/subscriptions/subscriptions.ex | 16 ++++---- lib/lemon_ex/usage_records/usage_record.ex | 25 ++++++++++++ lib/lemon_ex/usage_records/usage_records.ex | 38 +++++++++++++++++++ lib/lemon_ex/users/users.ex | 4 +- lib/lemon_ex/variants/variants.ex | 8 ++-- mix.exs | 2 +- testing.livemd | 23 +++++++++++ 22 files changed, 194 insertions(+), 86 deletions(-) create mode 100644 lib/lemon_ex/usage_records/usage_record.ex create mode 100644 lib/lemon_ex/usage_records/usage_records.ex create mode 100644 testing.livemd diff --git a/.tool-versions b/.tool-versions index 510eaf4..6fe0c3d 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -elixir 1.15.7-otp-26 -erlang 26.1.2 +elixir 1.17.1-otp-27 +erlang 27.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b6159a..a2cc84d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.2.3 - 2024-06-25 + +* Add `UsageRecords` endpoints. +* Accept the API-key as a request option in all endpoints. +* Add a Livebook for easier local testing of endpoints. + ## v0.2.2 * Add `first_subscription_item` to Subscriptions diff --git a/README.md b/README.md index bc17894..84fa7bd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ An Elixir client for the API and Webhooks of LemonSqueezy. ```elixir def deps do [ - {:lemon_ex, "~> 0.2.2"} + {:lemon_ex, "~> 0.2.3"} ] end ``` @@ -21,7 +21,7 @@ To make API calls, you need to create an [API key](https://docs.lemonsqueezy.com ```elixir import Config -config :lemon_ex, +config :lemon_ex, api_key: System.get_env("LEMONSQUEEZY_API_KEY"), webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET"), # (Optional) You can provide HTTPoison options which are added to every request. @@ -29,6 +29,12 @@ config :lemon_ex, request_options: [timeout: 10_000] ``` +Alternatively, you can also pass the `api_key` as an option when you make a request, like this: + +```elixir +LemonEx.UsageRecords.list([], [api_key: "your-api-key"]) +``` + If you don't provide a valid API key, you will receive `401: Unauthorized` error responses. ## Making Requests @@ -139,11 +145,15 @@ You can use [ngrok](https://ngrok.com/) to proxy webhook events to your `localho 1. Install `ngrok` with e.g. `brew install --cask ngrok` 2. Start `ngrok` with `ngrok http 4000` -3. Copy the URL behind `Forwarding` that looks like this: `https://{identifier_here}.eu.ngrok.io` +3. Copy the URL behind `Forwarding` that looks like this: `https://{identifier_here}.eu.ngrok.io` 4. Create a new Webhook in [LemonSqueezy](https://app.lemonsqueezy.com/settings/webhooks) that points to the copied URL plus your endpoint. For example: `https://{identifier}.eu.ngrok.io/webhooks/lemonsqueezy` 5. Start your Phoenix application and enjoy! 6. (Optional): View the event payload in the `Ngrok Inspector` at [http://localhost:4040](http://localhost:4040) +## Testing Endpoints locally + +You can use the `testing.livemd` Livebook to test LemonEx endpoints locally. Simply start the Livebook, add your test api key as `LEMON_EX_API_KEY` to the livebook, and start testing. + ## Todos - [x] Add all schema objects diff --git a/lib/lemon_ex/checkouts/checkouts.ex b/lib/lemon_ex/checkouts/checkouts.ex index eec1f0c..78db3e3 100644 --- a/lib/lemon_ex/checkouts/checkouts.ex +++ b/lib/lemon_ex/checkouts/checkouts.ex @@ -3,7 +3,7 @@ defmodule LemonEx.Checkouts do alias LemonEx.Request alias LemonEx.PaginatedResponse - def create(store_id, variant_id, attributes) do + def create(store_id, variant_id, attributes, opts \\ []) do data = %{ type: "checkouts", attributes: attributes, @@ -25,19 +25,19 @@ defmodule LemonEx.Checkouts do payload = %{data: data} - with {:ok, %{"data" => body}} <- Request.post("/checkouts", payload) do + with {:ok, %{"data" => body}} <- Request.post("/checkouts", payload, opts) do {:ok, Checkout.from_json(body)} end end - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/checkouts/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/checkouts/#{id}", opts) do {:ok, Checkout.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/checkouts", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/checkouts", filter, opts) do {:ok, PaginatedResponse.from_json(body, Checkout)} end end diff --git a/lib/lemon_ex/customers/customers.ex b/lib/lemon_ex/customers/customers.ex index 13b7073..f7dc6f2 100644 --- a/lib/lemon_ex/customers/customers.ex +++ b/lib/lemon_ex/customers/customers.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Customers do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/customers/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/customers/#{id}", opts) do {:ok, Customer.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/customers", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/customers", filter, opts) do {:ok, PaginatedResponse.from_json(body, Customer)} end end diff --git a/lib/lemon_ex/discount_redemptions/discount_redemptions.ex b/lib/lemon_ex/discount_redemptions/discount_redemptions.ex index ee6764d..a42444b 100644 --- a/lib/lemon_ex/discount_redemptions/discount_redemptions.ex +++ b/lib/lemon_ex/discount_redemptions/discount_redemptions.ex @@ -3,14 +3,14 @@ defmodule LemonEx.DiscountRedemptions do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/discount-redemptions/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/discount-redemptions/#{id}", opts) do {:ok, DiscountRedemption.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/discount-redemptions", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/discount-redemptions", filter, opts) do {:ok, PaginatedResponse.from_json(body, DiscountRedemption)} end end diff --git a/lib/lemon_ex/discounts/discounts.ex b/lib/lemon_ex/discounts/discounts.ex index bbb8e90..7c09c81 100644 --- a/lib/lemon_ex/discounts/discounts.ex +++ b/lib/lemon_ex/discounts/discounts.ex @@ -3,7 +3,7 @@ defmodule LemonEx.Discounts do alias LemonEx.Request alias LemonEx.PaginatedResponse - def create(store_id, attributes) do + def create(store_id, attributes, opts \\ []) do data = %{ type: "discounts", attributes: attributes, @@ -19,34 +19,34 @@ defmodule LemonEx.Discounts do payload = %{data: data} - with {:ok, %{"data" => body}} <- Request.post("/discounts", payload) do + with {:ok, %{"data" => body}} <- Request.post("/discounts", payload, opts) do {:ok, Discount.from_json(body)} end end - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/discounts/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/discounts/#{id}", opts) do {:ok, Discount.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/discounts", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/discounts", filter, opts) do {:ok, PaginatedResponse.from_json(body, Discount)} end end - def update(id, data) do + def update(id, data, opts \\ []) do data = Map.merge(%{type: "discounts", id: to_string(id)}, data) payload = %{data: data} - with {:ok, %{"data" => body}} <- Request.patch("/discounts/#{id}", payload) do + with {:ok, %{"data" => body}} <- Request.patch("/discounts/#{id}", payload, opts) do {:ok, Discount.from_json(body)} end end @spec delete(any()) :: :ok | {:error, integer(), any()} | {:error, any()} - def delete(id) do - Request.delete("/discounts/#{id}") + def delete(id, opts \\ []) do + Request.delete("/discounts/#{id}", opts) end end diff --git a/lib/lemon_ex/files/files.ex b/lib/lemon_ex/files/files.ex index d2afd6e..7d8cbde 100644 --- a/lib/lemon_ex/files/files.ex +++ b/lib/lemon_ex/files/files.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Files do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/files/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/files/#{id}", opts) do {:ok, File.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/files", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/files", filter, opts) do {:ok, PaginatedResponse.from_json(body, File)} end end diff --git a/lib/lemon_ex/license_keys/license_keys.ex b/lib/lemon_ex/license_keys/license_keys.ex index d59bb1b..191396e 100644 --- a/lib/lemon_ex/license_keys/license_keys.ex +++ b/lib/lemon_ex/license_keys/license_keys.ex @@ -3,14 +3,14 @@ defmodule LemonEx.LicenseKeys do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/license-keys/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/license-keys/#{id}", opts) do {:ok, LicenseKey.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/license-keys", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/license-keys", filter, opts) do {:ok, PaginatedResponse.from_json(body, LicenseKey)} end end diff --git a/lib/lemon_ex/order_items/order_items.ex b/lib/lemon_ex/order_items/order_items.ex index 66c36f0..e34189a 100644 --- a/lib/lemon_ex/order_items/order_items.ex +++ b/lib/lemon_ex/order_items/order_items.ex @@ -3,14 +3,14 @@ defmodule LemonEx.OrderItems do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/order-items/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/order-items/#{id}", opts) do {:ok, OrderItem.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/order-items", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/order-items", filter, opts) do {:ok, PaginatedResponse.from_json(body, OrderItem)} end end diff --git a/lib/lemon_ex/orders/orders.ex b/lib/lemon_ex/orders/orders.ex index c70bb55..bd7703c 100644 --- a/lib/lemon_ex/orders/orders.ex +++ b/lib/lemon_ex/orders/orders.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Orders do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/orders/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/orders/#{id}", opts) do {:ok, Order.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/orders", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/orders", filter, opts) do {:ok, PaginatedResponse.from_json(body, Order)} end end diff --git a/lib/lemon_ex/products/products.ex b/lib/lemon_ex/products/products.ex index 3a210b5..0b9cc62 100644 --- a/lib/lemon_ex/products/products.ex +++ b/lib/lemon_ex/products/products.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Products do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/products/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/products/#{id}", opts) do {:ok, Product.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/products", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/products", filter, opts) do {:ok, PaginatedResponse.from_json(body, Product)} end end diff --git a/lib/lemon_ex/request.ex b/lib/lemon_ex/request.ex index da879fd..a866ff2 100644 --- a/lib/lemon_ex/request.ex +++ b/lib/lemon_ex/request.ex @@ -1,9 +1,10 @@ defmodule LemonEx.Request do @api_base_url "https://api.lemonsqueezy.com/v1" - @spec post(binary(), any()) :: {:ok, map()} | {:error, any()} | {:error, integer(), any()} - def post(url, payload) do - headers = get_headers() + @spec post(binary(), any(), keyword()) :: + {:ok, map()} | {:error, any()} | {:error, integer(), any()} + def post(url, payload, opts \\ []) do + headers = get_headers(opts) url = "#{@api_base_url}#{url}" payload = prepare_payload(payload) opts = request_options() @@ -11,9 +12,10 @@ defmodule LemonEx.Request do handle_response(response) end - @spec get(binary(), keyword()) :: {:ok, map()} | {:error, any()} | {:error, integer(), any()} - def get(url, params \\ []) do - headers = get_headers() + @spec get(binary(), keyword(), keyword()) :: + {:ok, map()} | {:error, any()} | {:error, integer(), any()} + def get(url, params \\ [], opts \\ []) do + headers = get_headers(opts) url = "#{@api_base_url}#{url}" params = prepare_params(params) opts = [params: params] ++ request_options() @@ -21,9 +23,10 @@ defmodule LemonEx.Request do handle_response(response) end - @spec patch(binary(), any()) :: {:ok, map()} | {:error, any()} | {:error, integer(), any()} - def patch(url, payload) do - headers = get_headers() + @spec patch(binary(), any(), keyword()) :: + {:ok, map()} | {:error, any()} | {:error, integer(), any()} + def patch(url, payload, opts \\ []) do + headers = get_headers(opts) url = "#{@api_base_url}#{url}" payload = prepare_payload(payload) opts = request_options() @@ -31,9 +34,10 @@ defmodule LemonEx.Request do handle_response(response) end - @spec delete(binary()) :: :ok | {:ok, map()} | {:error, any()} | {:error, integer(), any()} - def delete(url) do - headers = get_headers() + @spec delete(binary(), keyword()) :: + :ok | {:ok, map()} | {:error, any()} | {:error, integer(), any()} + def delete(url, opts \\ []) do + headers = get_headers(opts) url = "#{@api_base_url}#{url}" opts = request_options() response = HTTPoison.delete(url, headers, opts) @@ -48,9 +52,11 @@ defmodule LemonEx.Request do Application.get_env(:lemon_ex, :request_options, []) end - defp get_headers do + defp get_headers(opts) do + bearer_token = Keyword.get(opts, :api_key, api_key()) + [ - {"Authorization", "Bearer #{api_key()}"}, + {"Authorization", "Bearer #{bearer_token}"}, {"Accept", "application/vnd.api+json"}, {"Content-Type", "application/vnd.api+json"} ] diff --git a/lib/lemon_ex/stores/stores.ex b/lib/lemon_ex/stores/stores.ex index eb55b60..af16894 100644 --- a/lib/lemon_ex/stores/stores.ex +++ b/lib/lemon_ex/stores/stores.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Stores do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/stores/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/stores/#{id}", opts) do {:ok, Store.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/stores", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/stores", filter, opts) do {:ok, PaginatedResponse.from_json(body, Store)} end end diff --git a/lib/lemon_ex/subscription_invoices/subscription_invoices.ex b/lib/lemon_ex/subscription_invoices/subscription_invoices.ex index 7fd24c3..124347f 100644 --- a/lib/lemon_ex/subscription_invoices/subscription_invoices.ex +++ b/lib/lemon_ex/subscription_invoices/subscription_invoices.ex @@ -3,14 +3,14 @@ defmodule LemonEx.SubscriptionInvoices do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/subscription-invoices/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/subscription-invoices/#{id}", opts) do {:ok, SubscriptionInvoice.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/subscription-invoices", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/subscription-invoices", filter, opts) do {:ok, PaginatedResponse.from_json(body, SubscriptionInvoice)} end end diff --git a/lib/lemon_ex/subscriptions/subscriptions.ex b/lib/lemon_ex/subscriptions/subscriptions.ex index f3e80bd..0a570ee 100644 --- a/lib/lemon_ex/subscriptions/subscriptions.ex +++ b/lib/lemon_ex/subscriptions/subscriptions.ex @@ -3,29 +3,29 @@ defmodule LemonEx.Subscriptions do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/subscriptions/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/subscriptions/#{id}", opts) do {:ok, Subscription.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/subscriptions", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/subscriptions", filter, opts) do {:ok, PaginatedResponse.from_json(body, Subscription)} end end - def update(id, data) do + def update(id, data, opts \\ []) do data = Map.merge(%{type: "subscriptions", id: to_string(id)}, data) payload = %{data: data} - with {:ok, %{"data" => body}} <- Request.patch("/subscriptions/#{id}", payload) do + with {:ok, %{"data" => body}} <- Request.patch("/subscriptions/#{id}", payload, opts) do {:ok, Subscription.from_json(body)} end end - def cancel(id) do - with {:ok, %{"data" => body}} <- Request.delete("/subscriptions/#{id}") do + def cancel(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.delete("/subscriptions/#{id}", opts) do {:ok, Subscription.from_json(body)} end end diff --git a/lib/lemon_ex/usage_records/usage_record.ex b/lib/lemon_ex/usage_records/usage_record.ex new file mode 100644 index 0000000..437abff --- /dev/null +++ b/lib/lemon_ex/usage_records/usage_record.ex @@ -0,0 +1,25 @@ +defmodule LemonEx.UsageRecords.UsageRecord do + defstruct [ + :id, + :type, + :subscription_item_id, + :quantity, + :action, + :updated_at, + :created_at + ] + + def from_json(body) do + attributes = body["attributes"] + + %__MODULE__{ + id: body["id"], + type: body["type"], + subscription_item_id: attributes["subscription_item_id"], + quantity: attributes["quantity"], + action: attributes["action"], + updated_at: attributes["updated_at"], + created_at: attributes["created_at"] + } + end +end diff --git a/lib/lemon_ex/usage_records/usage_records.ex b/lib/lemon_ex/usage_records/usage_records.ex new file mode 100644 index 0000000..147d507 --- /dev/null +++ b/lib/lemon_ex/usage_records/usage_records.ex @@ -0,0 +1,38 @@ +defmodule LemonEx.UsageRecords do + alias LemonEx.UsageRecords.UsageRecord + alias LemonEx.Request + alias LemonEx.PaginatedResponse + + def create(subscription_id, attributes, opts \\ []) do + data = %{ + type: "usage-records", + attributes: attributes, + relationships: %{ + subscription_item: %{ + data: %{ + type: "subscription-items", + id: to_string(subscription_id) + } + } + } + } + + payload = %{data: data} + + with {:ok, %{"data" => body}} <- Request.post("/usage-records", payload, opts) do + {:ok, UsageRecord.from_json(body)} + end + end + + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/usage-records/#{id}", opts) do + {:ok, UsageRecord.from_json(body)} + end + end + + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/usage-records", filter, opts) do + {:ok, PaginatedResponse.from_json(body, UsageRecord)} + end + end +end diff --git a/lib/lemon_ex/users/users.ex b/lib/lemon_ex/users/users.ex index 10229af..82ec934 100644 --- a/lib/lemon_ex/users/users.ex +++ b/lib/lemon_ex/users/users.ex @@ -2,8 +2,8 @@ defmodule LemonEx.Users do alias LemonEx.Users.User alias LemonEx.Request - def get_authenticated_user do - with {:ok, body} <- Request.get("/users/me") do + def get_authenticated_user(opts \\ []) do + with {:ok, body} <- Request.get("/users/me", opts) do {:ok, User.from_json(body)} end end diff --git a/lib/lemon_ex/variants/variants.ex b/lib/lemon_ex/variants/variants.ex index dd9963d..75c8697 100644 --- a/lib/lemon_ex/variants/variants.ex +++ b/lib/lemon_ex/variants/variants.ex @@ -3,14 +3,14 @@ defmodule LemonEx.Variants do alias LemonEx.Request alias LemonEx.PaginatedResponse - def get(id) do - with {:ok, %{"data" => body}} <- Request.get("/variants/#{id}") do + def get(id, opts \\ []) do + with {:ok, %{"data" => body}} <- Request.get("/variants/#{id}", opts) do {:ok, Variant.from_json(body)} end end - def list(filter \\ []) do - with {:ok, body} <- Request.get("/variants", filter) do + def list(filter \\ [], opts \\ []) do + with {:ok, body} <- Request.get("/variants", filter, opts) do {:ok, PaginatedResponse.from_json(body, Variant)} end end diff --git a/mix.exs b/mix.exs index 471a729..9d77120 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule LemonEx.MixProject do use Mix.Project - @version "0.2.2" + @version "0.2.3" @source_url "https://github.com/PJUllrich/lemon_ex" def project do diff --git a/testing.livemd b/testing.livemd new file mode 100644 index 0000000..82534e3 --- /dev/null +++ b/testing.livemd @@ -0,0 +1,23 @@ +# Testing LemonEx Locally + +```elixir +Mix.install( + [{:lemon_ex, path: __DIR__, env: :dev}], + config_path: __DIR__ <> "/config/config.exs" +) +``` + +## Load the API Key + +```elixir +api_key = System.get_env("LB_LEMON_EX_API_KEY") +opts = [api_key: api_key] +``` + +## Testing + +```elixir +LemonEx.UsageRecords.list([], opts) +``` + +