module HipChat.Types.Icon where
import Data.Aeson
import Data.Aeson.Types
import Data.Text (Text)
newtype CompoundIcon = CompoundIcon
{ unCompoundIcon :: Either Text Icon
} deriving Show
instance ToJSON CompoundIcon where
toJSON (CompoundIcon (Left x)) = toJSON x
toJSON (CompoundIcon (Right x)) = toJSON x
data Icon = Icon
{ iconUrl :: Text
, iconUrl2x :: Text
} deriving (Show, Eq)
instance ToJSON Icon where
toJSON (Icon url url2x) = object
[ "url" .= url
, "url@2x" .= url2x
]
instance FromJSON Icon where
parseJSON (Object x) = Icon <$> x .: "url" <*> x .: "url@2x"
parseJSON x = typeMismatch "Icon" x