open_exchange_rates v0.3.0 OpenExchangeRates
This module contains all the helper methods for converting currencies
Summary
Functions
Returns a list of all available currencies
Returns the age of the cache in seconds
Get the conversion rate for a between two currencies”
Will convert a price from once currency to another
bang method of convert/3 Will either return the result or raise when there was an error
examples
Converts a price and returns a properly formatted string for the given currency
Bang version of convert_and_format/3 Will either return the result or raise when there was an error
Will convert cents from once currency to another
bang method of convert_cents/3 Will either return the result or raise when there was an error
example
Converts cents and returns a properly formatted string for the given currency
Bang version of convert_cents_and_format/3 Will either return the result or raise when there was an error
Functions
Specs
available_currencies :: [String.t]
Returns a list of all available currencies.
example
iex> OpenExchangeRates.available_currencies |> Enum.take(10)
["AWG", "NAD", "INR", "LAK", "BOB", "MOP", "QAR", "SDG", "TMT", "BRL"]
Specs
cache_age :: Integer.t
Returns the age of the cache in seconds
example
OpenExchangeRates.cache_age
25341
Get the conversion rate for a between two currencies”
Example
iex> OpenExchangeRates.conversion_rate(:EUR, :GBP)
{:ok, 0.8481186252771619}
Specs
Will convert a price from once currency to another
example
iex> OpenExchangeRates.convert(100.00, :EUR, :GBP)
{:ok, 84.81186252771619}
Specs
bang method of convert/3 Will either return the result or raise when there was an error
examples
iex> OpenExchangeRates.convert!(100.00, :EUR, :GBP)
84.81186252771619
iex> OpenExchangeRates.convert!(100, :EUR, :GBP)
84.81186252771619
Converts a price and returns a properly formatted string for the given currency.
Examples
iex> OpenExchangeRates.convert_and_format(1234, :EUR, :AUD)
{:ok, "A$1,795.10"}
Bang version of convert_and_format/3 Will either return the result or raise when there was an error
#example
iex> OpenExchangeRates.convert_and_format!(1234567, :EUR, :USD)
"$1,368,699.56"
Specs
Will convert cents from once currency to another
example
iex> OpenExchangeRates.convert_cents(100, :GBP, :AUD)
{:ok, 172}
Specs
bang method of convert_cents/3 Will either return the result or raise when there was an error
example
iex> OpenExchangeRates.convert_cents!(100, :GBP, :AUD)
172
Converts cents and returns a properly formatted string for the given currency.
Examples
iex> OpenExchangeRates.convert_cents_and_format(1234567, :EUR, :CAD)
{:ok, "C$18,026.07"}
iex> OpenExchangeRates.convert_cents_and_format(1234567, :EUR, :USD)
{:ok, "$13,687"}
iex> OpenExchangeRates.convert_cents_and_format(1234567, :USD, :EUR)
{:ok, "€11.135,79"}
iex> OpenExchangeRates.convert_cents_and_format(1234567, :EUR, :NOK)
{:ok, "116.495,78NOK"}
Bang version of convert_cents_and_format/3 Will either return the result or raise when there was an error
#example
iex> OpenExchangeRates.convert_cents_and_format!(1234567, :EUR, :USD)
"$13,687"