{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
module Speechmatics.JSON.PostJob where
import System.Exit (exitFailure, exitSuccess)
import System.IO (stderr, hPutStrLn)
import qualified Data.ByteString.Lazy.Char8 as BSL
import System.Environment (getArgs)
import Control.Monad (forM_, mzero, join)
import Control.Applicative
import Data.Aeson.AutoType.Alternative
import Data.Aeson(decode, Value(..), FromJSON(..), ToJSON(..),
pairs, eitherDecode,
(.:), (.:?), object)
import Data.Monoid
import Data.Text (Text)
import qualified GHC.Generics
o .:?? val = fmap join (o .:? val)
data PostJob = PostJob {
checkWait :: (Maybe Value),
cost :: Double,
balance :: Double,
postId :: Integer
} deriving (Show,Eq,GHC.Generics.Generic)
instance FromJSON PostJob where
parseJSON (Object v) = PostJob <$> v .:?? "check_wait" <*> v .: "cost" <*> v .: "balance" <*> v .: "id"
parseJSON _ = mzero
parse :: BSL.ByteString -> Either String PostJob
parse = eitherDecode