Skip to content

Commit

Permalink
WIP: add response helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Jul 23, 2023
1 parent adb4e4a commit 874d1fa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/ex_ipfs/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,20 @@ defmodule ExIpfs.Utils do
_ -> data
end
end

def map_has_keys?(response, expected_keys) do
if Enum.all?(expected_keys, &Map.has_key?(response, &1)) do
response
else
raise ArgumentError, message: "Missing some of #{inspect(expected_keys)} in response from IPFS API"
end
end

def map_get_key!(response, key) do
case response do
%{^key => value} -> value
_ -> raise ArgumentError, message: "Problem extracting #{inspect(key)} from response from IPFS API"
end
end

end

0 comments on commit 874d1fa

Please sign in to comment.