defmodule Fintech.Fio.Account do @moduledoc """ FIO Banka - account. """ @doc """ Get token from parameter or config value. ## Examples iex> Fintech.Fio.Account.token "abcdefghijklmnopqrstuvwxyz01234567890" """ def token(token \\ nil) do token || Application.get_env(:fintech, Fintech.Fio.Account)[:token] end @doc """ Get transactions of specified account. ## Examples iex> Fintech.Fio.Account.transactions "" """ def transactions(token \\ nil, from \\ "2007-01-01", to \\ Timex.format!(Timex.now, "%Y-%m-%d", :strftime)) do token = Fintech.Fio.Account.token(token) url = "https://www.fio.cz/ib_api/rest/periods/#{token}/#{from}/#{to}/transactions.json" case HTTPoison.get(url) do {:ok, res} -> case Poison.decode(res.body) do {:ok, ts} -> ts res -> res end _ -> nil end end end