Packages

A simple library for fetching and converting foreign exchange rates based on ECB data.

Current section

Files

Jump to
forex lib forex feed feed_sweet_xml_parser.ex
Raw

lib/forex/feed/feed_sweet_xml_parser.ex

defmodule Forex.Feed.SweetXmlParser do
@moduledoc """
This module implements the `Forex.Feed.Parser` behaviour using the SweetXml library.
"""
import SweetXml
@behaviour Forex.Feed.Parser
@path ~x"//gesmes:Envelope/Cube/Cube"l
@doc false
@impl true
def parse_rates(response_body) do
response_body
|> SweetXml.parse(dtd: :none)
|> SweetXml.xpath(@path,
time: ~x"./@time"s,
rates: [
~x"./Cube"l,
currency: ~x"./@currency"s,
rate: ~x"./@rate"s
]
)
end
end