Fixerio v0.1.0 Fixerio View Source

Provides access to Fixer.io like API with support for multiple endpoint to use as fallback.

Link to this section Summary

Functions

Coverts the given amount from the from currency to to currency, optionally based on rate of a specific day.

Gets the latest conversion rates. Uses the /latest API endpoint.

Gets the conversion rates on a day in past.

Link to this section Functions

Link to this function

convert(amount, from, to, date \\ nil)

View Source

Coverts the given amount from the from currency to to currency, optionally based on rate of a specific day.

parameters:

  • amount (required): Integer - the amount to be converted
  • from (required): Atom - current currency of the amount
  • to (required): Atom - converted currency of the amount
  • date (optional): Date - rate of the day to be used

Returns: below data format in case of success

  {:ok,
    %{
      date: "2019-08-09",
      info: %{rate: 0.8930166101, timestamp: 1565380266},
      query: %{amount: 90000, from: :USD, to: :EUR},
      result: 80371.494909
    }
  }

or

{:error, "Failed. No API available."} in case of failure

Examples

iex> Fixerio.convert(90000, :USD, :EUR) {:ok, %{

date: "2019-08-09",
info: %{rate: 0.8930166101, timestamp: 1565380266},
query: %{amount: 90000, from: :USD, to: :EUR},
result: 80371.494909

}}

Link to this function

get_latest(options \\ %{base: :EUR})

View Source

Gets the latest conversion rates. Uses the /latest API endpoint.

parameters:

  • options (optioal): Map with optional keys base and symbols

Returns: %{ base: "USD", date: "2019-08-09", rates: %{ "AUD" => 1.46, "CZK" => 23.064, "IDR" => 14189.998, ... }} in case of success {:error, %{errors: []} in case of failure

Examples

iex> Fixerio.get_latest %{base: :USD} {:ok, %{

base: "USD",
date: "2019-08-09",
rates: %{
  "AUD" => 1.469190927,
  "CZK" => 23.0648330059,
  "IDR" => 14189.9982139668,
  .
  .
  .
}

}}

iex> Fixerio.get_latest %{base: :USD} {:error, %{

errors: [
  %{reason: "not found", url: "https://my-api.herokuapp.com"},
  %{
    reason: "Error. base_currency_access_restricted",
    url: "http://data.fixer.io"
  }
]

}}

iex> Fixerio.get_latest(%{symbols: [:AUD, :BRL, :CNY]}) {:ok, %{

base: "USD",
date: "2019-08-09",
rates: %{"AUD" => 1.469190927, "BRL" => 3.9287372745, "CNY" => 7.0583139846}

}}

Link to this function

historical_data(date, options \\ %{base: :EUR})

View Source

Gets the conversion rates on a day in past.

parameters:

  • date (required): Date
  • options (optioal): Map with optional keys base and symbols

Returns: %{ base: "USD", date: "2019-08-09", rates: %{ "AUD" => 1.46, "CZK" => 23.064, "IDR" => 14189.998, ... }} in case of success {:error, %{errors: []} in case of failure

Examples

iex> Fixerio.historical_data(Date.utc_today) {:ok, %{

base: "EUR",
date: "2019-08-09",
rates: %{
  "AUD" => 1.6452,
  "BGN" => 1.9558,
  "BRL" => 4.3994,
  .
  .
  .
}

}}