diff --git a/lib/cyphi/client/response.ex b/lib/cyphi/client/response.ex index 0be8b23..28202ff 100644 --- a/lib/cyphi/client/response.ex +++ b/lib/cyphi/client/response.ex @@ -49,6 +49,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,