From cd3326d4b6e0130f114ac293954a6b806466d2bf Mon Sep 17 00:00:00 2001 From: javierg Date: Tue, 23 Dec 2025 14:25:51 -0800 Subject: [PATCH 1/2] Support count response --- lib/cyphi/client/response.ex | 5 +++++ test/cyphi/client_test.exs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/cyphi/client/response.ex b/lib/cyphi/client/response.ex index 0be8b23..2fc5179 100644 --- a/lib/cyphi/client/response.ex +++ b/lib/cyphi/client/response.ex @@ -22,6 +22,7 @@ defmodule Cyphi.Client.Response do def decode({:ok, %Req.Response{status: status, body: body}}, %{ response: response_spec }) do + case List.keyfind(response_spec, status, 0) do {status, {module, type}} when status in [200, 201] -> {:ok, decode_body(body, module, type)} @@ -49,6 +50,10 @@ defmodule Cyphi.Client.Response do parse(module, map, type) end + defp parse(_module, %{"count" => count}, _type) do + count + end + defp parse(module, map, type) do attrs = module.__fields__(type) diff --git a/test/cyphi/client_test.exs b/test/cyphi/client_test.exs index 7f95f3e..86fe2e4 100644 --- a/test/cyphi/client_test.exs +++ b/test/cyphi/client_test.exs @@ -19,6 +19,18 @@ defmodule Cyphi.ClientTest do end) end + test "count list request returns amount" do + opts = %{ + method: :get, + url: "/badges", + response: [{200, [{Cyphi.Badge, :t}]}] + } + + with_response(%{status: 200, body: %{"count" => 10}}, fn -> + assert {:ok, 10} == Client.request(opts) + end) + end + test "single item request returns decoded response (GET)" do opts = %{ method: :get, From 6a08c6866cc0e4565dd644b29582e8d5c0b884ab Mon Sep 17 00:00:00 2001 From: javierg Date: Tue, 23 Dec 2025 14:38:04 -0800 Subject: [PATCH 2/2] remove extra space --- lib/cyphi/client/response.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cyphi/client/response.ex b/lib/cyphi/client/response.ex index 2fc5179..28202ff 100644 --- a/lib/cyphi/client/response.ex +++ b/lib/cyphi/client/response.ex @@ -22,7 +22,6 @@ defmodule Cyphi.Client.Response do def decode({:ok, %Req.Response{status: status, body: body}}, %{ response: response_spec }) do - case List.keyfind(response_spec, status, 0) do {status, {module, type}} when status in [200, 201] -> {:ok, decode_body(body, module, type)}