packages feed

http-query 0.1.0.1 → 0.1.1

raw patch · 4 files changed

+38/−7 lines, 4 filesdep ~aesondep ~http-conduitPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aeson, http-conduit

API changes (from Hackage documentation)

+ Network.HTTP.Query: apiQueryURI :: String -> Query -> URI

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for http-query +## 0.1.1 (2021-11-29)+- add apiQueryURI: returns the URI of a query+- fix build with aeson-2.0+ ## 0.1.0.1 (2021-02-28) - webAPIQuery: use setRequestCheckStatus - build for ghc-7.10 with transformers
README.md view
@@ -1,6 +1,6 @@ # http-query -[![GitHub CI](https://github.com/juhp/dl-fedora/workflows/build/badge.svg)](https://github.com/juhp/dl-fedora/actions)+[![GitHub CI](https://github.com/juhp/http-query/workflows/build/badge.svg)](https://github.com/juhp/http-query/actions) [![Hackage](http://img.shields.io/hackage/v/http-query.png)](http://hackage.haskell.org/package/http-query)  Very thin layer over http-conduit for simpler web json API queries.@@ -11,8 +11,10 @@  A few projects use http-query already: +- https://hackage.haskell.org/package/cached-json-file+- https://hackage.haskell.org/package/fbrnch+- https://hackage.haskell.org/package/stack-all - https://github.com/juhp/bodhi-hs - https://github.com/juhp/copr-hs - https://github.com/juhp/pagure-hs - https://github.com/juhp/pdc-hs-- https://github.com/juhp/fbrnch
http-query.cabal view
@@ -1,5 +1,5 @@ name:                http-query-version:             0.1.0.1+version:             0.1.1 synopsis:            Simple http queries description:         Simple web API queries to JSON.@@ -25,7 +25,7 @@                      , aeson                      , bytestring                      , network-uri-                     , http-conduit+                     , http-conduit >= 2.3.2                      , text   if impl(ghc < 8)     build-depends:     transformers
src/Network/HTTP/Query.hs view
@@ -30,12 +30,19 @@   makeItem,   (+/+),   webAPIQuery,+  apiQueryURI,   lookupKey,   lookupKeyEither,   lookupKey'   ) where +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>))+#endif import Control.Monad.IO.Class (MonadIO)+#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson.Key (fromText)+#endif import Data.Aeson.Types #if !MIN_VERSION_http_conduit(2,3,3) import Data.ByteString (ByteString)@@ -93,16 +100,34 @@                 requestFromURI_ uri       in getResponseBody <$> httpJSON req +-- | Get the URI for a web query+apiQueryURI :: String -- ^ url of endpoint+            -> Query -- ^ query options+            -> URI+apiQueryURI url params =+  case parseURI url of+    Nothing -> error $ "Cannot parse uri: " ++ url+    Just uri ->+      let req = setRequestQueryString params $+                requestFromURI_ uri+      in getUri req+ -- FIXME support "key1.key2" etc -- | Look up key in object lookupKey :: FromJSON a => Text -> Object -> Maybe a-lookupKey k = parseMaybe (.: k)+lookupKey k =+  parseMaybe (.: fromText k)  -- | Like lookupKey but returns error message if not found lookupKeyEither :: FromJSON a => Text -> Object -> Either String a-lookupKeyEither k = parseEither (.: k)+lookupKeyEither k = parseEither (.: fromText k)  -- | Like lookupKey but raises an error if no key found lookupKey' :: FromJSON a => Text -> Object -> a lookupKey' k =-  either error id . parseEither (.: k)+  either error id . parseEither (.: fromText k)++#if !MIN_VERSION_aeson(2,0,0)+fromText :: Text -> Text+fromText = id+#endif