Money v0.4.1 Money.ExchangeRates behaviour View Source

Implements functions to retrieve exchange rates from Open Exchange Rates.

An app_id is required and is configured in config.exs of the appropriate environment configuration file. The app_id can be configured as either a string or as a tuple {:system, "shell variable name"} to ease runtime retrieval of the app_id.

Example configurations

config :ex_money,
  open_exchange_rates_app_id: "app_id_string",
  open_exchange_rates_retrieve_every: 300_000

config :ex_money,
  open_exchange_rates_app_id: {:system, "OPEN_EXCHANGE_RATES_APP_ID"},
  open_exchange_rates_retrieve_every: 300_000

Link to this section Summary

Functions

Returns the configuration for the exchange rates retriever

Retrieves exchange rates from the configured exchange rate api module

Return the timestamp of the last successful retrieval of exchange rates or {:error, reason} if no timestamp is known

Return the latest exchange rates

Returns true if exchange rates are available and false otherwise

Forces retrieval of exchange rates

Callbacks

Defines the behaviour to retrieve exchange rates from an external data source

Link to this section Functions

Returns the configuration for the exchange rates retriever.

Retrieves exchange rates from the configured exchange rate api module.

This call is the public api to retrieve results from an external api service or other mechanism implemented by an api module. This method is typically called periodically by Money.ExchangeRates.Retriever.handle_info/2 but can called at any time by other functions.

Link to this function last_updated() View Source
last_updated ::
  {:ok, DateTime.t} |
  {:error, {Exception.t, binary}}

Return the timestamp of the last successful retrieval of exchange rates or {:error, reason} if no timestamp is known.

Example

Money.ExchangeRates.last_updated
#> {:ok,
 %DateTime{calendar: Calendar.ISO, day: 20, hour: 12, microsecond: {731942, 6},
  minute: 36, month: 11, second: 6, std_offset: 0, time_zone: "Etc/UTC",
  utc_offset: 0, year: 2016, zone_abbr: "UTC"}}
Link to this function latest_rates() View Source
latest_rates() :: {:ok, Map.t} | {:error, {Exception.t, binary}}

Return the latest exchange rates.

Returns:

  • {:ok, rates} if exchange rates are successfully retrieved. rates is a map of exchange rate converstion.

  • {:error, reason} if no exchange rates can be returned.

Link to this function rates_available?() View Source
rates_available?() :: boolean

Returns true if exchange rates are available and false otherwise.

Forces retrieval of exchange rates

Sends a message ot the exchange rate retrieval worker to request rates be retrieved.

This function does not return exchange rates, for that see Money.ExchangeRates.latest_rates/0.

Link to this section Callbacks

Link to this callback get_latest_rates() View Source
get_latest_rates() :: {:ok, %{}} | {:error, binary}

Defines the behaviour to retrieve exchange rates from an external data source