packages feed

quantum-random 0.6.3 → 0.6.4

raw patch · 3 files changed

+16/−28 lines, 3 filesdep −regex-posixdep ~aeson

Dependencies removed: regex-posix

Dependency ranges changed: aeson

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for `quantum-random` +#### 0.6.4++* Update dependency for `aeson-1.1`.+* Drop `regex-posix` dependency and properly use Aeson's `fieldLabelModifier` instead.+ #### 0.6.3  * Update dependency for `aeson-1.0`.
quantum-random.cabal view
@@ -1,5 +1,5 @@ name:                quantum-random-version:             0.6.3+version:             0.6.4 synopsis:            Retrieve, store and manage real quantum random data.  description:         Retrieve, store and manage real quantum random data, originating from vacuum@@ -44,9 +44,8 @@    build-depends:       base          >=4.8  && <4.10,                        ansigraph     >=0.2  && <0.4,-                       aeson         >=0.8  && <1.1,+                       aeson         >=0.8  && <1.2,                        text          >=1.2  && <1.3,-                       regex-posix   >=0.9  && <1.0,                        bytestring    >=0.10 && <0.11,                        http-conduit  >=2.1  && <2.3,                        ansi-terminal >=0.6  && <0.7,
src-lib/Quantum/Random/Codec.hs view
@@ -18,11 +18,10 @@ import Quantum.Random.Display  import GHC.Generics               (Generic)-import Data.Aeson                 (FromJSON,ToJSON,eitherDecode)+import Data.Aeson+import Data.Aeson.Types           (Options (..)) import Data.Text                  (Text) import Data.ByteString.Lazy       (ByteString)-import Data.ByteString.Lazy.Char8 (pack,unpack)-import Text.Regex.Posix           ((=~)) import Data.Bifunctor             (first)  @@ -38,9 +37,13 @@                              , targetStoreSize :: Int                              , defaultDisplayStyle :: DisplayStyle } deriving (Show, Generic) +instance FromJSON QRResponse where+    parseJSON = genericParseJSON $+        defaultOptions { fieldLabelModifier = qrFieldRenamer }+            where qrFieldRenamer :: String -> String+                  qrFieldRenamer ('q':str) = str+                  qrFieldRenamer str       = str -instance FromJSON QRResponse-instance ToJSON   QRResponse instance FromJSON QRSettings instance ToJSON   QRSettings @@ -60,28 +63,9 @@ updateDefaultStyle :: DisplayStyle -> QRSettings -> QRSettings updateDefaultStyle sty qs = qs { defaultDisplayStyle = sty } --- | Replace instances of the words "data", "type", "length", with "qdata", "qtype", "qlength"---   respectively, to avoid clashes between record field names and keywords/Prelude.-process :: ByteString -> ByteString-process = pack . repData . repType . repLength . unpack--repData :: String -> String-repData = replaceWord "data" "qdata"--repType :: String -> String-repType = replaceWord "type" "qtype"--repLength :: String -> String-repLength = replaceWord "length" "qlength"---replaceWord :: String -> String -> String -> String-replaceWord x y s = let (a,_,c) = s =~ x :: (String, String, String)-                    in  a ++ y ++ c- -- | From a Bytestring, attempt to decode a response from ANU ('QRResponse'). parseResponse :: ByteString -> Either QRException QRResponse-parseResponse = first ParseResponseError . eitherDecode . process+parseResponse = first ParseResponseError . eitherDecode  -- | From a Bytestring, attempt to decode a settings record. parseSettings :: ByteString -> Either QRException QRSettings