X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFeedHosts.hs;h=58f82f57ae9d4ad29cec82c59a5ac29f02952cb2;hb=HEAD;hp=43bab176aa67efeaba8e6a045aa1ae9d8057481d;hpb=d4d924b26e451aec9ad84b6d9d376ba2aeab3422;p=dead%2Fhtsn.git diff --git a/src/FeedHosts.hs b/src/FeedHosts.hs index 43bab17..58f82f5 100644 --- a/src/FeedHosts.hs +++ b/src/FeedHosts.hs @@ -1,25 +1,38 @@ {-# LANGUAGE DeriveDataTypeable #-} -- | A newtype around a list of Strings which represent the feed --- hosts. This is all to avoid an orphan instance of Configured for --- [String] if we had defined one in e.g. OptionalConfiguration. +-- hosts. This is all to avoid an orphan instance of Configured for +-- [String] if we had defined one in e.g. 'OptionalConfiguration'. +-- +-- This was placed under the \"TSN\" namespace because its Default +-- instance is specific to TSN, even though otherwise it's just a +-- list of strings. -- module FeedHosts where -- DC is needed only for the DCT.Configured instance of String. import qualified Data.Configurator as DC() -import qualified Data.Configurator.Types as DCT +import qualified Data.Configurator.Types as DCT ( + Configured, + Value( List ), + convert ) import Data.Data (Data) import System.Console.CmdArgs.Default (Default(..)) import Data.Typeable (Typeable) +-- | A (wrapper around a) list of hostnames that supply the XML feed. +-- newtype FeedHosts = FeedHosts { get_feed_hosts :: [String] } deriving (Data, Show, Typeable) +-- | The default list of feed hosts. These were found by checking +-- PTR records in the neighborhood of the IP address in use. There +-- is a feed4.sportsnetwork.com, but it was not operational when +-- this was written. instance Default FeedHosts where def = FeedHosts ["feed1.sportsnetwork.com", "feed2.sportsnetwork.com", @@ -27,11 +40,18 @@ instance Default FeedHosts where instance DCT.Configured FeedHosts where + -- | This allows us to read a FeedHosts object out of a Configurator + -- config file. By default Configurator wouldn't know what to do, + -- so we have to tell it that we expect a list, and if that list + -- has strings in it, we can apply the FeedHosts constructor to + -- it. convert (DCT.List xs) = + -- mapM gives us a Maybe [String] here. fmap FeedHosts (mapM convert_string xs) where convert_string :: DCT.Value -> Maybe String convert_string = DCT.convert + -- If we read anything other than a list of values out of the file, + -- fail. convert _ = Nothing -