{-# LANGUAGE OverloadedStrings #-}
module Network.Cloudflare.Types where

import           Data.Aeson
import           Data.Text

-- | Cloudflare API token
-- see https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on creating a token
data CloudflareAuth = CloudflareAuth {
  CloudflareAuth -> Text
cloudflareAuthToken :: Text
}

-- | Cloudflare account information
data Account = Account {
  Account -> Text
accountId :: Text -- ^ Cloudflare account ID
, Account -> Text
accountName :: Text -- ^ Cloudflare account name
} deriving (Account -> Account -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Account -> Account -> Bool
$c/= :: Account -> Account -> Bool
== :: Account -> Account -> Bool
$c== :: Account -> Account -> Bool
Eq, Eq Account
Account -> Account -> Bool
Account -> Account -> Ordering
Account -> Account -> Account
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Account -> Account -> Account
$cmin :: Account -> Account -> Account
max :: Account -> Account -> Account
$cmax :: Account -> Account -> Account
>= :: Account -> Account -> Bool
$c>= :: Account -> Account -> Bool
> :: Account -> Account -> Bool
$c> :: Account -> Account -> Bool
<= :: Account -> Account -> Bool
$c<= :: Account -> Account -> Bool
< :: Account -> Account -> Bool
$c< :: Account -> Account -> Bool
compare :: Account -> Account -> Ordering
$ccompare :: Account -> Account -> Ordering
Ord, Int -> Account -> ShowS
[Account] -> ShowS
Account -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Account] -> ShowS
$cshowList :: [Account] -> ShowS
show :: Account -> String
$cshow :: Account -> String
showsPrec :: Int -> Account -> ShowS
$cshowsPrec :: Int -> Account -> ShowS
Show)

instance FromJSON Account where
  parseJSON :: Value -> Parser Account
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Account" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Text
id' <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
    Text
name <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Text -> Account
Account Text
id' Text
name

-- | Result type for Cloudflare API calls that don't return any extra data
-- and wrap the result in a "result" field
newtype ResultOnly a = ResultOnly {
  forall a. ResultOnly a -> a
resultOnlyResult :: a
} deriving (ResultOnly a -> ResultOnly a -> Bool
forall a. Eq a => ResultOnly a -> ResultOnly a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultOnly a -> ResultOnly a -> Bool
$c/= :: forall a. Eq a => ResultOnly a -> ResultOnly a -> Bool
== :: ResultOnly a -> ResultOnly a -> Bool
$c== :: forall a. Eq a => ResultOnly a -> ResultOnly a -> Bool
Eq, ResultOnly a -> ResultOnly a -> Bool
ResultOnly a -> ResultOnly a -> Ordering
ResultOnly a -> ResultOnly a -> ResultOnly a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (ResultOnly a)
forall a. Ord a => ResultOnly a -> ResultOnly a -> Bool
forall a. Ord a => ResultOnly a -> ResultOnly a -> Ordering
forall a. Ord a => ResultOnly a -> ResultOnly a -> ResultOnly a
min :: ResultOnly a -> ResultOnly a -> ResultOnly a
$cmin :: forall a. Ord a => ResultOnly a -> ResultOnly a -> ResultOnly a
max :: ResultOnly a -> ResultOnly a -> ResultOnly a
$cmax :: forall a. Ord a => ResultOnly a -> ResultOnly a -> ResultOnly a
>= :: ResultOnly a -> ResultOnly a -> Bool
$c>= :: forall a. Ord a => ResultOnly a -> ResultOnly a -> Bool
> :: ResultOnly a -> ResultOnly a -> Bool
$c> :: forall a. Ord a => ResultOnly a -> ResultOnly a -> Bool
<= :: ResultOnly a -> ResultOnly a -> Bool
$c<= :: forall a. Ord a => ResultOnly a -> ResultOnly a -> Bool
< :: ResultOnly a -> ResultOnly a -> Bool
$c< :: forall a. Ord a => ResultOnly a -> ResultOnly a -> Bool
compare :: ResultOnly a -> ResultOnly a -> Ordering
$ccompare :: forall a. Ord a => ResultOnly a -> ResultOnly a -> Ordering
Ord, Int -> ResultOnly a -> ShowS
forall a. Show a => Int -> ResultOnly a -> ShowS
forall a. Show a => [ResultOnly a] -> ShowS
forall a. Show a => ResultOnly a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultOnly a] -> ShowS
$cshowList :: forall a. Show a => [ResultOnly a] -> ShowS
show :: ResultOnly a -> String
$cshow :: forall a. Show a => ResultOnly a -> String
showsPrec :: Int -> ResultOnly a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ResultOnly a -> ShowS
Show)

instance FromJSON a => FromJSON (ResultOnly a) where
  parseJSON :: Value -> Parser (ResultOnly a)
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResultOnly" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    a
result <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"result"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. a -> ResultOnly a
ResultOnly a
result

-- | Result type for Cloudflare API call errors
data ResponseError = ResponseError {
  ResponseError -> Int
responseErrorCode :: Int
, ResponseError -> Text
responseErrorMessage :: Text
} deriving (ResponseError -> ResponseError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResponseError -> ResponseError -> Bool
$c/= :: ResponseError -> ResponseError -> Bool
== :: ResponseError -> ResponseError -> Bool
$c== :: ResponseError -> ResponseError -> Bool
Eq, Eq ResponseError
ResponseError -> ResponseError -> Bool
ResponseError -> ResponseError -> Ordering
ResponseError -> ResponseError -> ResponseError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResponseError -> ResponseError -> ResponseError
$cmin :: ResponseError -> ResponseError -> ResponseError
max :: ResponseError -> ResponseError -> ResponseError
$cmax :: ResponseError -> ResponseError -> ResponseError
>= :: ResponseError -> ResponseError -> Bool
$c>= :: ResponseError -> ResponseError -> Bool
> :: ResponseError -> ResponseError -> Bool
$c> :: ResponseError -> ResponseError -> Bool
<= :: ResponseError -> ResponseError -> Bool
$c<= :: ResponseError -> ResponseError -> Bool
< :: ResponseError -> ResponseError -> Bool
$c< :: ResponseError -> ResponseError -> Bool
compare :: ResponseError -> ResponseError -> Ordering
$ccompare :: ResponseError -> ResponseError -> Ordering
Ord, Int -> ResponseError -> ShowS
[ResponseError] -> ShowS
ResponseError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResponseError] -> ShowS
$cshowList :: [ResponseError] -> ShowS
show :: ResponseError -> String
$cshow :: ResponseError -> String
showsPrec :: Int -> ResponseError -> ShowS
$cshowsPrec :: Int -> ResponseError -> ShowS
Show)

instance FromJSON ResponseError where
  parseJSON :: Value -> Parser ResponseError
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResponseError" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Int
code <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"code"
    Text
message <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Text -> ResponseError
ResponseError Int
code Text
message

-- | Additional messages from Cloudflare API calls
data ResponseMessage = ResponseMessage {
  ResponseMessage -> Int
responseMessageCode :: Int
, ResponseMessage -> Text
responseMessageMessage :: Text
} deriving (ResponseMessage -> ResponseMessage -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResponseMessage -> ResponseMessage -> Bool
$c/= :: ResponseMessage -> ResponseMessage -> Bool
== :: ResponseMessage -> ResponseMessage -> Bool
$c== :: ResponseMessage -> ResponseMessage -> Bool
Eq, Eq ResponseMessage
ResponseMessage -> ResponseMessage -> Bool
ResponseMessage -> ResponseMessage -> Ordering
ResponseMessage -> ResponseMessage -> ResponseMessage
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResponseMessage -> ResponseMessage -> ResponseMessage
$cmin :: ResponseMessage -> ResponseMessage -> ResponseMessage
max :: ResponseMessage -> ResponseMessage -> ResponseMessage
$cmax :: ResponseMessage -> ResponseMessage -> ResponseMessage
>= :: ResponseMessage -> ResponseMessage -> Bool
$c>= :: ResponseMessage -> ResponseMessage -> Bool
> :: ResponseMessage -> ResponseMessage -> Bool
$c> :: ResponseMessage -> ResponseMessage -> Bool
<= :: ResponseMessage -> ResponseMessage -> Bool
$c<= :: ResponseMessage -> ResponseMessage -> Bool
< :: ResponseMessage -> ResponseMessage -> Bool
$c< :: ResponseMessage -> ResponseMessage -> Bool
compare :: ResponseMessage -> ResponseMessage -> Ordering
$ccompare :: ResponseMessage -> ResponseMessage -> Ordering
Ord, Int -> ResponseMessage -> ShowS
[ResponseMessage] -> ShowS
ResponseMessage -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResponseMessage] -> ShowS
$cshowList :: [ResponseMessage] -> ShowS
show :: ResponseMessage -> String
$cshow :: ResponseMessage -> String
showsPrec :: Int -> ResponseMessage -> ShowS
$cshowsPrec :: Int -> ResponseMessage -> ShowS
Show)

instance FromJSON ResponseMessage where
  parseJSON :: Value -> Parser ResponseMessage
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResponseMessage" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Int
code <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"code"
    Text
message <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Text -> ResponseMessage
ResponseMessage Int
code Text
message

-- | Result information for Cloudflare API calls that return a list of results
data ResultInfo = ResultInfo {
  ResultInfo -> Int
resultInfoCount :: Int
, ResultInfo -> Int
resultInfoPage :: Int
, ResultInfo -> Int
resultInfoPerPage :: Int
, ResultInfo -> Int
resultInfoTotalCount :: Int
} deriving (ResultInfo -> ResultInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultInfo -> ResultInfo -> Bool
$c/= :: ResultInfo -> ResultInfo -> Bool
== :: ResultInfo -> ResultInfo -> Bool
$c== :: ResultInfo -> ResultInfo -> Bool
Eq, Eq ResultInfo
ResultInfo -> ResultInfo -> Bool
ResultInfo -> ResultInfo -> Ordering
ResultInfo -> ResultInfo -> ResultInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResultInfo -> ResultInfo -> ResultInfo
$cmin :: ResultInfo -> ResultInfo -> ResultInfo
max :: ResultInfo -> ResultInfo -> ResultInfo
$cmax :: ResultInfo -> ResultInfo -> ResultInfo
>= :: ResultInfo -> ResultInfo -> Bool
$c>= :: ResultInfo -> ResultInfo -> Bool
> :: ResultInfo -> ResultInfo -> Bool
$c> :: ResultInfo -> ResultInfo -> Bool
<= :: ResultInfo -> ResultInfo -> Bool
$c<= :: ResultInfo -> ResultInfo -> Bool
< :: ResultInfo -> ResultInfo -> Bool
$c< :: ResultInfo -> ResultInfo -> Bool
compare :: ResultInfo -> ResultInfo -> Ordering
$ccompare :: ResultInfo -> ResultInfo -> Ordering
Ord, Int -> ResultInfo -> ShowS
[ResultInfo] -> ShowS
ResultInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultInfo] -> ShowS
$cshowList :: [ResultInfo] -> ShowS
show :: ResultInfo -> String
$cshow :: ResultInfo -> String
showsPrec :: Int -> ResultInfo -> ShowS
$cshowsPrec :: Int -> ResultInfo -> ShowS
Show)

instance FromJSON ResultInfo where
  parseJSON :: Value -> Parser ResultInfo
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResultInfo" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Int
c <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"count"
    Int
page <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"page"
    Int
perPage <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"per_page"
    Int
totalCount <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"total_count"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> Int -> ResultInfo
ResultInfo Int
c Int
page Int
perPage Int
totalCount

-- TODO this could use a better name that doesn't conflict with the Result type from aeson

-- | Result type for Cloudflare API calls that returns a result with a list of errors, a list of messages, and a success flag
data ResultResponse a = ResultResponse {
  forall a. ResultResponse a -> [ResponseError]
resultErrors :: [ResponseError]
, forall a. ResultResponse a -> [ResponseMessage]
resultMessages :: [ResponseMessage]
, forall a. ResultResponse a -> Bool
resultSuccess :: Bool
, forall a. ResultResponse a -> a
resultResult :: a
} deriving (ResultResponse a -> ResultResponse a -> Bool
forall a. Eq a => ResultResponse a -> ResultResponse a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultResponse a -> ResultResponse a -> Bool
$c/= :: forall a. Eq a => ResultResponse a -> ResultResponse a -> Bool
== :: ResultResponse a -> ResultResponse a -> Bool
$c== :: forall a. Eq a => ResultResponse a -> ResultResponse a -> Bool
Eq, ResultResponse a -> ResultResponse a -> Bool
ResultResponse a -> ResultResponse a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (ResultResponse a)
forall a. Ord a => ResultResponse a -> ResultResponse a -> Bool
forall a. Ord a => ResultResponse a -> ResultResponse a -> Ordering
forall a.
Ord a =>
ResultResponse a -> ResultResponse a -> ResultResponse a
min :: ResultResponse a -> ResultResponse a -> ResultResponse a
$cmin :: forall a.
Ord a =>
ResultResponse a -> ResultResponse a -> ResultResponse a
max :: ResultResponse a -> ResultResponse a -> ResultResponse a
$cmax :: forall a.
Ord a =>
ResultResponse a -> ResultResponse a -> ResultResponse a
>= :: ResultResponse a -> ResultResponse a -> Bool
$c>= :: forall a. Ord a => ResultResponse a -> ResultResponse a -> Bool
> :: ResultResponse a -> ResultResponse a -> Bool
$c> :: forall a. Ord a => ResultResponse a -> ResultResponse a -> Bool
<= :: ResultResponse a -> ResultResponse a -> Bool
$c<= :: forall a. Ord a => ResultResponse a -> ResultResponse a -> Bool
< :: ResultResponse a -> ResultResponse a -> Bool
$c< :: forall a. Ord a => ResultResponse a -> ResultResponse a -> Bool
compare :: ResultResponse a -> ResultResponse a -> Ordering
$ccompare :: forall a. Ord a => ResultResponse a -> ResultResponse a -> Ordering
Ord, Int -> ResultResponse a -> ShowS
forall a. Show a => Int -> ResultResponse a -> ShowS
forall a. Show a => [ResultResponse a] -> ShowS
forall a. Show a => ResultResponse a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultResponse a] -> ShowS
$cshowList :: forall a. Show a => [ResultResponse a] -> ShowS
show :: ResultResponse a -> String
$cshow :: forall a. Show a => ResultResponse a -> String
showsPrec :: Int -> ResultResponse a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ResultResponse a -> ShowS
Show)

instance FromJSON a => FromJSON (ResultResponse a) where
  parseJSON :: Value -> Parser (ResultResponse a)
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Result" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    [ResponseError]
errors <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"errors"
    [ResponseMessage]
messages <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"messages"
    Bool
success <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"success"
    a
result <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"result"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a.
[ResponseError]
-> [ResponseMessage] -> Bool -> a -> ResultResponse a
ResultResponse [ResponseError]
errors [ResponseMessage]
messages Bool
success a
result

-- | Result type for Cloudflare API calls that returns a result with meta information about the result,
-- a list of errors, a list of messages, and a success flag
data ResultWithInfo a = ResultWithInfo {
  forall a. ResultWithInfo a -> ResultInfo
resultWithInfoInfo :: ResultInfo
, forall a. ResultWithInfo a -> [ResponseError]
resultWithInfoErrors :: [ResponseError]
, forall a. ResultWithInfo a -> [ResponseMessage]
resultWithInfoMessages :: [ResponseMessage]
, forall a. ResultWithInfo a -> Bool
resultWithInfoSuccess :: Bool
, forall a. ResultWithInfo a -> a
resultWithInfoResult :: a
} deriving (ResultWithInfo a -> ResultWithInfo a -> Bool
forall a. Eq a => ResultWithInfo a -> ResultWithInfo a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c/= :: forall a. Eq a => ResultWithInfo a -> ResultWithInfo a -> Bool
== :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c== :: forall a. Eq a => ResultWithInfo a -> ResultWithInfo a -> Bool
Eq, ResultWithInfo a -> ResultWithInfo a -> Bool
ResultWithInfo a -> ResultWithInfo a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (ResultWithInfo a)
forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Bool
forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Ordering
forall a.
Ord a =>
ResultWithInfo a -> ResultWithInfo a -> ResultWithInfo a
min :: ResultWithInfo a -> ResultWithInfo a -> ResultWithInfo a
$cmin :: forall a.
Ord a =>
ResultWithInfo a -> ResultWithInfo a -> ResultWithInfo a
max :: ResultWithInfo a -> ResultWithInfo a -> ResultWithInfo a
$cmax :: forall a.
Ord a =>
ResultWithInfo a -> ResultWithInfo a -> ResultWithInfo a
>= :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c>= :: forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Bool
> :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c> :: forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Bool
<= :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c<= :: forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Bool
< :: ResultWithInfo a -> ResultWithInfo a -> Bool
$c< :: forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Bool
compare :: ResultWithInfo a -> ResultWithInfo a -> Ordering
$ccompare :: forall a. Ord a => ResultWithInfo a -> ResultWithInfo a -> Ordering
Ord, Int -> ResultWithInfo a -> ShowS
forall a. Show a => Int -> ResultWithInfo a -> ShowS
forall a. Show a => [ResultWithInfo a] -> ShowS
forall a. Show a => ResultWithInfo a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultWithInfo a] -> ShowS
$cshowList :: forall a. Show a => [ResultWithInfo a] -> ShowS
show :: ResultWithInfo a -> String
$cshow :: forall a. Show a => ResultWithInfo a -> String
showsPrec :: Int -> ResultWithInfo a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ResultWithInfo a -> ShowS
Show)

instance FromJSON a => FromJSON (ResultWithInfo a) where
  parseJSON :: Value -> Parser (ResultWithInfo a)
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResultWithInfo" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    [ResponseError]
errors <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"errors"
    [ResponseMessage]
messages <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"messages"
    Bool
success <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"success"
    ResultInfo
resultInfo <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"result_info"
    a
result <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"result"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a.
ResultInfo
-> [ResponseError]
-> [ResponseMessage]
-> Bool
-> a
-> ResultWithInfo a
ResultWithInfo ResultInfo
resultInfo [ResponseError]
errors [ResponseMessage]
messages Bool
success a
result