]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/TSN/FeedHosts.hs
Add more code documentation.
[dead/htsn.git] / src / TSN / FeedHosts.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
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.
6 --
7 -- This was placed under the "TSN" namespace because its Default
8 -- instance is specific to TSN, even though otherwise it's just a
9 -- list of strings.
10 --
11 module TSN.FeedHosts
12 where
13
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 (
17 Configured,
18 Value( List ),
19 convert )
20 import Data.Data (Data)
21 import System.Console.CmdArgs.Default (Default(..))
22 import Data.Typeable (Typeable)
23
24
25 -- | A (wrapper around a) list of hostnames that supply the XML feed.
26 --
27 newtype FeedHosts =
28 FeedHosts { get_feed_hosts :: [String] }
29 deriving (Data, Show, Typeable)
30
31
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
36 -- this was written.
37 def = FeedHosts ["feed1.sportsnetwork.com",
38 "feed2.sportsnetwork.com",
39 "feed3.sportsnetwork.com"]
40
41
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
47 -- it.
48 convert (DCT.List xs) =
49 -- mapM gives us a Maybe [String] here.
50 fmap FeedHosts (mapM convert_string xs)
51 where
52 convert_string :: DCT.Value -> Maybe String
53 convert_string = DCT.convert
54
55 -- If we read anything other than a list of values out of the file,
56 -- fail.
57 convert _ = Nothing