module Network.Pusher.Internal.Util
( failExpectObj
, failExpectArray
, failExpectStr
, failExpectSingletonArray
, getTime
, show'
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A
import Data.String (IsString, fromString)
import Data.Time.Clock.POSIX (getPOSIXTime)
getTime :: IO Int
getTime = round <$> getPOSIXTime
failExpectObj :: A.Value -> A.Parser a
failExpectObj = fail . ("Expected JSON object, got " ++) . show
failExpectArray :: A.Value -> A.Parser a
failExpectArray = fail . ("Expected JSON array, got " ++) . show
failExpectSingletonArray :: A.Value -> A.Parser a
failExpectSingletonArray =
fail . ("Expected JSON array with exactly one object, got" ++) . show
failExpectStr :: A.Value -> A.Parser a
failExpectStr = fail . ("Expected JSON string, got " ++) . show
show' :: (Show a, IsString b) => a -> b
show' = fromString . show