aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-21 08:43:56 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-21 08:43:56 +0000
commit79a01c5fe636dad60338e4847be8b3cbf3716192 (patch)
treee715aefd359a9c74cb8b94ac009cf30481f28041 /spec
parentd27690786ed2056d64c882ac72825755110d4870 (diff)
downloadthermoprint-79a01c5fe636dad60338e4847be8b3cbf3716192.tar
thermoprint-79a01c5fe636dad60338e4847be8b3cbf3716192.tar.gz
thermoprint-79a01c5fe636dad60338e4847be8b3cbf3716192.tar.bz2
thermoprint-79a01c5fe636dad60338e4847be8b3cbf3716192.tar.xz
thermoprint-79a01c5fe636dad60338e4847be8b3cbf3716192.zip
Reworked API
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/API.hs29
1 files changed, 16 insertions, 13 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs
index 627f9b1..4b10130 100644
--- a/spec/src/Thermoprint/API.hs
+++ b/spec/src/Thermoprint/API.hs
@@ -7,6 +7,7 @@ module Thermoprint.API
7 ( PrinterStatus(..) 7 ( PrinterStatus(..)
8 , JobStatus(..) 8 , JobStatus(..)
9 , PrintingError(..) 9 , PrintingError(..)
10 , DraftTitle
10 , ThermoprintAPI 11 , ThermoprintAPI
11 , thermoprintAPI 12 , thermoprintAPI
12 , module Thermoprint.Identifiers 13 , module Thermoprint.Identifiers
@@ -20,8 +21,11 @@ import Servant.API
20import Data.Aeson 21import Data.Aeson
21 22
22import Data.Set (Set) 23import Data.Set (Set)
24import Data.Map (Map)
23import Data.Sequence (Seq) 25import Data.Sequence (Seq)
24 26
27import Data.Text (Text)
28
25import GHC.Generics (Generic) 29import GHC.Generics (Generic)
26 30
27import Data.Proxy (Proxy(..)) 31import Data.Proxy (Proxy(..))
@@ -33,8 +37,8 @@ data PrinterStatus = Busy JobId
33 | Available 37 | Available
34 deriving (Generic, Show, FromJSON, ToJSON) 38 deriving (Generic, Show, FromJSON, ToJSON)
35 39
36data JobStatus = Queued 40data JobStatus = Queued PrinterId
37 | Printing 41 | Printing PrinterId
38 | Done 42 | Done
39 | Failed PrintingError 43 | Failed PrintingError
40 deriving (Generic, Show, FromJSON, ToJSON) 44 deriving (Generic, Show, FromJSON, ToJSON)
@@ -42,28 +46,27 @@ data JobStatus = Queued
42data PrintingError = UnknownError 46data PrintingError = UnknownError
43 deriving (Typeable, Generic, Show, FromJSON, ToJSON, Exception) 47 deriving (Typeable, Generic, Show, FromJSON, ToJSON, Exception)
44 48
45type ThermoprintAPI = "printers" :> Get '[JSON] (Set PrinterId) 49type DraftTitle = Text
46 :<|> "printer" :> Capture "printerId" PrinterId :> ( 50
47 ReqBody '[JSON] Printout :> Post '[JSON] JobId 51type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus)
48 :<|> "status" :> Get '[JSON] PrinterStatus
49 )
50 :<|> "jobs" :> ( 52 :<|> "jobs" :> (
51 QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq JobId) 53 QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq (JobId, JobStatus))
54 :<|> QueryParam "printer" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId
52 ) 55 )
53 :<|> "job" :> Capture "jobId" JobId :> ( 56 :<|> "job" :> Capture "jobId" JobId :> (
54 Get '[JSON] Printout 57 Get '[JSON] Printout
55 :<|> "status" :> Get '[JSON] JobStatus 58 :<|> "status" :> Get '[JSON] JobStatus
56 :<|> "printer" :> Get '[JSON] PrinterId
57 :<|> Delete '[] () 59 :<|> Delete '[] ()
58 ) 60 )
59 :<|> "drafts" :> ( 61 :<|> "drafts" :> (
60 Get '[JSON] (Set DraftId) 62 Get '[JSON] (Map DraftId (Maybe DraftTitle))
61 :<|> ReqBody '[JSON] Printout :> Post '[JSON] DraftId 63 :<|> QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Post '[JSON] DraftId
62 ) 64 )
63 :<|> "draft" :> Capture "draftId" DraftId :> ( 65 :<|> "draft" :> Capture "draftId" DraftId :> (
64 ReqBody '[JSON] Printout :> Put '[] () 66 QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[] ()
65 :<|> Get '[JSON] Printout 67 :<|> Get '[JSON] (Maybe DraftTitle, Printout)
66 :<|> Delete '[] () 68 :<|> Delete '[] ()
69 :<|> QueryParam "printer" PrinterId :> Post '[JSON] JobId
67 ) 70 )
68 71
69thermoprintAPI :: Proxy ThermoprintAPI 72thermoprintAPI :: Proxy ThermoprintAPI