From 2b9ceaead3f3cd80e973cccecb9a3eebc51154f7 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 17 Jul 2016 19:21:56 +0200 Subject: Fixes for GHC 8.0.1 --- spec/src/Thermoprint/API.hs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'spec/src/Thermoprint/API.hs') diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 9e91487..8e98db8 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs @@ -100,12 +100,6 @@ instance Exception PrintingError type DraftTitle = Text -instance FromText UTCTime where - fromText = parseTimeM True defaultTimeLocale "%F_%T%Q" . T.unpack - -instance ToText UTCTime where - toText = T.pack . formatTime defaultTimeLocale "%F_%T%Q" - data Range a = Min a | Max a | Through a a deriving (Show, Eq, Generic) @@ -121,17 +115,19 @@ contains (Min min) x = min <= x contains (Max max) x = max >= x contains (Through min max) x = min <= x && x <= max -instance ToText a => ToText (Range a) where - toText (Min min) = toText min <> "-" - toText (Max max) = "-" <> toText max - toText (Through min max) = toText min <> "-" <> toText max +instance ToHttpApiData a => ToHttpApiData (Range a) where + toUrlPiece (Min min) = toUrlPiece min <> "-" + toUrlPiece (Max max) = "-" <> toUrlPiece max + toUrlPiece (Through min max) = toUrlPiece min <> "-" <> toUrlPiece max -instance FromText a => FromText (Range a) where - fromText t = listToMaybe $ through <> max <> min +instance FromHttpApiData a => FromHttpApiData (Range a) where + parseUrlPiece t = listToEither $ through <> max <> min where - through = [ Through min max | ((fromText -> Just min), (T.uncons -> Just ('-', (fromText -> Just max)))) <- zip (T.inits t) (T.tails t) ] - min = [ Min min | (fromText -> Just min) <- T.inits t ] - max = [ Max max | (fromText -> Just max) <- T.tails t ] + through = [ Through min max | ((parseUrlPiece -> Right min), (T.uncons -> Just ('-', (parseUrlPiece -> Right max)))) <- zip (T.inits t) (T.tails t) ] + min = [ Min min | (parseUrlPiece -> Right min) <- T.inits t ] + max = [ Max max | (parseUrlPiece -> Right max) <- T.tails t ] + listToEither [x] = Right x + listToEither _ = Left t type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) :<|> "jobs" :> ( @@ -144,16 +140,16 @@ type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) :<|> "job" :> Capture "jobId" JobId :> ( Get '[JSON] Printout :<|> "status" :> Get '[JSON] JobStatus - :<|> Delete '[PlainText] () + :<|> Delete '[JSON] () ) :<|> "drafts" :> ( Get '[JSON] (Map DraftId (Maybe DraftTitle)) :<|> QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Post '[JSON] DraftId ) :<|> "draft" :> Capture "draftId" DraftId :> ( - QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[PlainText] () + QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[JSON] () :<|> Get '[JSON] (Maybe DraftTitle, Printout) - :<|> Delete '[PlainText] () + :<|> Delete '[JSON] () :<|> QueryParam "printer" PrinterId :> Post '[JSON] JobId ) -- cgit v1.2.3