mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-05 05:45:46 +03:00
kh: prefer withObject helper over custom parser
This commit is contained in:
parent
aec9883c3b
commit
5fcf570c99
@ -162,10 +162,9 @@ data PointResponse = PointResponse
|
|||||||
} deriving (Show, Eq, Generic)
|
} deriving (Show, Eq, Generic)
|
||||||
|
|
||||||
instance FromJSON PointResponse where
|
instance FromJSON PointResponse where
|
||||||
parseJSON (Object o) = do
|
parseJSON = withObject "PointResponse" $ \o -> do
|
||||||
prNetwork <- o .: "network"
|
prNetwork <- o .: "network"
|
||||||
pure PointResponse{..}
|
pure PointResponse{..}
|
||||||
parseJSON _ = do error "failed to parse PointResponse json"
|
|
||||||
|
|
||||||
data PointNetwork = PointNetwork
|
data PointNetwork = PointNetwork
|
||||||
{ pnKeys :: PointKeys
|
{ pnKeys :: PointKeys
|
||||||
@ -174,12 +173,11 @@ data PointNetwork = PointNetwork
|
|||||||
} deriving (Show, Eq, Generic)
|
} deriving (Show, Eq, Generic)
|
||||||
|
|
||||||
instance FromJSON PointNetwork where
|
instance FromJSON PointNetwork where
|
||||||
parseJSON (Object o) = do
|
parseJSON = withObject "PointNetwork" $ \o -> do
|
||||||
pnKeys <- o .: "keys"
|
pnKeys <- o .: "keys"
|
||||||
pnSponsor <- o .: "sponsor"
|
pnSponsor <- o .: "sponsor"
|
||||||
pnRift <- o .: "rift"
|
pnRift <- o .: "rift"
|
||||||
pure PointNetwork{..}
|
pure PointNetwork{..}
|
||||||
parseJSON _ = do error "failed to parse PointNetwork json"
|
|
||||||
|
|
||||||
data PointKeys = PointKeys
|
data PointKeys = PointKeys
|
||||||
{ pkLife :: Life
|
{ pkLife :: Life
|
||||||
@ -189,7 +187,7 @@ data PointKeys = PointKeys
|
|||||||
} deriving (Show, Eq, Generic)
|
} deriving (Show, Eq, Generic)
|
||||||
|
|
||||||
instance FromJSON PointKeys where
|
instance FromJSON PointKeys where
|
||||||
parseJSON (Object o) = do
|
parseJSON = withObject "PointKeys" $ \o -> do
|
||||||
pkLife <- o .: "life"
|
pkLife <- o .: "life"
|
||||||
pkSuite <- o .: "suite"
|
pkSuite <- o .: "suite"
|
||||||
rawAuth <- o .: "auth"
|
rawAuth <- o .: "auth"
|
||||||
@ -199,7 +197,6 @@ instance FromJSON PointKeys where
|
|||||||
pure PointKeys{..}
|
pure PointKeys{..}
|
||||||
where
|
where
|
||||||
parseKey = reverse . toBytes . hexString . removePrefix . encodeUtf8
|
parseKey = reverse . toBytes . hexString . removePrefix . encodeUtf8
|
||||||
parseJSON _ = do error "failed to parse PointKeys json"
|
|
||||||
|
|
||||||
data PointSponsor = PointSponsor
|
data PointSponsor = PointSponsor
|
||||||
{ psHas :: Bool
|
{ psHas :: Bool
|
||||||
@ -207,11 +204,10 @@ data PointSponsor = PointSponsor
|
|||||||
} deriving (Show, Eq, Generic)
|
} deriving (Show, Eq, Generic)
|
||||||
|
|
||||||
instance FromJSON PointSponsor where
|
instance FromJSON PointSponsor where
|
||||||
parseJSON (Object o) = do
|
parseJSON = withObject "PointSponsor" $ \o -> do
|
||||||
psHas <- o .: "has"
|
psHas <- o .: "has"
|
||||||
psWho <- o .: "who"
|
psWho <- o .: "who"
|
||||||
pure PointSponsor{..}
|
pure PointSponsor{..}
|
||||||
parseJSON _ = do error "failed to parse PointSponsor json"
|
|
||||||
|
|
||||||
data PointRequest = PointRequest Ship
|
data PointRequest = PointRequest Ship
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user