plaid v0.3.0 Plaid.Utilities

Utility functions for Plaid.

Summary

Functions

Encodes parameters for HTTP request body

Functions

encode_params(params, cred \\ %{})

Specs

encode_params(map, map) :: binary

Encodes parameters for HTTP request body.

Merges Plaid credentials with supplied parameters and encodes the result for submission as the HTTP request body.

Returns string.

Example

params = %{username: "plaid_test", password: "plaid_good", type: "wells",
           options: %{webhook: "http://requestb.in/", login_only: true,
           pending: true, list: true, start_date: "2015-01-01",
           end_date: "2015-03-31"}}
cred = %{client_id: "test_id", secret: "test_secret"}

"username=plaid_test&password=plaid_good&..." = Plaid.Utilities.encode_params(params, cred)
handle_plaid_response(response, schema)

Specs

handle_plaid_response({atom, any}, atom) :: {atom, any}
handle_plaid_response(map, atom) :: {atom, binary | map}

Handles Plaid response.

Routes success responses to the decoder which explicitly maps them to pre-defined structs based on the schema (provided as a parameter). Unsuccessful responses are mapped to the Plaid.Error struct.

Returns a Plaid data struct or HTTPoison.Error struct.

Example

{:ok, "test_bofa"} = Plaid.Utilities.handle_plaid_response(%HTTPoison.Response{body: "{...}"}, :token)