module Text.RSS.Syntax
( RSS (..)
, URLString
, DateString
, RSSChannel (..)
, RSSItem (..)
, RSSSource (..)
, RSSEnclosure (..)
, RSSCategory (..)
, RSSGuid (..)
, RSSImage (..)
, RSSCloud (..)
, RSSTextInput (..)
, nullRSS
, nullChannel
, nullItem
, nullSource
, nullEnclosure
, newCategory
, nullGuid
, nullPermaGuid
, nullImage
, nullCloud
, nullTextInput
) where
import Text.XML.Light as XML
data RSS
= RSS
{ rssVersion :: String
, rssAttrs :: [XML.Attr]
, rssChannel :: RSSChannel
, rssOther :: [XML.Element]
}
deriving (Show)
type URLString = String
type DateString = String
data RSSChannel
= RSSChannel
{ rssTitle :: String
, rssLink :: URLString
, rssDescription :: String
, rssItems :: [RSSItem]
, rssLanguage :: Maybe String
, rssCopyright :: Maybe String
, rssEditor :: Maybe String
, rssWebMaster :: Maybe String
, rssPubDate :: Maybe DateString
, rssLastUpdate :: Maybe DateString
, rssCategories :: [RSSCategory]
, rssGenerator :: Maybe String
, rssDocs :: Maybe URLString
, rssCloud :: Maybe RSSCloud
, rssTTL :: Maybe Integer
, rssImage :: Maybe RSSImage
, rssRating :: Maybe String
, rssTextInput :: Maybe RSSTextInput
, rssSkipHours :: Maybe [Integer]
, rssSkipDays :: Maybe [String]
, rssChannelOther :: [XML.Element]
}
deriving (Show)
data RSSItem
= RSSItem
{ rssItemTitle :: Maybe String
, rssItemLink :: Maybe URLString
, rssItemDescription :: Maybe String
, rssItemAuthor :: Maybe String
, rssItemCategories :: [RSSCategory]
, rssItemComments :: Maybe URLString
, rssItemEnclosure :: Maybe RSSEnclosure
, rssItemGuid :: Maybe RSSGuid
, rssItemPubDate :: Maybe DateString
, rssItemSource :: Maybe RSSSource
, rssItemAttrs :: [XML.Attr]
, rssItemOther :: [XML.Element]
}
deriving (Show)
data RSSSource
= RSSSource
{ rssSourceURL :: URLString
, rssSourceAttrs :: [XML.Attr]
, rssSourceTitle :: String
}
deriving (Show)
data RSSEnclosure
= RSSEnclosure
{ rssEnclosureURL :: URLString
, rssEnclosureLength :: Maybe Integer
, rssEnclosureType :: String
, rssEnclosureAttrs :: [XML.Attr]
}
deriving (Show)
data RSSCategory
= RSSCategory
{ rssCategoryDomain :: Maybe String
, rssCategoryAttrs :: [XML.Attr]
, rssCategoryValue :: String
}
deriving (Show)
data RSSGuid
= RSSGuid
{ rssGuidPermanentURL :: Maybe Bool
, rssGuidAttrs :: [XML.Attr]
, rssGuidValue :: String
}
deriving (Show)
data RSSImage
= RSSImage
{ rssImageURL :: URLString
, rssImageTitle :: String
, rssImageLink :: URLString
, rssImageWidth :: Maybe Integer
, rssImageHeight :: Maybe Integer
, rssImageDesc :: Maybe String
, rssImageOther :: [XML.Element]
}
deriving (Show)
data RSSCloud
= RSSCloud
{ rssCloudDomain :: Maybe String
, rssCloudPort :: Maybe String
, rssCloudPath :: Maybe String
, rssCloudRegisterProcedure :: Maybe String
, rssCloudProtocol :: Maybe String
, rssCloudAttrs :: [XML.Attr]
}
deriving (Show)
data RSSTextInput
= RSSTextInput
{ rssTextInputTitle :: String
, rssTextInputDesc :: String
, rssTextInputName :: String
, rssTextInputLink :: URLString
, rssTextInputAttrs :: [XML.Attr]
, rssTextInputOther :: [XML.Element]
}
deriving (Show)
nullRSS :: String
-> URLString
-> RSS
nullRSS title link =
RSS
{ rssVersion = "2.0"
, rssAttrs = []
, rssChannel = nullChannel title link
, rssOther = []
}
nullChannel :: String
-> URLString
-> RSSChannel
nullChannel title link =
RSSChannel
{ rssTitle = title
, rssLink = link
, rssDescription = title
, rssItems = []
, rssLanguage = Nothing
, rssCopyright = Nothing
, rssEditor = Nothing
, rssWebMaster = Nothing
, rssPubDate = Nothing
, rssLastUpdate = Nothing
, rssCategories = []
, rssGenerator = Nothing
, rssDocs = Nothing
, rssCloud = Nothing
, rssTTL = Nothing
, rssImage = Nothing
, rssRating = Nothing
, rssTextInput = Nothing
, rssSkipHours = Nothing
, rssSkipDays = Nothing
, rssChannelOther = []
}
nullItem :: String
-> RSSItem
nullItem title =
RSSItem
{ rssItemTitle = Just title
, rssItemLink = Nothing
, rssItemDescription = Nothing
, rssItemAuthor = Nothing
, rssItemCategories = []
, rssItemComments = Nothing
, rssItemEnclosure = Nothing
, rssItemGuid = Nothing
, rssItemPubDate = Nothing
, rssItemSource = Nothing
, rssItemAttrs = []
, rssItemOther = []
}
nullSource :: URLString
-> String
-> RSSSource
nullSource url title =
RSSSource
{ rssSourceURL = url
, rssSourceAttrs = []
, rssSourceTitle = title
}
nullEnclosure :: URLString
-> Maybe Integer
-> String
-> RSSEnclosure
nullEnclosure url mb_len ty =
RSSEnclosure
{ rssEnclosureURL = url
, rssEnclosureLength = mb_len
, rssEnclosureType = ty
, rssEnclosureAttrs = []
}
newCategory :: String
-> RSSCategory
newCategory nm =
RSSCategory
{ rssCategoryDomain = Nothing
, rssCategoryAttrs = []
, rssCategoryValue = nm
}
nullGuid :: String
-> RSSGuid
nullGuid v =
RSSGuid
{ rssGuidPermanentURL = Nothing
, rssGuidAttrs = []
, rssGuidValue = v
}
nullPermaGuid :: String
-> RSSGuid
nullPermaGuid v = (nullGuid v){rssGuidPermanentURL=Just True}
nullImage :: URLString
-> String
-> URLString
-> RSSImage
nullImage url title link =
RSSImage
{ rssImageURL = url
, rssImageTitle = title
, rssImageLink = link
, rssImageWidth = Nothing
, rssImageHeight = Nothing
, rssImageDesc = Nothing
, rssImageOther = []
}
nullCloud :: RSSCloud
nullCloud =
RSSCloud
{ rssCloudDomain = Nothing
, rssCloudPort = Nothing
, rssCloudPath = Nothing
, rssCloudRegisterProcedure = Nothing
, rssCloudProtocol = Nothing
, rssCloudAttrs = []
}
nullTextInput :: String
-> String
-> URLString
-> RSSTextInput
nullTextInput title nm link =
RSSTextInput
{ rssTextInputTitle = title
, rssTextInputDesc = title
, rssTextInputName = nm
, rssTextInputLink = link
, rssTextInputAttrs = []
, rssTextInputOther = []
}