module Rollbar.Item.Body
( Body(..)
, MessageBody(..)
) where
import Data.Aeson
(KeyValue, ToJSON, object, pairs, toEncoding, toJSON, (.=))
import Data.Aeson.Encoding (pair)
import Data.String (IsString)
import GHC.Generics (Generic)
import qualified Data.Text as T
data Body arbitrary
= Message
{ messageBody :: MessageBody
, messageData :: arbitrary
}
deriving (Eq, Generic, Show)
bodyKVs :: (KeyValue kv, ToJSON v) => Body v -> [kv]
bodyKVs Message{..} =
[ "body" .= messageBody
, "data" .= messageData
]
instance ToJSON arbitrary => ToJSON (Body arbitrary) where
toJSON x = object ["message" .= object (bodyKVs x)]
toEncoding = pairs . pair "message" . pairs . mconcat . bodyKVs
newtype MessageBody
= MessageBody T.Text
deriving (Eq, IsString, Show, ToJSON)