1 module Cryptsy
.API
.Public
.Order
3 , withComponents
, withText
4 , module Cryptsy
.API
.Public
5 , module Data
.Aeson
.Types
6 -- |Re-exported from Data.Text
8 -- |Re-exported from Data.Aeson
9 , FromJSON
(..), Value
, Object
14 import Control
.Applicative
((<$>), (<*>))
17 import Data
.Text
(Text
, pack
)
20 import qualified Data
.Aeson
as Aeson
21 import Data
.Aeson
(FromJSON
(..), Value
, Object
, withObject
, (.:))
22 import Data
.Aeson
.Types
(Parser
)
25 import Cryptsy
.API
.Public
(CryptsyNum
(..))
27 data GOrder p q t
= Order
32 type Order
= GOrder CryptsyNum CryptsyNum CryptsyNum
34 instance (FromJSON p
, FromJSON q
, FromJSON t
) =>
35 FromJSON
(GOrder p q t
)
37 parseJSON
= withObject
"order"
38 $ withComponents parseJSON parseJSON parseJSON
40 -- Combine component parsers into JSON Object parser, for use with
41 -- 'Aeson.withObject'.
42 withComponents
:: (Value
-> Parser p
) -- ^ price parser
43 -> (Value
-> Parser q
) -- ^ quantity parser
44 -> (Value
-> Parser t
) -- ^ total parser
45 -> Object
-> Parser
(GOrder p q t
)
46 withComponents parsePrice parseQuantity parseTotal o
=
48 (o
.: pack
"price" >>= parsePrice
) <*>
49 (o
.: pack
"quantity" >>= parseQuantity
) <*>
50 (o
.: pack
"total" >>= parseTotal
)
52 -- Special from of withComponents, since API delivers components as JSON
54 withText
:: (Text
-> Parser p
) -- ^ price parser
55 -> (Text
-> Parser q
) -- ^ quantity parser
56 -> (Text
-> Parser t
) -- ^ total parser
57 -> Object
-> Parser
(GOrder p q t
)
58 withText parsePrice parseQuantity parseTotal
= withComponents
59 (Aeson
.withText
"price" parsePrice
)
60 (Aeson
.withText
"quantity" parseQuantity
)
61 (Aeson
.withText
"total" parseTotal
)