aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-21 09:12:50 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-21 09:12:50 +0000
commitff05fa3fab535df6610ce4df21162fc676f098f0 (patch)
treeeda3eb6233610bbb533e5af0eccde42d00e71f34 /spec
parent58d26527560f8d3e21f5f50ec9a5e993cf044ae0 (diff)
downloadthermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar
thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.gz
thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.bz2
thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.tar.xz
thermoprint-ff05fa3fab535df6610ce4df21162fc676f098f0.zip
Added json instances to api
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/API.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs
index 4b10130..6c86008 100644
--- a/spec/src/Thermoprint/API.hs
+++ b/spec/src/Thermoprint/API.hs
@@ -22,8 +22,12 @@ import Data.Aeson
22 22
23import Data.Set (Set) 23import Data.Set (Set)
24import Data.Map (Map) 24import Data.Map (Map)
25import qualified Data.Map as Map (foldMapWithKey, singleton)
25import Data.Sequence (Seq) 26import Data.Sequence (Seq)
26 27
28import Data.IntMap.Strict (IntMap)
29import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton)
30
27import Data.Text (Text) 31import Data.Text (Text)
28 32
29import GHC.Generics (Generic) 33import GHC.Generics (Generic)
@@ -33,6 +37,13 @@ import Data.Proxy (Proxy(..))
33import Control.Exception (Exception) 37import Control.Exception (Exception)
34import Data.Typeable (Typeable) 38import Data.Typeable (Typeable)
35 39
40instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where
41 toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId)
42
43instance (Enum k, Ord k, FromJSON v) => FromJSON (Map k v) where
44 parseJSON = fmap (IntMap.foldMapWithKey $ Map.singleton . castId) . parseJSON
45
46
36data PrinterStatus = Busy JobId 47data PrinterStatus = Busy JobId
37 | Available 48 | Available
38 deriving (Generic, Show, FromJSON, ToJSON) 49 deriving (Generic, Show, FromJSON, ToJSON)