1 {-# LANGUAGE DeriveDataTypeable #-}
3 -- | A newtype around a list of Strings which represent the feed
4 -- hosts. This is all to avoid an orphan instance of Configured for
5 -- [String] if we had defined one in e.g. OptionalConfiguration.
7 -- This was placed under the "TSN" namespace because its Default
8 -- instance is specific to TSN, even though otherwise it's just a
14 -- DC is needed only for the DCT.Configured instance of String.
15 import qualified Data.Configurator as DC()
16 import qualified Data.Configurator.Types as DCT (
20 import Data.Data (Data)
21 import System.Console.CmdArgs.Default (Default(..))
22 import Data.Typeable (Typeable)
25 -- | A (wrapper around a) list of hostnames that supply the XML feed.
28 FeedHosts { get_feed_hosts :: [String] }
29 deriving (Data, Show, Typeable)
32 instance Default FeedHosts where
33 -- | The default list of feed hosts. These were found by checking
34 -- PTR records in the neighborhood of the IP address in use. There
35 -- is a feed4.sportsnetwork.com, but it was not operational when
37 def = FeedHosts ["feed1.sportsnetwork.com",
38 "feed2.sportsnetwork.com",
39 "feed3.sportsnetwork.com"]
42 instance DCT.Configured FeedHosts where
43 -- | This allows us to read a FeedHosts object out of a Configurator
44 -- config file. By default Configurator wouldn't know what to do,
45 -- so we have to tell it that we expect a list, and if that list
46 -- has strings in it, we can apply the FeedHosts constructor to
48 convert (DCT.List xs) =
49 -- mapM gives us a Maybe [String] here.
50 fmap FeedHosts (mapM convert_string xs)
52 convert_string :: DCT.Value -> Maybe String
53 convert_string = DCT.convert
55 -- If we read anything other than a list of values out of the file,