summaryrefslogtreecommitdiff
path: root/src/Servall/Types.hs
blob: 2c49532f17d62ad13a40d304414cfa518c7b854c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Servall.Types where

import           Data.Aeson                     ( (.:)
                                                , (.=)
                                                , FromJSON(..)
                                                , ToJSON(..)
                                                , Value(..)
                                                , object
                                                )
import           Data.Text                      ( Text )
import           GHC.Generics                   ( Generic )

data WikiTemplate = WikiTemplate
  { wtName :: Text
  -- , wtSubName :: Maybe Text
  , wtArgs :: [(Maybe Text, Text)]
  }
  deriving Show

data Video = Video
  { vid       :: Text
  , vtitle    :: Text
  , vdesc     :: Text
  , vduration :: Int
  }
  deriving (Eq, Show)

instance FromJSON Video where
  parseJSON (Object o) =
    Video
      <$> o
      .:  "id"
      <*> o
      .:  "title"
      <*> o
      .:  "description"
      <*> o
      .:  "duration"

instance ToJSON Video where
  toJSON (Video vid title desc duration) = object
    [ "id" .= vid
    , "title" .= title
    , "description" .= desc
    , "duration" .= duration
    ]


data WikiSummary = WikiSummary
  { wsTitle   :: Text
  , wsWikbase :: Text
  , wsPageId  :: Int
  }
  deriving (Show, Eq, Generic)

instance FromJSON WikiSummary where
  parseJSON (Object o) =
    WikiSummary <$> o .: "title" <*> o .: "wikibase_item" <*> o .: "pageid"

instance ToJSON WikiSummary where
  toJSON (WikiSummary title wikibase pageid) =
    object ["title" .= title, "wikibase" .= wikibase, "pageid" .= pageid]