diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-11 03:34:16 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-11 03:34:16 +0000 |
commit | ea079b5ee00f5371bde992a14676374a431371b5 (patch) | |
tree | b6b9dd11a18af502eb777c304762a68cd7e3a146 /spec | |
parent | f6dc3d1d5e5109c4196ad17ee69ccc7fc8b57b3b (diff) | |
download | thermoprint-ea079b5ee00f5371bde992a14676374a431371b5.tar thermoprint-ea079b5ee00f5371bde992a14676374a431371b5.tar.gz thermoprint-ea079b5ee00f5371bde992a14676374a431371b5.tar.bz2 thermoprint-ea079b5ee00f5371bde992a14676374a431371b5.tar.xz thermoprint-ea079b5ee00f5371bde992a14676374a431371b5.zip |
More fleshed out API
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/API.hs | 69 | ||||
-rw-r--r-- | spec/src/Thermoprint/Identifiers.hs | 19 | ||||
-rw-r--r-- | spec/thermoprint-spec.cabal | 1 |
3 files changed, 81 insertions, 8 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index f2ffd02..d722903 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs | |||
@@ -1,21 +1,74 @@ | |||
1 | {-# LANGUAGE GeneralizedNewtypeDeriving, NoDeriveAnyClass #-} | 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} |
2 | {-# LANGUAGE TypeOperators, DataKinds #-} | 2 | {-# LANGUAGE TypeOperators, DataKinds #-} |
3 | {-# LANGUAGE OverloadedStrings #-} | ||
3 | 4 | ||
4 | module Thermoprint.API | 5 | module Thermoprint.API |
5 | ( PrinterId(..) | 6 | ( PrinterStatus(..) |
6 | , JobId(..) | 7 | , JobStatus(..) |
7 | , ThermoprintAPI | 8 | , ThermoprintAPI |
9 | , thermoprintAPI | ||
10 | , module Thermoprint.Identifiers | ||
11 | , module Thermoprint.Printout | ||
8 | ) where | 12 | ) where |
9 | 13 | ||
10 | import Thermoprint.Printout | 14 | import Thermoprint.Printout |
15 | import Thermoprint.Identifiers | ||
11 | 16 | ||
12 | import Servant.API | 17 | import Servant.API |
18 | import Servant.Docs | ||
13 | import Data.Aeson | 19 | import Data.Aeson |
14 | 20 | ||
15 | newtype PrinterId = PrinterId Integer | 21 | import Data.Set (Set) |
16 | deriving (Show, Eq, FromText, ToText, FromJSON, ToJSON) | 22 | import Data.Sequence (Seq) |
17 | 23 | ||
18 | newtype JobId = JobId Integer | 24 | import GHC.Generics (Generic) |
19 | deriving (Show, Eq, FromText, ToText, FromJSON, ToJSON) | ||
20 | 25 | ||
21 | type ThermoprintAPI = "print" :> Capture "printerId" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId | 26 | import Data.Proxy (Proxy(..)) |
27 | |||
28 | import Data.Functor.Identity (Identity(..)) | ||
29 | import Control.Exception (Exception) | ||
30 | import Data.Typeable (Typeable) | ||
31 | |||
32 | data PrinterStatus = Busy JobId | ||
33 | | Available | ||
34 | deriving (Generic, Show, FromJSON, ToJSON) | ||
35 | |||
36 | data JobInfo = JobInfo | ||
37 | { jobPrinter :: PrinterId | ||
38 | , jobStatus :: JobStatus | ||
39 | } | ||
40 | |||
41 | data JobStatus = Queued | ||
42 | | Printing | ||
43 | | Done | ||
44 | | Failed PrintingError | ||
45 | deriving (Generic, Show, FromJSON, ToJSON) | ||
46 | |||
47 | data PrintingError = UnknownError | ||
48 | deriving (Typeable, Generic, Show, FromJSON, ToJSON, Exception) | ||
49 | |||
50 | type ThermoprintAPI = "printers" :> Get '[JSON] (Set PrinterId) | ||
51 | :<|> "printer" :> Capture "printerId" PrinterId :> ( | ||
52 | ReqBody '[JSON] Printout :> Post '[JSON] JobId | ||
53 | :<|> "status" :> Get '[JSON] PrinterStatus | ||
54 | ) | ||
55 | :<|> "jobs" :> ( | ||
56 | QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq JobId) | ||
57 | ) | ||
58 | :<|> "job" :> Capture "jobId" JobId :> ( | ||
59 | Get '[JSON] Printout | ||
60 | :<|> "status" :> Get '[JSON] JobInfo | ||
61 | :<|> Delete '[] () | ||
62 | ) | ||
63 | :<|> "drafts" :> ( | ||
64 | Get '[JSON] (Set DraftId) | ||
65 | :<|> ReqBody '[JSON] Printout :> Post '[JSON] DraftId | ||
66 | ) | ||
67 | :<|> "draft" :> Capture "draftId" DraftId :> ( | ||
68 | ReqBody '[JSON] Printout :> Put '[] () | ||
69 | :<|> Get '[JSON] Printout | ||
70 | :<|> Delete '[] () | ||
71 | ) | ||
72 | |||
73 | thermoprintAPI :: Proxy ThermoprintAPI | ||
74 | thermoprintAPI = Proxy | ||
diff --git a/spec/src/Thermoprint/Identifiers.hs b/spec/src/Thermoprint/Identifiers.hs new file mode 100644 index 0000000..bd0b7a6 --- /dev/null +++ b/spec/src/Thermoprint/Identifiers.hs | |||
@@ -0,0 +1,19 @@ | |||
1 | {-# LANGUAGE GeneralizedNewtypeDeriving, NoDeriveAnyClass #-} | ||
2 | |||
3 | module Thermoprint.Identifiers | ||
4 | ( PrinterId(..) | ||
5 | , JobId(..) | ||
6 | , DraftId(..) | ||
7 | ) where | ||
8 | |||
9 | import Servant.API (ToText, FromText) | ||
10 | import Data.Aeson (FromJSON, ToJSON) | ||
11 | |||
12 | newtype PrinterId = PrinterId Integer | ||
13 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
14 | |||
15 | newtype JobId = JobId Integer | ||
16 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
17 | |||
18 | newtype DraftId = DraftId Integer | ||
19 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal index f7227ca..b9f7fd6 100644 --- a/spec/thermoprint-spec.cabal +++ b/spec/thermoprint-spec.cabal | |||
@@ -19,6 +19,7 @@ cabal-version: >=1.10 | |||
19 | library | 19 | library |
20 | hs-source-dirs: src | 20 | hs-source-dirs: src |
21 | exposed-modules: Thermoprint.Printout | 21 | exposed-modules: Thermoprint.Printout |
22 | , Thermoprint.Identifiers | ||
22 | , Thermoprint.API | 23 | , Thermoprint.API |
23 | -- other-modules: | 24 | -- other-modules: |
24 | -- other-extensions: | 25 | -- other-extensions: |