module Sound.Freesound.Pack.Type where
import Control.Monad (mzero)
import Data.Aeson (FromJSON(..), Value(..), (.:))
import Data.Text (Text)
import Sound.Freesound.API (Resource, URI)
import Sound.Freesound.List (List, Elem(..))
import qualified Sound.Freesound.Sound as Sound
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
class Pack a where
ref :: a -> Resource ()
url :: a -> URI
sounds :: a -> Resource (List Sound.Summary)
name :: a -> Text
created :: a -> Text
numDownloads :: a -> Integer
data Summary = Summary {
pack_ref :: Resource ()
, pack_url :: URI
, pack_sounds :: Resource (List Sound.Summary)
, pack_name :: Text
, pack_created :: Text
, pack_num_downloads :: Integer
} deriving (Eq, Show)
instance Pack Summary where
ref = pack_ref
url = pack_url
sounds = pack_sounds
name = pack_name
created = pack_created
numDownloads = pack_num_downloads
instance FromJSON Summary where
parseJSON (Object o) =
Summary
<$> o .: "ref"
<*> o .: "url"
<*> o .: "sounds"
<*> o .: "name"
<*> o .: "created"
<*> o .: "num_downloads"
parseJSON _ = mzero
instance Elem Summary where
elemsFieldName _ = "packs"
data Detail = Detail {
summary :: Summary
, username :: Text
} deriving (Eq, Show)
instance Pack Detail where
ref = ref . summary
url = url . summary
sounds = sounds . summary
name = name . summary
created = created . summary
numDownloads = numDownloads . summary
instance FromJSON Detail where
parseJSON v@(Object o) =
Detail
<$> parseJSON v
<*> o .: "username"
parseJSON _ = mzero