DynamicSchema.hs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. {-# LANGUAGE Rank2Types #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3. module Codec.ActivityStream.DynamicSchema
  4. ( module Codec.ActivityStream.Dynamic
  5. -- * Verbs
  6. , SchemaVerb(..)
  7. -- * Object Types
  8. , SchemaObjectType(..)
  9. -- ** Audio/Video
  10. , avEmbedCode
  11. , avStream
  12. -- ** Binary
  13. , bnCompression
  14. , bnData
  15. , bnFileUrl
  16. , bnLength
  17. , bnMd5
  18. , bnMimeType
  19. -- ** Event
  20. , evAttended
  21. , evAttending
  22. , evEndTime
  23. , evInvited
  24. , evMaybeAttending
  25. , evNotAttendedBy
  26. , evNotAttending
  27. , evStartTime
  28. -- ** Issue
  29. , isTypes
  30. -- ** Permission
  31. , pmScope
  32. , pmActions
  33. -- ** Place
  34. , plPosition
  35. , plAddress
  36. -- *** PlacePosition
  37. , PlacePosition
  38. -- *** PlaceAddress
  39. , PlaceAddress
  40. -- ** Role/Group
  41. , rlMembers
  42. -- ** Task
  43. , tsActor
  44. , tsBy
  45. , tsObject
  46. , tsPrerequisites
  47. , tsRequired
  48. , tsSupersedes
  49. , tsVerb
  50. -- * Basic Extension Properties
  51. , acContext
  52. , getLocation
  53. , oMood
  54. , oRating
  55. , acResult
  56. , getSource
  57. , getStartTime
  58. , getEndTime
  59. , Mood
  60. , moodRest
  61. , moodDisplayName
  62. , moodImage
  63. ) where
  64. import qualified Data.Aeson as Aeson
  65. import Data.DateTime (DateTime)
  66. import Data.Aeson ( FromJSON(..), ToJSON(..) )
  67. import qualified Data.HashMap.Strict as HM
  68. import Data.Text (Text)
  69. import Codec.ActivityStream.LensInternal
  70. import Codec.ActivityStream.Dynamic
  71. import Codec.ActivityStream.Schema (SchemaVerb(..), SchemaObjectType(..))
  72. -- audio/video
  73. -- | A fragment of HTML markup that, when embedded within another HTML
  74. -- page, provides an interactive user-interface for viewing or listening
  75. -- to the video or audio stream.
  76. avEmbedCode :: Lens' Object (Maybe Text)
  77. avEmbedCode = makeAesonLensMb "embedCode" oRest
  78. -- | An Activity Streams Media Link to the video or audio content itself.
  79. avStream :: Lens' Object (Maybe MediaLink)
  80. avStream = makeAesonLensMb "stream" oRest
  81. -- binary
  82. -- | An optional token identifying a compression algorithm applied to
  83. -- the binary data prior to Base64-encoding. Possible algorithms
  84. -- are "deflate" and "gzip", respectively indicating the use of
  85. -- the compression mechanisms defined by RFC 1951 and RFC 1952.
  86. -- Additional compression algorithms MAY be used but are not defined
  87. -- by this specification. Note that previous versions of this
  88. -- specification allowed for multiple compression algorithms to be
  89. -- applied and listed using a comma-separated format. The use of
  90. -- multiple compressions is no longer permitted.
  91. bnCompression :: Lens' Object (Maybe Text)
  92. bnCompression = makeAesonLensMb "compression" oRest
  93. bnData :: Lens' Object (Maybe Text)
  94. bnData = makeAesonLensMb "data" oRest
  95. bnFileUrl :: Lens' Object (Maybe Text)
  96. bnFileUrl = makeAesonLensMb "fileUrl" oRest
  97. bnLength :: Lens' Object (Maybe Text)
  98. bnLength = makeAesonLensMb "length" oRest
  99. bnMd5 :: Lens' Object (Maybe Text)
  100. bnMd5 = makeAesonLensMb "md5" oRest
  101. bnMimeType :: Lens' Object (Maybe Text)
  102. bnMimeType = makeAesonLensMb "mimeType" oRest
  103. -- event
  104. evAttended :: Lens' Object (Maybe Collection)
  105. evAttended = makeAesonLensMb "attended" oRest
  106. evAttending :: Lens' Object (Maybe Collection)
  107. evAttending = makeAesonLensMb "attending" oRest
  108. evEndTime :: Lens' Object (Maybe DateTime)
  109. evEndTime = makeAesonLensMb "endTime" oRest
  110. evInvited :: Lens' Object (Maybe Collection)
  111. evInvited = makeAesonLensMb "invited" oRest
  112. evMaybeAttending :: Lens' Object (Maybe Collection)
  113. evMaybeAttending = makeAesonLensMb "maybeAttending" oRest
  114. evNotAttendedBy :: Lens' Object (Maybe Collection)
  115. evNotAttendedBy = makeAesonLensMb "notAttendedBy" oRest
  116. evNotAttending :: Lens' Object (Maybe Collection)
  117. evNotAttending = makeAesonLensMb "notAttending" oRest
  118. evStartTime :: Lens' Object (Maybe DateTime)
  119. evStartTime = makeAesonLensMb "startTime" oRest
  120. -- issue
  121. isTypes :: Lens' Object (Maybe [Text])
  122. isTypes = makeAesonLensMb "types" oRest
  123. -- permission
  124. pmScope :: Lens' Object (Maybe Object)
  125. pmScope = makeAesonLensMb "scope" oRest
  126. pmActions :: Lens' Object (Maybe [Text])
  127. pmActions = makeAesonLensMb "actions" oRest
  128. -- place
  129. plPosition :: Lens' Object (Maybe PlacePosition)
  130. plPosition = makeAesonLensMb "position" oRest
  131. plAddress :: Lens' Object (Maybe PlaceAddress)
  132. plAddress = makeAesonLensMb "address" oRest
  133. data PlacePosition = PPO { fromPPO :: Aeson.Object } deriving (Eq, Show)
  134. instance FromJSON PlacePosition where
  135. parseJSON (Aeson.Object o)
  136. | HM.member "altitude" o
  137. && HM.member "latitude" o
  138. && HM.member "longitude" o = return (PPO o)
  139. | otherwise = fail "..."
  140. parseJSON _ = fail "..."
  141. instance ToJSON PlacePosition where
  142. toJSON = Aeson.Object . fromPPO
  143. data PlaceAddress = PAO { fromPAO :: Aeson.Object } deriving (Eq, Show)
  144. instance FromJSON PlaceAddress where
  145. parseJSON (Aeson.Object o)
  146. | HM.member "formatted" o
  147. && HM.member "streetAddress" o
  148. && HM.member "locality" o
  149. && HM.member "region" o
  150. && HM.member "postalCode" o
  151. && HM.member "country" o = return (PAO o)
  152. | otherwise = fail "..."
  153. parseJSON _ = fail "..."
  154. instance ToJSON PlaceAddress where
  155. toJSON = Aeson.Object . fromPAO
  156. -- role/group
  157. rlMembers :: Lens' Object (Maybe [Object])
  158. rlMembers = makeAesonLensMb "members" oRest
  159. -- Task
  160. tsActor :: Lens' Object (Maybe Object)
  161. tsActor = makeAesonLensMb "actor" oRest
  162. tsBy :: Lens' Object (Maybe DateTime)
  163. tsBy = makeAesonLensMb "by" oRest
  164. tsObject :: Lens' Object (Maybe Object)
  165. tsObject = makeAesonLensMb "object" oRest
  166. tsPrerequisites :: Lens' Object (Maybe [Object])
  167. tsPrerequisites = makeAesonLensMb "prerequisites" oRest
  168. tsRequired :: Lens' Object (Maybe Bool)
  169. tsRequired = makeAesonLensMb "required" oRest
  170. tsSupersedes :: Lens' Object (Maybe [Object])
  171. tsSupersedes = makeAesonLensMb "supersedes" oRest
  172. tsVerb :: Lens' Object (Maybe SchemaVerb)
  173. tsVerb = makeAesonLensMb "verb" oRest
  174. -- extra properties
  175. acContext :: Lens' Activity (Maybe Object)
  176. acContext = makeAesonLensMb "context" acRest
  177. getLocation :: Lens' a Aeson.Object -> Lens' a (Maybe Object)
  178. getLocation = makeAesonLensMb "location"
  179. oMood :: Lens' Object (Maybe Mood)
  180. oMood = makeAesonLensMb "mood" oRest
  181. oRating :: Lens' Object (Maybe Double)
  182. oRating = makeAesonLensMb "rating" oRest
  183. acResult :: Lens' Activity (Maybe Object)
  184. acResult = makeAesonLensMb "result" acRest
  185. getSource :: Lens' a Aeson.Object -> Lens' a (Maybe Object)
  186. getSource = makeAesonLensMb "source"
  187. getStartTime :: Lens' a Aeson.Object -> Lens' a (Maybe Text)
  188. getStartTime = makeAesonLensMb "startTime"
  189. getEndTime :: Lens' a Aeson.Object -> Lens' a (Maybe Text)
  190. getEndTime = makeAesonLensMb "endTime"
  191. -- mood
  192. data Mood = Mood { fromMood :: Aeson.Object } deriving (Eq, Show)
  193. instance FromJSON Mood where
  194. parseJSON (Aeson.Object o)
  195. | HM.member "displayName" o
  196. && HM.member "image" o = return (Mood o)
  197. | otherwise = fail "..."
  198. parseJSON _ = fail "..."
  199. instance ToJSON Mood where
  200. toJSON = Aeson.Object . fromMood
  201. moodRest :: Lens' Mood Aeson.Object
  202. moodRest = makeLens fromMood (\ o' m -> m { fromMood = o' })
  203. moodDisplayName :: Lens' Mood Text
  204. moodDisplayName = makeAesonLens "displayName" moodRest
  205. moodImage :: Lens' Mood MediaLink
  206. moodImage = makeAesonLens "image" moodRest