eurofxref 0.1.0 → 0.1.1
raw patch · 3 files changed
+37/−4 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Financial.EuroFXRef: ECBHttpException :: HttpException -> EuropeanCentralBankException
+ Financial.EuroFXRef: ECBHttpStatusException :: Status -> EuropeanCentralBankException
+ Financial.EuroFXRef: ECBParseException :: String -> EuropeanCentralBankException
+ Financial.EuroFXRef: ECBXMLParseException :: XMLParseError -> EuropeanCentralBankException
+ Financial.EuroFXRef: data EuropeanCentralBankException
Files
- Financial/EuroFXRef.hs +9/−3
- eurofxref.cabal +2/−1
- example.hs +26/−0
Financial/EuroFXRef.hs view
@@ -12,6 +12,7 @@ module Financial.EuroFXRef ( -- * Simple fetch,+ EuropeanCentralBankException(..), -- * Lower-level europeanCentralBankDaily, fetchFrom,@@ -92,7 +93,10 @@ europeanCentralBankDaily :: Failure HttpException m => m (HTTP.Request m) europeanCentralBankDaily = parseUrl "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml" --- | Fetch from a specified URL.+-- | Fetch today's currency rates from the specified URL.+--+-- Throws a 'EuropeanCentralBankException' for failures at HTTP and above,+-- or 'IOException' for network-level failures. fetchFrom :: (Failure EuropeanCentralBankException m, Failure HttpException m, MonadIO m, Read a) => HTTP.Request m -> m (Rates a)@@ -116,9 +120,11 @@ Right rates -> return rates _ -> lift $ failure $ ECBHttpStatusException status --- | Fetch daily currency rates from European Central Bank server.---+-- | Fetch today's currency rates from European Central Bank server. -- 'IO' works for @m@ and 'Double' for @a@.+--+-- Throws a 'EuropeanCentralBankException' for failures at HTTP and above,+-- or 'IOException' for network-level failures. fetch :: (Failure EuropeanCentralBankException m, Failure HttpException m, MonadIO m, Read a) => m (Rates a) fetch = fetchFrom =<< europeanCentralBankDaily
eurofxref.cabal view
@@ -1,5 +1,5 @@ name: eurofxref-version: 0.1.0+version: 0.1.1 cabal-version: >=1.6 build-type: Simple license: BSD3@@ -15,6 +15,7 @@ A Haskell API for the the European Central Bank's free daily currency reference rates. category: Finance author: Stephen Blackheath+data-files: example.hs Library build-depends: base >=4 && <5, bytestring == 0.9.*, containers >= 0.2 && < 0.5,
+ example.hs view
@@ -0,0 +1,26 @@+import Financial.EuroFXRef+import Network.HTTP.Enumerator (parseUrl)+import Control.Applicative+import Control.Exception+import Control.Monad+import qualified Data.Map as M+import Data.Time.Format+import Prelude hiding (catch)+import System.Locale (defaultTimeLocale)++main = do+ r <- rebase (Currency "USD") <$> fetch+ dumpRates r+ `catch` (\exc -> do+ putStrLn $ "FAILED: "++show (exc :: EuropeanCentralBankException)+ return ())+ `catch` (\exc -> do+ putStrLn $ "IOException: "++show (exc :: IOException)+ return ())++dumpRates :: Rates Double -> IO ()+dumpRates r = do+ let Currency cur = raReference r+ putStrLn $ "The value of "++ cur ++ " 1 in each currency on "++formatTime defaultTimeLocale "%F" (raTime r)+ forM_ (M.assocs . raRates $ r) $ \(Currency cur, rate) -> do+ putStrLn $ cur ++ " " ++ show rate