-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the response mappers #17
Comments
How would you imagine an external lib using the response mapper? |
This is not my exact usecase but it demonstrates a usecase defmodule MyApp.EctoPlaidTransactions do
@behaviour Ecto.Type
def type, do: :map
def cast(%Plaid.Transactions{} = plaid_transactions) do
{:ok, plaid_transactions}
end
def cast(plaid_transactions) when is_map(plaid_transactions) do
# This is a bit hacky due to an unnecessary transform
with {:ok, plaid_transactions_binary} <- dump(plaid_transactions) do
cast(plaid_transactions_binary)
else
_ -> :error
end
end
def cast(plaid_transactions) when is_binary(plaid_transactions) do
# Currently `.map_body/2` is private though
Plaid.Utils.map_body(plaid_transactions, :transactions)
end
def dump(%Plaid.Transactions{} = plaid_transactions) do
Poison.encode(plaid_transactions)
end
end |
Gotcha. Yeah I can do that. |
Merged
@sitch would this PR address your issue? |
Yes sir! Very thanks 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently
Plaid.Utils.map_body/2
is privately defined, but this can be useful externally to libs. For instance, implementing anEcto.Type
behaviour.This parsing functionality could be safely moved into its own module and called from
Plaid.Utils.handle_resp/2
to maintain the existing public signature.Moving this to somewhere like
Plaid.Middlewares.ResponseHandler
makes a lot of sense to me.The text was updated successfully, but these errors were encountered: