shopify v0.4.0 Shopify.Adapters.MockUtils

Some useful functions to help implementing a mock adapter.

Link to this section Summary

Functions

Filter resources if query params given and the resource is a list

Puts an id into resources, usefull for create options that would otherwise return the resource built from the body without an id

Link to this section Functions

Filter resources if query params given and the resource is a list.

This is a naive implementation that will fail whenever the query parameter keys do not correspond to the resource keys.

Examples

iex> Shopify.Adapters.MockUtils.filter_resources({:ok, %Shopify.Response{data: [%{a: "a"}, %{a: "b"}]}}, %Shopify.Request{query_params: %{a: "a"}})
{:ok, %Shopify.Response{code: nil, data: [%{a: "a"}]}}

iex> Shopify.Adapters.MockUtils.filter_resources({:ok, %Shopify.Response{data: [%{a: "a"}, %{a: "b"}, %{a: "c"}]}}, %Shopify.Request{query_params: %{a: ["a", "b"]}})
{:ok, %Shopify.Response{code: nil, data: [%{a: "a"}, %{a: "b"}]}}
Link to this function put_id(raw_resource, id \\ 1)
put_id(map() | [map()], integer()) :: map()

Puts an id into resources, usefull for create options that would otherwise return the resource built from the body without an id.